Webform 上数据编辑的简单反馈
我使用 GridView 控件,使用 Northwind 数据库作为沙箱。
我已允许使用 AutoGenerateEditButton="true" 编辑行,并且一切正常。我用作参考的书建议使用以下代码进行错误处理 (C#):
protected void GridView1_RowUpdated(object sender, GridViewUpdatedEventArgs e)
{
if (e.Exception != null)
this.lblErrorMessage.Text = e.Exception.Message;
}
我在同一个 Web 表单上使用了一个简单的 asp 标签。作为实验,我将上面的内容编辑为如下所示,因为我想要一个简单的文本确认:
protected void GridView1_RowUpdated(object sender, GridViewUpdatedEventArgs e)
{
if (e.Exception != null)
this.lblErrorMessage.Text = e.Exception.Message;
else
this.lblErrorMessage.Text = "Row updated!";
}
但是,这似乎对我的标签文本没有影响,使我相信异常处理片段也不起作用。谁能告诉我为什么?
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(object 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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
GridView 没有“OnRowUpdated”属性,因此后面的相关代码从未执行。通过在 asp:GridView 标记中添加 OnRowUpdated="GridView1_RowUpdated" 来解决。
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.