关于Datagrid 删除列的问题?
我的datagrid 有 一列 是删除列
用的是 linkbutton 形式
我怎么在点击 删除 的时候 在页面弹出 confirm(‘确定删除’) 对话框?
------解决方案--------------------在datagrid的ItemDataBound中写事件
private void DataGrid1_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
{
LinkButton lb;
if(e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.Item)
{
lb = (LinkButton)e.Item.Cells[3].Controls[0];
lb.Attributes.Add( "onclick ", "return confirm( '是否真的删除该XX! '); ");
}
}
------解决方案--------------------我这有一个和你需求一样的例子,是关于GridView的,你可以照着改
HTML:
-------------------------------
<body>
<form id= "form1 " runat= "server ">
<div>
<asp:DataGrid ID= "DataGrid1 " runat= "server " OnDeleteCommand= "DataGrid1_DeleteCommand " DataKeyField= "id " AutoGenerateColumns= "False ">
<Columns>
<asp:TemplateColumn HeaderText= "name ">
<ItemTemplate>
<%# DataBinder.Eval(Container.DataItem, "name ")%>
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText= "sale ">
<ItemTemplate>
<%# DataBinder.Eval(Container.DataItem, "sale ")%>
</ItemTemplate>
</asp:TemplateColumn>
<asp:ButtonColumn CommandName= "Delete " Text= "删除 "> </asp:ButtonColumn>
</Columns>
</asp:DataGrid> </div>
</form>
</body>
C#:
--------------------------------