gridview 与 detailsview 处理插入与更新异常

来源:互联网 发布:linux select poll 编辑:程序博客网 时间:2024/06/05 00:57

 protected void DetailsView1_ItemInserted(object sender, DetailsViewInsertedEventArgs e)
    {
        if (e.Exception != null)
        {
            // System.Windows.Forms.MessageBox.Show(e.Exception.Message);
            if (e.Exception.Message.Contains("NULL"))
            {
                (DetailsView1.FindControl("error") as Label).Text = "内容不能为空!";
            }
            if (e.Exception.Message.Contains("截断"))
            {
                (DetailsView1.FindControl("error") as Label).Text = "编号或语言的内容过长!";
            }
           
            e.ExceptionHandled = true;
            e.KeepInInsertMode = true;
        }
    }

更新同理!

原创粉丝点击