【问题标题】:How to display a column only in an edit mode GridView in c#如何仅在 C# 中的编辑模式 GridView 中显示列
【发布时间】:2014-11-21 15:27:11
【问题描述】:

如何仅在编辑模式下显示列

只有当 GridView 处于编辑模板状态时,aspnet c# GridView 才可能显示一列?

我已经尝试过这段代码,但在 default.aspx 页面中,GridView 在模板字段中显示一个空列:

<asp:TemplateField>
    <EditItemTemplate>
        <asp:DropDownList ID="Mono" runat="server">
            <asp:ListItem Value="" Text="---"></asp:ListItem>
            <asp:ListItem Value="Y" Text="Y"> </asp:ListItem>
            <asp:ListItem Value="N" Text="N"> </asp:ListItem>
        </asp:DropDownList>
    </EditItemTemplate>
</asp:TemplateField>

【问题讨论】:

    标签: c# asp.net gridview


    【解决方案1】:

    在行数据绑定中试试这个:

    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
            {
                if (GridView1.EditIndex >= 0)
                    return;
    
                if ((e.Row.RowState == DataControlRowState.Normal || e.Row.RowState == DataControlRowState.Alternate) &&
                (e.Row.RowType == DataControlRowType.DataRow || e.Row.RowType == DataControlRowType.Header))
                {
                    e.Row.Cells[4].Visible = false;
                }
            }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多