Last post Nov 07, 2007 08:31 AM by vinz
Nov 04, 2007 07:34 AM|faezeh|LINK
in my project i have the following items;
- 1 table called 'Objects'
- this table has five fields by the names of '"objectsID" (this field is set to have auto numbers), "AuthorName", "Title", "Description" and "Image"
- my database connection as shown in the server Exploere is read as "your-eace4a545a\sqlexpress.KLTrails.dbo"
- in the design view of my website i have a GridView called "GirdView2"
- an SqlDataSource called "CopyingRow" [linked to my table]
- a link button called "Copy"
Nov 04, 2007 12:49 PM|InsanePaul|LINK
i would like to know too
Nov 05, 2007 08:58 PM|Techie Zhang - MSFT|LINK
According to you description, you want to copy a selected row and give it a unique ID as a new record.
I'm not sure what the new record is used for, but there is a way of copying which may be helpful to you.
Add Click event handler to the Copy button like
protected void Button1_Click(object sender, EventArgs e)
Button bttn = (Button)sender;
DataGridItem item = (DataGridItem)bttn.NamingContainer;
Label lb = (Label)item.FindControl("Label1");
string authorName = lb.Text;
// ditto to get values of other fields
// after get all the values, do whatever you want
Nov 06, 2007 04:04 AM|faezeh|LINK
Thank you very much for your advice. in your codes there is a 'label' - could you please explain what this does and where i should create one. also where it says 'DataGridItem' should i be writing my DataGridItem id in order to connect to the database or
there is no need when writing in VB language?
Nov 06, 2007 06:58 AM|faezeh|LINK
i have tried this code, but i am keep getting many syntax and declaration errors. I think i am doing this wrong, coudl you please advice.
Nov 06, 2007 11:25 AM|vinz|LINK
I know you are using vb but i think this will give you directions regarding your problem. Try this snippet below:
int count = int.Parse(GridView1.Rows.Count.ToString());
for (int i = 0; i < count; i++)
if (GridView1.SelectedIndex == i)
string Author= GridView1.Rows[i].Cells.Text;
string Title = GridView1.Rows[i].Cells.Text;
string Description = GridView1.Rows[i].Cells.Text;
// And so on....
The code above gets the value in your gridview
Hope this will help you.
Nov 06, 2007 05:14 PM|faezeh|LINK
Thank you, i have tried your code but in my VB page i get many syntax problems i.e. "Name 'count' is not declared"
Nov 06, 2007 10:50 PM|Allen Chen – MSFT|LINK
You can utilize this tool:
Nov 07, 2007 08:06 AM|vinz|LINK
Have you declared the variable count?
Nov 07, 2007 08:11 AM|faezeh|LINK
Thank you for asking, but No i dont know how to declar count.
Nov 07, 2007 08:31 AM|vinz|LINK
Dim count as integer