• GridView学习之四删除记录


    将CommandField的ShowDeleteButton=True,那么当点击这个CommandField字段时会触发RowDeleting事件

    而BUttonField需要将CommandName=Delete才会激发RowDeleting事件

     1using System;
     2using System.Data;
     3using System.Configuration;
     4using System.Collections;
     5using System.Web;
     6using System.Web.Security;
     7using System.Web.UI;
     8using System.Web.UI.WebControls;
     9using System.Web.UI.WebControls.WebParts;
    10using System.Web.UI.HtmlControls;
    11
    12public partial class GridViewDeletingTest : System.Web.UI.Page
    13{
    14    protected void Page_Load(object sender, EventArgs e)
    15    {
    16        if (!IsPostBack)
    17        {
    18            ClientInfoAccessObj accessor = new ClientInfoAccessObj();
    19            GridView1.DataSource = accessor.GetAllClients();
    20            GridView1.DataBind();
    21        }

    22    }

    23    protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
    24    {
    25        ClientInfoAccessObj accessor = new ClientInfoAccessObj();
    26        int ClientID = Convert.ToInt32(GridView1.DataKeys[e.RowIndex].Value);//获得要删除的客户编号
    27        accessor.DeleteClientInfoForID(ClientID);//根据客户ID删除对应的记录
    28        ClientScript.RegisterClientScriptBlock(this.GetType(), "info""alert('记录被删除');"true);
    29        GridView1.DataSource = accessor.GetAllClients();//绑定数据
    30        GridView1.DataBind();
    31    }

    32    protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
    33    {
    34        //GirdView中的按钮被点击之后触发该事件
    35        lblInfo.Text = string.Format("CommandName={0},CommandArgument={1},CommandSource={2}",e.CommandName,e.CommandArgument,e.CommandSource);
    36    }

    37}

    38
  • 相关阅读:
    安装nodejs和yarn(配置淘宝源)
    适用于 Linux 的 Windows 子系统没有已安装的分发版
    selenium定位元素click时报错
    dubbo从入门到实战(转)
    SpringBoot整合JPA简单介绍
    办公自动化路上的异化
    邮箱黑名单:如何查看邮件IP是否被列入黑名单,及如何删除
    邮箱黑名单(1):
    Vmware挂载san存储_vSphere 6.x 共享存储LUN丢失分区表修复(精华)
    AD中FSMO五大角色的介绍及操作
  • 原文地址:https://www.cnblogs.com/mdy41034264/p/1356219.html
Copyright © 2020-2023  润新知