为GridView添加删除确认的若干种方法
2007-01-22 09:06
555 查看
先介绍最简单的方法
1.利用OnClientClick事件
<ItemTemplate>
<asp:ImageButton ID="IbnDel" runat="server" ToolTip="删除" CommandName="Delete" ImageUrl="/Images/delete01.gif" OnClientClick="javascript:return confirm('你确定要删除吗?将不可恢复哦');" />
</ItemTemplate>
2.后台代码里写,算最简便的一种方法了
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Cells[8].Attributes.Add("onclick", "return confirm('删除此条记录?');");
}
}
3.遍历每个元素,找到你要的控件,添加删除确认.
protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
{
LinkButton l;
for(int i=0;i<e.Row.Cells.Count;i++)
{
for (int j = 0; j < e.Row.Cells[i].Controls.Count; j++)
{
if (e.Row.Cells[i].Controls[j].GetType().ToString() == "System.Web.UI.WebControls.DataControlLinkButton")
{
l = (LinkButton)e.Row.Cells[i].Controls[j];
if (l.Text == "删除")
{
l.Attributes.Add("onclick", "return confirm('确定要删除这个分类吗?');");
}
}
}
}
}
4.最后附上DataGrid的删除确认方法
private void DataGrid1_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
{
switch(e.Item.ItemType)//添加删除提示
{
case ListItemType.AlternatingItem:
case ListItemType.EditItem:
case ListItemType.Item:
{
LinkButton lbtDelete = (LinkButton)e.Item.Cells[2].Controls[0];
lbtDelete.Attributes.Add("onclick","return confirm('您确定要删除[" + e.Item.Cells[0].Text + "]的数据吗?此操作将删除[" + e.Item.Cells[0].Text + "]的所有小类以及所有新闻!');");
break;
}
}
}
相关文章推荐
- 为gridview“删除”列添加确认对话框的方法
- 为gridview“删除”列添加确认对话框的方法
- ASP.NET2.0下为GridView添加服务器端删除确认!
- gridview“删除”列添加确认对话框
- ASP.NET中为GridView添加删除确认提示框
- 给 GridView 的 LinkButton 删除按钮添加弹出层的确认删除对话框
- 解决ASP 2.0中GridView控件的删除、插入、编辑命令操作客户端确认问题的另一方法
- 在.net2.0中,实现对gridview删除行时弹出确认对话框的四种方法
- 为gridview“删除”列添加确认对话框
- 为gridview“删除”列添加确认对话框
- 为gridview“删除”列添加确认对话框
- (转)为gridview“删除”列添加确认对话框
- 为GridView的删除行添加删除确认
- 为 GridView、DetailsView、FormView 等数据显示控件删除功能添加“确认对话框”
- ASP.NET2.0下为GridView添加服务器端删除确认!
- 为gridview“删除”列添加确认对话框 C#
- 实现对gridview删除行时弹出确认对话框的四种方法
- [转] 为GridView删除添加确认对话框
- 为GridView“删除”列添加确认对话框
- 为GridView删除添加确认对话框