add a confirm dialogbox to the editItem of the datagrid

博客代码展示了在DataGrid中添加委托处理项创建事件。当创建项时,若为普通项或交替项则调用CustomizeItem方法。该方法设置项样式,添加删除确认弹窗,并设置工具提示,实现DataGrid项的相关操作。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

//first add a delegate in private void InitializeComponent()

this.DataGrid1.ItemCreated += new System.Web.UI.WebControls.DataGridItemEventHandler(this.DataGrid1_ItemCreated);

private void DataGrid1_ItemCreated(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
  {
   ListItemType lit = e.Item.ItemType;
   if (lit == ListItemType.Item || lit == ListItemType.AlternatingItem)
   {
    CustomizeItem(e);
   }
  }

  private void CustomizeItem(DataGridItemEventArgs e)
  {
   WebControl wc;
   int i = e.Item.Cells.Count -1;
   wc = ((WebControl) e.Item.Cells[i]);
   wc.Height = 25;//set the item's style
   wc.Width = 25;
   String js = "return confirm("Delete it?");";
   wc.Attributes.Add("onclick", js);
   //   wc.ToolTip = e.Item.Cells[0].Text.Trim() + "...";
   wc.ToolTip += "Delete this row";
  }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值