2014-01-21 120 views
0

我有一個gridview填充數據和基於Chekbox選擇我想隱藏editform上的一個字段。 任何人都可以請指導一下,有什麼更好的隱藏客戶端或服務器端代碼的列?,請找到下面的代碼供您參考(下面是devexpress網格中的4列(4個字段),當我們選擇複選框,然後列(Dropdown)之一應該隱藏。)。隱藏基於複選框選擇的特定gridview(Devexpress網格)字段

<dx:GridViewDataTextColumn FieldName="Name" VisibleIndex="1" Caption="Name"> 
</dx:GridViewDataTextColumn> 
<dx:GridViewDataTextColumn FieldName="Email" VisibleIndex="2" Caption="Email"> 
</dx:GridViewDataTextColumn> 
<dx:GridViewDataCheckColumn FieldName="IsGraduate" VisibleIndex="3" Caption="Is Graduate "> 
</dx:GridViewDataCheckColumn> 
<dx:GridViewDataComboBoxColumn Caption="Degree" FieldName="Degree" 
ShowInCustomizationForm="True" VisibleIndex="4"> 
<PropertiesComboBox DataSourceID="DegreeDataSource" TextField="Degree" ValueField="Id"> 
</PropertiesComboBox> 
</dx:GridViewDataComboBoxColumn> 
+0

上面看起來像asp.net。你確定標籤devexpress-windows-ui或devepxress-wpf是相關的嗎? – surfmuggle

+0

是的,很確定,我正在使用Asp.net並使用devepxress Grid。 – Vishal

+0

也許這只是我,但[asp.net webforms](https://demos.devexpress.com/ASPxGridViewDemos/DataBinding/LinqDataSourceServerMode.aspx)看起來接近上面的代碼。 [mvc](https://demos.devexpress.com/MVCxGridViewDemos/DataBinding/DataBindingToLargeDatabase)代碼看起來不像您的代碼。在[asp.net的演示頁面](https://www.devexpress.com/Products/NET/Controls/ASP/demos.xml)中沒有提及wpf。你使用的是mvc還是webforms? – surfmuggle

回答

0

您是否嘗試將EditFormSetting可見性用於必要的列?看看下面的例子

 <dx:GridViewDataComboBoxColumn FieldName="color" Caption="#" VisibleIndex="2" ReadOnly="True" 
      Width="25px"> 
      <HeaderStyle HorizontalAlign="Center" /> 
      <PropertiesComboBox DataSourceID="ColoredStatusSource" TextField="name" ValueField="id" 
       EnableSynchronization="False" IncrementalFilteringMode="Contains" ValueType="System.Int32"> 
      </PropertiesComboBox> 
      <EditFormSettings Visible="False" /> 
     </dx:GridViewDataComboBoxColumn> 
0

如果你通過使用客戶端事件來防止回調來隱藏列會更好。 使用下列代碼作爲指南:

Protected Sub dgView_001_CellEditorInitialize(sender As Object, e As DevExpress.Web.ASPxGridView.ASPxGridViewEditorEventArgs) Handles dgView_001.CellEditorInitialize 

    If e.Column.FieldName = "IsGraduate" Then 

     Dim chk As DevExpress.Web.ASPxEditors.ASPxCheckBox = New DevExpress.Web.ASPxEditors.ASPxCheckBox() 

     chk = TryCast(e.Editor, DevExpress.Web.ASPxEditors.ASPxCheckBox) 

     chk.ClientInstanceName = "chkIsGraduate" 

     chk.ClientSideEvents.CheckedChanged = "function(s, e){ //if checked = true, hide column you want to hide }" 

    ElseIf e.Column.FieldName = "Degree" Then 

     Dim cmb As DevExpress.Web.ASPxEditors.ASPxComboBox = New DevExpress.Web.ASPxEditors.ASPxComboBox() 

     cmb = TryCast(e.Editor, DevExpress.Web.ASPxEditors.ASPxComboBox) 

     cmb.ClientInstanceName = "cmbDegree" 

    End If 

    End Sub 

留意,你也應該指定一個客戶機實例名稱要隱藏你在使用JavaScript訪問它的列。希望這可以幫助! :)