ASP.Net DataGrids one button Update
It is while since I wrote this code-snippet, but at the time many DataGrid experts said it could not be done. After about twenty minutes of trying to understand some DataGrid events a working solution was found:
if (this.dataGrid.EditItemIndex > -1)
{
// Update the DataGrid
this.dataGrid_UpdateCommand(
this.dataGrid,
new DataGridCommandEventArgs(
this.dataGrid.Items[this.dataGrid.EditItemIndex],
this.dataGrid,
new System.Web.UI.WebControls.CommandEventArgs(“Update”, “”)));
}
Not a pretty event call but it works. On my last ASP.Net project several pages used one Update Button to perform updates on three or more DataGrids simultaneously. If your code forces users to click several update buttons, then use of this code may just make them a little happier.
about 1 year ago
You are the man! I used it in vb.net:
If dgResults.EditItemIndex > -1 Then
dgResults_UpdateCommand(dgResults, New DataGridCommandEventArgs(dgResults.Items(dgResults.EditItemIndex), dgResults, New System.Web.UI.WebControls.CommandEventArgs("Update", "")))
End If
and it works perfect! datagrid = dgResults
about 1 year ago
That is a great suggestion. I think too many people that get into ASP.NET don’t think of the objects as being actual class and being able to code against them in such a way. Great blog and I hope to see more!
about 1 year ago
Thanks for the translation for the VB.Net users. The post has only had five views so far but there must be many projects worldwide who are in need of that snippet. With luck Google will cache it and more people will find it.
Brendon highlights a great point about the .Net Framework. If something does not work out of the box, then because the inner workings of the framework are exposed we can often work around such problems.