日期:2014-05-18  浏览次数:20471 次

为Gridview添加确认删除的对话框
就是点gridview上的删除,弹出一个对话框
点是就删除
点否就不删除,取消操作

------解决方案--------------------
在后台的GridView1_RowDataBound()方法添加代码

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
//如果是绑定数据行
if (e.Row.RowType == DataControlRowType.DataRow)
{
if (e.Row.RowState == DataControlRowState.Normal || e.Row.RowState == DataControlRowState.Alternate)
{
((LinkButton)e.Row.Cells[1].Controls[0]).Attributes.Add( "onclick ", "javascript:return confirm( '你确认要删除:\ " " + e.Row.Cells[1].Text + "\ "吗? ') ");
}
}

}


------解决方案--------------------
1.在ItemDataBound事件中写,
if ((e.Item.ItemType == ListItemType.Item) || (e.Item.ItemType == ListItemType.AlternatingItem))
{


// 添加删除确认函数
LinkButton link = (LinkButton)e.Item.Cells[e.Item.Cells.Count-1].Controls[0];
link.Attributes.Add( "onclick ", "return confirmDelete( ' " + e.Item.Cells[1].Text + " '); ");
}

2.在前台写
<script language= "javascript ">
<!--
function confirmDelete(code) // 确认删除
{
return confirm( "您确认删除当前选记录吗? ");

}
//-->
</script
3.这是datagrid改一下就行了,要在grid中增加一个模板列()
------解决方案--------------------
btn.Attributes[ "onclick "] = "javascript:return confirm( '是否删除? '); ";
------解决方案--------------------
星星们正解,呵呵.
------解决方案--------------------
http://www.dj9158.com/ReadCode/397.html

http://www.dj9158.com/ReadCode/175.html

http://www.dj9158.com/ReadCode/248.html

http://www.dj9158.com/ReadCode/220.html
------解决方案--------------------
private void DataGrid1_ItemCreated(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
{
switch(e.Item.ItemType)
{
case ListItemType.Item:
case ListItemType.AlternatingItem:
case ListItemType.EditItem:
TableCell myTableCell;
myTableCell = e.Item.Cells[0];
LinkButton myDeleteButton;
myDeleteButton = (LinkButton)myTableCell.Controls[0];
myDeleteButton.Attributes.Add( "onclick ", "return confirm( '您真的要删除吗? '); ");
break;
  default:
  break;
}
}

如果删除是在第一列就用Cells[0];在第二列用Cells[1];别的以次类推!
------解决方案--------------------
<asp:LinkButton ID= "LinkButton2 " runat= "server " CausesValidation= "False "
CommandName= "Delete " OnClientClick= "return confirm( '确定删除吗? ') "
Text= "删除 " ToolTip= ' <%#Eval( "Id ").ToString() %> '> </asp:LinkButton>
------解决方案--------------------
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
//如果是绑定数据行
if (e.Row.RowType == DataControlRowType.DataRow)
{
if (e.Row.RowState == DataControlRowState.Normal || e.Row.RowState == DataControlRowState.Alternate)