码迷,mamicode.com
首页 > 其他好文 > 详细

GridView移除(隐藏)行

时间:2014-09-16 19:02:50      阅读:175      评论:0      收藏:0      [点我收藏+]

标签: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='<%# 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;
            }
        }
    }
}


GridView移除(隐藏)行

标签:gridview   移除   隐藏      

原文地址:http://blog.csdn.net/jumtre/article/details/39320231

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!