代码之家  ›  专栏  ›  技术社区  ›  GordyII

ASP。NET-如何在try-catch或停止行删除中包装GridView Delete

  •  2
  • GordyII  · 技术社区  · 16 年前

    我希望能够将网格视图行删除包裹在try-catch中,并在屏幕上显示一条漂亮的错误消息,或者在某些情况下尝试停止删除。

    有人能告诉我怎么做吗?

    2 回复  |  直到 16 年前
        1
  •  4
  •   Tarik    16 年前

    您可以使用 GridView Row Deleting Event

    这是一个示例代码:

    void CustomersGridView_RowDeleting
            (Object sender, GridViewDeleteEventArgs e)
        {
            TableCell cell = CustomersGridView.Rows[e.RowIndex].Cells[2];
            if (cell.Text == "Beaver")
            {
                e.Cancel = true;
                Message.Text = "You cannot delete customer Beaver.";
            }
            else
            {
                Message.Text = "";
            }
        } 
    
        2
  •  1
  •   Tarik    16 年前

    使用数据源 删除 事件可能更清晰,因为不依赖于GUI元素及其可能的重新定位,这可能会破坏代码。

    推荐文章