tags:

views:

144

answers:

2

Hi guys,

I have a gridview in which I have set datasource as datatable. Whatever update I make to the gridview, it should reflect only in datatable not to database. When I click update I have to get the row number of particular row which I want to update. How can I get the row number in rowupdating event of gridview inorder to update datatable? Suppose i have datakey and if i get that unique id, how can i update the datatable which is the datasource?. Can anybody help?

A: 

If there is sorting applied then the row numbers in gridview and datatable won't match.

So if you try to update with the row number in gridview it may end up in incorrect values.

The updation should be based on a unique ID in the gridview datasource.

rahul
if soting is not there how can i get rownumber
A: 

This is the way to get the row id of your updated row :

protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
  string id = GridView1.DataKeys[e.RowIndex].Values[0].ToString(); 
}

Maybe you want only the e.RowIndex. But the above code returns the specified unique data key for the row.

Canavar