Simple Feedback Upon Data Edit on Webform
I'm using a GridView control, using the Northwind database as a sandbox.
I have allowed editing of rows using AutoGenerateEditButton="true" and that all works fine. The book I'm using for reference suggests the following code behind for error handling (C#):
protected void GridView1_RowUpdated(object sender, GridViewUpdatedEventArgs e)
{
if (e.Exception != null)
this.lblErrorMessage.Text = e.Exception.Message;
}
I've used a simple asp label, on the same webform. As an experiment, I edited the above to look as follows, since I want a simple text confirmation:
protected void GridView1_RowUpdated(obj开发者_如何学Pythonect sender, GridViewUpdatedEventArgs e)
{
if (e.Exception != null)
this.lblErrorMessage.Text = e.Exception.Message;
else
this.lblErrorMessage.Text = "Row updated!";
}
However, this seems to have no effect upon my label text, leading me to believe that the exception handling snippet won't work either. Can anyone please advise me as to why?
The GridView did not have an 'OnRowUpdated' property, so the relevant code behind was never executed. Solved through the addition of OnRowUpdated="GridView1_RowUpdated" to the asp:GridView tag.
精彩评论