2014-07-25 52 views
2

我正在使用RadGrid顯示數據庫中的數據。如果在行顯示爲「拒絕」的狀態列中,我想將RadGrid中的行顏色更改爲紅色。如果狀態爲NULL,則該行將保持顯示爲白色。我已經試過這段代碼,但行仍然不會將顏色更改爲紅色。設置Telerik RadGrid的行顏色

try 
{ 
    if (dataBoundItem["status"].Text == "REJECTED") 
    { 
     TableCell cell = (TableCell)dataBoundItem["status"]; 
     cell.BackColor = System.Drawing.Color.Red; 
     dataBoundItem.BackColor = System.Drawing.Color.Red; 

     if (e.Item is GridDataItem) 
     { 
      GridDataItem dataBoundItem1 = e.Item as GridDataItem; 

      if (dataBoundItem1["Status"].Text != null) 
      { 
       cell.BackColor = System.Drawing.Color.Red; 
       dataBoundItem1.BackColor = Color.Red; 
       dataBoundItem1["status"].ForeColor = Color.Red; 
       dataBoundItem1["status"].Font.Bold = true; 
      } 
     } 
    } 
} 
catch 
{ } 
+1

如果拋出異常,你永遠不會知道。除去空的「catch」塊,看看是否能夠揭示這種情況。 –

+0

您能否提供radgrid標記代碼? –

回答

4

嘗試是這樣的:

using System.Drawing; 

protected void RadGrid1_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e) 
{ 
    if (e.Item is GridDataItem) 
    { 
    TableCell celltoVerify1 = dataBoundItem["status"]; 
    GridDataItem dataBoundItem = e.Item as GridDataItem; 
     if (celltoVerify1.Text== "REJECTED") 
     { 
      celltoVerify1.ForeColor = Color.Red;/// Only Change Cell Color 
      dataBoundItem.ForeColor = Color.Yellow; /// Change the row Color 
      //celltoVerify1.Font.Bold = true; 
      //celltoVerify1.BackColor = Color.Yellow; 
     } 
    } 
} 

讓我知道它是否適合你。