ASP.Net DataGrids – One Button to Update them all

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

This entry was posted in Uncategorized. Bookmark the permalink.

3 Responses to ASP.Net DataGrids – One Button to Update them all

  1. stillers says:

    You are the man! I used it in
    <br> If dgResults.EditItemIndex &gt; -1 Then
    <br> dgResults_UpdateCommand(dgResults, New DataGridCommandEventArgs(dgResults.Items(dgResults.EditItemIndex), dgResults, New System.Web.UI.WebControls.CommandEventArgs(&quot;Update&quot;, &quot;&quot;)))
    <br> End If
    <br>and it works perfect! datagrid = dgResults

  2. Brendon Schwartz says:

    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!

  3. Paul Lockwood says:

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

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s