2014-11-21 21 views
0

如何只在編輯模式如何只在C#中的編輯模式的GridView

它在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

在行數據試試這個約束:

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; 
      } 
     } 
相關問題