2013-01-09 18 views
0

我的GridView這樣在我從數據庫中獲取數據,並沒有標題欄gridview的第一行文字的cel

enter image description here

這個GridView控件沒有標題這些都是行only.Now問題是,我想格式化該列其中

在這裏你可以看到31 DEC是星期一,所以我想格式化每一列的日期是星期一。我想改變那列的星期一在第一行的顏色。所以任何一個可以告訴我在c#中執行此操作的想法。

+0

http://stackoverflow.com/questions/12608414/change-the- background-color-without-change-the-header-of-the-gridview – andy

+0

http://stackoverflow.com/questions/13153579/set-gridview-row-background-color-using-value-in-binding-dataset – andy

+0

先生我想修復列,而我想修復第一個單元格中的星期一 – user1915635

回答

0

我發現我自己的答案是這樣的

foreach (TableCell cell in e.Row.Cells) { 
        if (cell.Text != "-1" && cell.Text != "Cotton Arrival") { 

         char[] c = new char[7]; 
         c = cell.Text.ToCharArray(); 

         string datee = c[0].ToString()+c[1].ToString() ; 
         string monthh = c[2].ToString() + c[3].ToString(); 
         string yearr = c[4].ToString() + c[5].ToString() + c[6].ToString() + c[7].ToString(); 

         DateTime dtime = new DateTime(Convert.ToInt32(yearr),Convert.ToInt32(monthh),Convert.ToInt32(datee)); 

         string day = dtime.DayOfWeek.ToString() ; 

         if (day.ToLower() == "monday") 
         { 
          GridView1.Columns[count].ItemStyle.CssClass = "monday"; 
          GridView2.Columns[count].ItemStyle.CssClass = "monday"; 
          GridView3.Columns[count].ItemStyle.CssClass = "monday"; 
          GridView4.Columns[count].ItemStyle.CssClass = "monday"; 
          break; 
         } 
         count ++; 
        } 
       } 
2

這會幫助你對顏色名稱相符細胞

protected void grid_RowDataBound(Object sender, GridViewRowEventArgs e) 
{ 
    if (e.Row.RowType = DataControlRowType.DataRow) 
    { 
    //Check your condition here 
    //Get Id from here and based on Id check value in the 
    //underlying dataSource Row Where you have "Done" column Value 
    // e.g. 
    // (gridview.DataSource as DataTable), now you can find your row and cell 
    // of "Done" 
    If(Condition True) 
    { 
     e.Row.BackColor = Drawing.Color.Red // your color settings 
    } 
    } 
}