vs05:
<asp:Button ID="Button1" runat="server" Text="Button" OnClientClick="return confirm('是否删除?')" OnClick="Button1_Click"/>
//
vs03:
Page_Load
Button1.Attributes.Add("onclick","return confirm('是否删除?')");
//
private void Bind()
{
try
{
string strSql="select * from loupan order by id desc";
DataSet ds=new DataSet();
ds=cmd.GetDS(strSql);
this.DataGrid1.DataSource=ds;
this.DataGrid1.DataBind();
for(int i=0;i<this.DataGrid1.Items.Count;i++)
{
//找到DataGrid中的删除按钮
((LinkButton)this.DataGrid1.Items[i].Cells[10].Controls[0]).Attributes.Add("onclick","return confirm('确定要删除吗?')");
}
}
catch(Exception Err)
{
Response.Write(Err.Message);
}
}
//删除事件
private void DataGrid1_DeleteCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
try
{
int id=int.Parse(e.Item.Cells[0].Text);
string strSql="delete from loupan where id="+id+"";
string msg=cmd.GetCmd(strSql);
Page.RegisterStartupScript("","<script>alert('"+msg+"');</script>");
this.Bind();
}
catch(Exception Err)
{
Response.Write(Err.Message);
}
}