綁定刪除控件IMAGEBUTTON:
<asp:GridView ID="GridView1" runat="server" BorderColor="#BCD2A3"
BorderWidth="1px" CellPadding="4" Width="966px"
AutoGenerateColumns="False" HeaderStyle-Height="30px"
Font-Size="13px" onrowcommand="GridView1_RowCommand">
<Columns>
<asp:BoundField DataField="name" HeaderText="用戶組名稱" ItemStyle-CssClass="padlef">
<HeaderStyle Font-Bold="True" Font-Size="13px"/>
<ItemStyle CssClass="padlef"></ItemStyle>
</asp:BoundField>
<asp:BoundField DataField="rights" HeaderText="管理權限">
<HeaderStyle Font-Bold="True" Font-Size="13px"/>
</asp:BoundField>
<asp:TemplateField ItemStyle-HorizontalAlign="Center">
<ItemTemplate>
<asp:ImageButton ID="ImageButton1" runat="server" Width="23px" Height="21px"
ImageUrl="~/image/gvdelimg.jpg" CommandArgument='<%# bind("id") %>' CommandName="del" OnClientClick="return confirm('您確定要刪除該條信息嗎?');"/>
</ItemTemplate>
<ItemStyle HorizontalAlign="Center"></ItemStyle>
</asp:TemplateField>
<asp:BoundField DataField="id" Visible="False" />
</Columns>
<RowStyle BackColor="White" ForeColor="black" BorderColor="#BCD2A3" BorderWidth="1px" BorderStyle="Solid" Height="35px"/>
<FooterStyle/>
<PagerStyle HorizontalAlign="Center"/>
<SelectedRowStyle Font-Bold="True"/>
<HeaderStyle Font-Bold="True" ForeColor="black" CssClass="gv1" />
</asp:GridView>
--------------------------------------------------------------------------------------------------------------------------------------------
cs代碼:
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
string rcn = e.CommandName.ToString();
if(rcn=="del")
{
if(e.CommandArgument!=null)
{
if (agp.GetGroupPer(Convert.ToInt32(e.CommandArgument)) == false)
{
if (agp.Delete(Convert.ToInt32(e.CommandArgument)) == "success")
{
ScriptManager.RegisterStartupScript(this, this.GetType(), "", "alert('刪除成功!');", true);
dt = agp.GetUserGroupLst();
this.GridView1.DataSource = dt;
this.GridView1.DataBind();
}
else
{
ScriptManager.RegisterStartupScript(this, this.GetType(), "", "alert('刪除失敗!');", true);
}
}
else
{
ScriptManager.RegisterStartupScript(this, this.GetType(), "", "alert('請先移走此組內管理員再嘗試刪除');", true);
}
}
}
}