Referencing Datagrid Rows while Datagrid is Sorted

M

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.
 
S

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top