Home All Groups Group Topic Archive Search About

Referencing Datagrid Rows while Datagrid is Sorted

Author
20 May 2005 8:44 PM
MrMike
I see this question raised often elsewhere, but I haven't yet found an
answer.  When a datagrid is sorted, referencing a specific row is a problem. 
In my applications I frequently use datagrids and I must tell my users "If
you are going to edit/update/delete a record from a datagrid, make sure you
don't have it sorted first because you'll perform the action on the wrong
record."

Is there a way to work around the problem of sorting a datagrid and then
referencing it's records?  Thanks.

Author
21 May 2005 5:01 AM
Steve Goodyear
Hi Mike,

It's no problem to let them sort still and also let them edit the data. Look
in the DataGridCommandEventArgs of the update event to get the DataGrid row
instead of EditItemIndex to get the updates for your DataTable. This way your
DataGrid can be more flexable:

private void DataGrid1_UpdateCommand(object source,
System.Web.UI.WebControls.DataGridCommandEventArgs e)
  {
    string updatedText = e.Item.Cells[0].Text;
  }

Cheers,
Steve Goodyear
Author
23 May 2005 12:02 PM
MrMike
Hi Steve,

Thank you very much for that valuable information!!

Show quoteHide quote
"Steve Goodyear" wrote:

> Hi Mike,
>
> It's no problem to let them sort still and also let them edit the data. Look
> in the DataGridCommandEventArgs of the update event to get the DataGrid row
> instead of EditItemIndex to get the updates for your DataTable. This way your
> DataGrid can be more flexable:
>
> private void DataGrid1_UpdateCommand(object source,
> System.Web.UI.WebControls.DataGridCommandEventArgs e)
>   {
>     string updatedText = e.Item.Cells[0].Text;
>   }
>
> Cheers,
> Steve Goodyear