【问题标题】:How do i hide a row in grid when clicked on image button which is in that row?单击该行中的图像按钮时,如何在网格中隐藏一行?
【发布时间】:2013-02-28 10:58:38
【问题描述】:

我有几列的网格,其中一列是图像。单击该图像时,我希望该行隐藏。

当我点击最后一列时,我的行必须被隐藏,

我怎样才能做到这一点

【问题讨论】:

    标签: .net gridview datagridview


    【解决方案1】:

    这几个步骤将对您有所帮助。

    1. 确保您单击的图像列是一个 ImgaeButton
    2. Imgaebutton 将具有 CommandName 和 CommandArguement 属性
    3. 使用 gridview 的 RowCommand 事件可以为您解决问题。

    类似的东西。

    <asp:GridView ID="GridView1" runat="server" Width="100%" AutoGenerateColumns="False" OnRowCommand="GridView1_RowCommand">
        <Columns>
            <asp:TemplateField>
            <ItemTemplate>
                <asp:ImageButton runat="server" id="gvibtn"
                                 CommandName="HideRow" 
                                 CommandArgument='<%# Container.DisplayIndex %>'
                                 Text='<%# Bind("Text") %>'>       
                </asp:ImageButton>
            </ItemTemplate>
            </asp:TemplateField>
        </Columns>
    </asp:GridView>
    

    后面的代码看起来像这样。

    protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if(e.CommandName == "HideRow")
        {
            int rowIndex = Convert.ToInt32(e.CommandArgument);
            // now you got the rowindex, run your hiding logic here.
        }
    } 
    

    【讨论】:

      【解决方案2】:

      为图像单元格的点击事件编写一个事件处理程序。该事件的发送者将是图像单元格。您可以将发送者转换回一个单元格,然后获取该单元格的父单元(将是行)并将父行的 Visible 属性设置为 false。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2010-12-19
        • 2014-06-02
        • 2013-12-06
        相关资源
        最近更新 更多