C# 如何在c中仅在编辑模式GridView中显示列#
如何仅在编辑模式下显示列 在aspnet c#GridView中,当GridView处于编辑模板状态时,是否可以只显示一列 我尝试过此代码,但在default.aspx页面中,GridView在模板字段中显示一个空列:C# 如何在c中仅在编辑模式GridView中显示列#,c#,asp.net,gridview,C#,Asp.net,Gridview,如何仅在编辑模式下显示列 在aspnet c#GridView中,当GridView处于编辑模板状态时,是否可以只显示一列 我尝试过此代码,但在default.aspx页面中,GridView在模板字段中显示一个空列: <asp:TemplateField> <EditItemTemplate> <asp:DropDownList ID="Mono" runat="server"> <asp:ListIte
<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;
}
}