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

DataGrid
点击DataGrid删除按钮后,弹出提示是否删除,选择是后执行DeleteCommand程序,该如何做?

------解决方案--------------------
up
------解决方案--------------------
在删除按键中添加: onClientClick= "return confirm( '确定要删除吗 ') "
------解决方案--------------------
你的删除按钮用的是模板列 还是 按钮列中的删除?
------解决方案--------------------
private void dgd_NewsList_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
{
//确保处理的是数据行,而不是Header或者Footer
if(e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
e.Item.Attributes.Add( "onMouseOver ", "this.style.backgroundColor= '#f2fbed ' ");
e.Item.Attributes.Add( "onMouseOut ", "this.style.backgroundColor= ' ' ");
//删除确认
LinkButton delBttn = (LinkButton) e.Item.Cells[7].Controls[0];
string strTitle=Convert.ToString (DataBinder.Eval(e.Item.DataItem, "NewsTitle "));
strTitle=strTitle.Replace( "\r\n ", " ");
delBttn.Attributes.Add( "onclick ", "javascript:return confirm( '确定删除\ " " +strTitle+ "\ "? '); ");
}
}
------解决方案--------------------
/// <summary>
/// 删除新闻信息
/// </summary>
/// <param name= "source "> </param>
/// <param name= "e "> </param>
private void dgd_NewsList_DeleteCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
string strNewsID=e.Item.Cells[1].Text;
try
{
//删除文件
deleteFile(strNewsID,e.Item.Cells[9].Text);
//news
string strSqlDelete= "delete from Tb_news where NewsId= "+strNewsID;
DbHelperSQL.ExecuteSql(strSqlDelete);
//数据绑定
datagridbind(true);
}
catch
{}

}