首页 > 其他 > 详细

GridView移除(隐藏)行

时间:2014-09-16 19:02:51      阅读:244      评论:0      收藏:0      [点我收藏+]
前台相关代码:
<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移除(隐藏)行

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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!