GridView删除提示

在GridView中添加一个模板列:LinkButton.设置CommandName="Delete",OnClientClick="return confirm('确认要删除吗?');"

Html代码如下:


< asp:TemplateField  HeaderText ="删除" >
                                
< ItemTemplate >
                                    
< asp:LinkButton  ID ="LinkButton1"  runat ="server"  CommandName ="Delete"  OnClientClick ="return confirm('确认要删除吗?');" > 删除 </ asp:LinkButton >
                                
</ ItemTemplate >
                            
</ asp:TemplateField >

然后把删除代码写在RowDeleting事件中:

protected   void  GridView1_RowDeleting( object  sender, GridViewDeleteEventArgs e)
    
{
        
int j = Convert.ToInt32(GridView1.DataKeys[e.RowIndex].Value);
        addb.DeleteADType(j);
        GridView1.DataSource 
= addb.GetAdType().Tables[0];
        GridView1.DataBind();
    }

你可能感兴趣的:(GridView)