<asp:TemplateField HeaderText="移除"> <ItemStyle HorizontalAlign="Center" /> <ItemTemplate> <asp:LinkButton ID="LinkButtonRemove" runat="server" CommandName="Remove" CommandArgument='<%# Eval("CpId")%>' Text="移除" /> <asp:HiddenField ID="HiddenField1" runat="server" Value='<%# Eval("CpId") %>'/> </ItemTemplate> </asp:TemplateField>
为GridView添加OnRowCommand事件,事件名称为gridViewCPImportPercent_RowCommand,后台代码:
protected void gridViewCPImportPercent_RowCommand(object sender, GridViewCommandEventArgs e) { if (string.IsNullOrEmpty(e.CommandName) || e.CommandArgument == null) return; if (e.CommandName == "Remove") { for (int i = 0; i < gridViewCPImportPercent.Rows.Count; i++) { if ((gridViewCPImportPercent.Rows[i].FindControl("HiddenField1") as HiddenField).Value == e.CommandArgument.ToString()) { gridViewCPImportPercent.Rows[i].Visible = false; break; } } } }
原文地址:http://blog.csdn.net/jumtre/article/details/39320231