在datagrid中当删除是怎样弹出对话框
private void DataGrid1_DeleteCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
int nyqID=(int)this.DataGrid1.DataKeys[e.Item.ItemIndex];
string connString = "server=(local);database=yqsb;uid=sa;pwd=1111;";
string sql = @"DELETE FROM admint WHERE yqID = " +nyqID.ToString();
SqlConnection conn = new SqlConnection(connString);
SqlCommand cmd = new SqlCommand(sql, conn);
cmd.Connection.Open();
try
{
cmd.ExecuteNonQuery();
}
catch (SqlException)
{
// handle exception...
}
finally
{
cmd.Connection.Close();
}
DataGrid1.EditItemIndex = -1;
this.daYQ.Fill(this.dsYQ1.admint);
DataBind();
}
我用过下面这段代码,但弹不出!
private void DataGridNews_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
{
if(e.Item.ItemIndex>=0)
{
LinkButton LB=(LinkButton)e.Item.Cells[1].Controls[0];
LB.Attributes.Add("onclick","if(!confirm(确定要删除该条记录吗?)) return false;");
}
}
NO.1 作者: gOODiDEA
<asp:ButtonColumn Text="<div id=de onclick="javascript:return confirm(是否删除...);">删除</div>" HeaderText="操作" CommandName="Delete">
<HeaderStyle Width="10%"></HeaderStyle>
<ItemStyle HorizontalAlign="Center"></ItemStyle>
</asp:ButtonColumn>
NO.2 作者: zwztu
直接将删除按钮列的text属性改为"<div id=de onclick="javascript:return confirm(是否删除...);">删除</div>"即可在删除时确认