2010-11-18 50 views
0

我有這個得到頭的電池

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e) 
    { 
     e.Row.Cells[0].Style.Add("text-align", "center"); 
    } 

我想使這個細胞無形的頭..我如何通過只知道單元格的值做到這一點...

它找不到頭...我在運行時創建的頭......這樣

GridView Grid = new GridView(); 
Grid.RowDataBound += Grid_RowDataBound; 


     Grid.ID = machGrps[j].ToString(); 
     //Grid.AutoGenerateColumns = false; 
     Grid.AllowSorting = false; 
     Grid.CellSpacing = 2; 
     Grid.ForeColor = System.Drawing.Color.White; 
     Grid.GridLines = GridLines.None; 
     Grid.Width = Unit.Percentage(100); 
     Grid.Style.Add(HtmlTextWriterStyle.Overflow, "Scroll"); 
     Grid.ShowHeader = true; 

DataTable taskTable = new DataTable("TaskList7"); 
taskTable.Columns.Add("MachineID"); 

DataRow tableRow = taskTable.NewRow(); 
tableRow["MachineID"] = machID[i]; 
taskTable.Rows.Add(tableRow); 
Grid.DataSource = taskTable; 
Grid.DataBind(); 

    protected void Grid_RowDataBound(object sender, GridViewRowEventArgs e) 
    { 
     if (e.Row.RowType == DataControlRowType.Header) 
      { 
       e.Row.Cells[0].Visible = false; 
      } 
    } 
+0

你想使一個單元的頭看不見?還是所有的細胞?我不認爲這是可能的使一個標頭不可見... – MrFox 2010-11-18 22:11:28

+0

一個標題..像單元格[0]隱藏的標題 – user175084 2010-11-18 22:14:05

+0

我可以通過e.Row [0] .Visible = false使單元格不可見; – user175084 2010-11-18 22:15:13

回答

2

對不起,VB.Net:

Select Case e.Row.RowType 
    Case DataControlRowType.Header 
     e.Row.Cells(0).Visible = False 
End Select 

編輯:C#

if (e.Row.RowType == DataControlRowType.Header){ 
    e.Row.Cells(0).Visible = False; 
} 
+0

它無法找到該行的標題..它不執行上述語句 – user175084 2010-11-18 22:36:19

+1

你有ShowHeader =「true」嗎?向我們展示您的網格的aspx標記。 您的網格是否包含行? – 2010-11-18 22:45:12

+0

正如你可以在我的代碼中看到的,我在運行時創建網格..所以沒有HTML代碼。當taskTable.Columns.Add(「MachineID」);被執行,並由它下面的代碼創建。 – user175084 2010-11-18 22:48:04