2012-04-11 82 views
0

我昨天實現了表分類器,我有一個問題,試圖改變單元格的顏色,如果某一時間少於當前時間我想改變單元格紅色,如果他們失敗這是我的C#代碼,我們原本只是有它工作得很好一個GridView,但我們想改變它,使其更快繼承人排序C#代碼JQuery Table Sorter插件樣式

protected void gvResult_rowDataBound(Object sender, GridViewRowEventArgs e) 
     { 
      DateTime AppointmentTime = DateTime.Now; 

      if (e.Row.RowType == DataControlRowType.DataRow) 
      { 
       AppointmentTime = Convert.ToDateTime(DataBinder.Eval(e.Row.DataItem, "AppointmentTime")); 

       if (AppointmentTime < DateTime.Now) 
       { 

        e.Row.CssClass = "gvRowRed"; 
        e.Row.Cells[0].CssClass = "white"; 
        e.Row.Cells[1].CssClass = "white"; 
        e.Row.Cells[2].CssClass = "white"; 
        e.Row.Cells[3].CssClass = "white"; 
        e.Row.Cells[4].CssClass = "white"; 
        e.Row.Cells[5].CssClass = "white"; 
        e.Row.Cells[6].CssClass = "white"; 
        e.Row.Cells[7].CssClass = "white"; 
       } 
       else if (AppointmentTime > DateTime.Now && AppointmentTime < DateTime.Now.AddHours(1)) 
       { 
        e.Row.CssClass = "gvRowGreen"; 
        e.Row.Cells[0].CssClass = "white"; 
        e.Row.Cells[1].CssClass = "white"; 
        e.Row.Cells[2].CssClass = "white"; 
        e.Row.Cells[3].CssClass = "white"; 
        e.Row.Cells[4].CssClass = "white"; 
        e.Row.Cells[5].CssClass = "white"; 
        e.Row.Cells[6].CssClass = "white"; 
        e.Row.Cells[7].CssClass = "white"; 
       } 
      } 


     } 

它的第一部分IM在此刻集中,所以如果appointmenttime少然後datetime.now我需要顏色的單元格背景紅色和字體的顏色白色,但由於某種原因背景顏色不會改變,只有字體的顏色做任何幫助瓦特不勝感激。

繼承人的CSS

table.tablesorter { 
    font-family:arial; 
    background-color: #CDCDCD; 
    margin:10px 0pt 15px; 
    width: 100%; 
    text-align: left; 
} 
table.tablesorter thead tr th, table.tablesorter tfoot tr th { 
    background-color: #336699; 
    border: 1px solid black; 
    padding: 10px 15px; 
    vertical-align:middle; 
    font:verdana; 
    color:White; 
} 
table.tablesorter thead tr .header { 
    background-image: url('/img/bg/bg.gif'); 
    background-repeat: no-repeat; 
    background-position: center right; 
    cursor: pointer; 
} 
table.tablesorter tbody td { 
    color: #3D3D3D; 
    padding: 4px; 
    background-color: #FFF; 
    vertical-align: top; 
} 
table.tablesorter tbody tr.odd td { 
    background-color:#F0F0F6; 
} 
table.tablesorter thead tr .headerSortUp { 
    background-image: url('/img/bg/asc.gif') ; 
    background-repeat: no-repeat; 
    background-position: center right; 
} 
table.tablesorter thead tr .headerSortDown { 
    background-image: url('/img/bg/desc.gif'); 
    background-repeat: no-repeat; 
    background-position: center right; 
} 
table.tablesorter thead tr .headerSortDown, table.tablesorter thead tr .headerSortUp { 
background-color: #8dbdd8; 
} 

.gvRowRed 
{ 
    background-color:Red !important; 
} 

.white 
{ 
color:#ffffff !important; 
} 

+0

你可以添加相關的css嗎? – 2012-04-11 09:25:31

+0

請參閱以上的CSS – 2012-04-11 09:28:56

回答

0

嘗試改變

.gvRowRed 
{ 
    background-color:Red !important; 
} 

.gvRowRed td 
{ 
    background-color:Red !important; 
} 

與同爲gvRowGreen - 它的應用類的行而不是細胞。

+0

優秀,工作正常!謝謝:D – 2012-04-11 09:34:03

+0

完全沒問題:) – 2012-04-11 09:39:22