如何仅在编辑模式下显示列
在aspnet中有可能c#GridView只在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>
答案 0 :(得分:0)
在行数据绑定中尝试此操作:
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;
}
}