首页 > 代码库 > GridView移除(隐藏)行

GridView移除(隐藏)行

前台相关代码:
<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=http://www.mamicode.com/''/>>

为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 =http://www.mamicode.com/= e.CommandArgument.ToString())>

GridView移除(隐藏)行