如何在 c# 中的编辑模式下仅显示列 GridView
本文关键字:显示 GridView 模式 编辑 | 更新日期: 2023-09-27 18:31:19
如何在编辑模式下仅显示列
在 aspnet c# GridView 中,仅当 GridView 处于"编辑模板"状态时,才可能显示一列?
我尝试过这段代码,但默认情况下.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>
在行数据绑定中尝试此操作:
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;
}
}