2012-01-06 77 views
1

我有一個特定列的GridView Date。我已將列的Visible屬性設置爲false,因爲我想顯示不同的頁面條件。請告訴我,我該怎麼用vb.net我Date欄應該顯示或隱藏在運行時,它做Gridview顯示和隱藏特定的列

更新

我當前的代碼是

If Not Page.User.Identity.Name = "bilal" Then 
      GridView1.AutoGenerateEditButton = False 

      GridView2.AutoGenerateEditButton = False 
      GridView3.AutoGenerateEditButton = False 
     Else 
      GridView1.AutoGenerateEditButton = True 
      GridView1.AutoGenerateColumns = True 

      GridView1.DataBind() 
      If GridView1.Columns.Count > 0 Then 
       'assuming your date-column is the first ' 
       GridView1.Columns(3).Visible = True 
      Else 
       GridView1.HeaderRow.Cells(0).Visible = False 
       For Each gvr As GridViewRow In GridView1.Rows 
        gvr.Cells(0).Visible = True 
       Next 
      End If 



      GridView2.AutoGenerateEditButton = True 
      GridView3.AutoGenerateEditButton = True 

     End If 

回答

6

如果您已設置AutoGenerateColumnsTrue,列計數將爲0,那麼您需要循環行並顯示/隱藏適當的單元格。否則,您可以使用Visible屬性。

GridView1.DataBind() 
If GridView1.Columns.Count > 0 Then 
    'assuming your date-column is the 4.' 
    GridView1.Columns(3).Visible = True 
Else 
    GridView1.HeaderRow.Cells(3).Visible = False 
    For Each gvr As GridViewRow In GridView1.Rows 
     gvr.Cells(3).Visible = True 
    Next 
End If 
+0

是它的工作原理與autogenertae列,但它顯示在GridView中的所有coulmns,我想只顯示一列顯示或隱藏。我已經更新了我當前的代碼,以我的問題,請給我進一步建議 – 2012-01-06 09:48:54

+0

編輯我的回答提供正確的列索引(3)。你只是將它部分改爲3。 – 2012-01-06 10:01:21

+0

那麼現在我該怎麼做一個特定的顏色 – 2012-01-06 10:23:17