更改特定行的颜色(TELERIK)

问题描述:

我在我的网格中显示一个显示“INDEF”或“MA”的GridTemplateColumn。当它的“INDEF”,我想我行改颜色:更改特定行的颜色(TELERIK)

这是我的尝试:

protected void grid_ItemDataBound(object sender, GridItemEventArgs e) 
{ 
if (e.Item is GridDataItem) 
{ 
    GridDataItem item = (GridDataItem)e.Item; 
    Label lbl = (Label)item.FindControl("test"); 
    if (lbl.Text == "INDEF") 
    { 
    lbl.ForeColor = System.Drawing.Color.Red; 
    } 
} 
} 

与列的有问题的代码:

   <telerik:GridTemplateColumn HeaderText="Type de tickets" 
    UniqueName="typedestickets"> 
    <ItemTemplate><asp:Label id="test" runat="server"></asp:Label></ItemTemplate> 
</telerik:GridTemplateColumn> 

但我通过添加一个断点注意到e.Item不是GridDataItem,但GridPagerItem(我不知道为什么)

所以我试过这个:(不工作)

protected void RadGrid1_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e) 
{ 
    if (e.Item is GridPagerItem) 
    { 
     GridPagerItem item = (GridPagerItem)e.Item; 
     Label lbl = (Label)item.FindControl("test"); 



     if (lbl.Text == "INDEF") 
     { 
      lbl.ForeColor = System.Drawing.Color.Red; 
      item.BackColor = System.Drawing.Color.Red; 
      lbl.BackColor = System.Drawing.Color.Red; 

     } 
    } 
} 

在此先感谢您的帮助

试试这个

protected void RadGrid1_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e) 
{ 
    //Is it a GridDataItem 
    if (e.Item is GridDataItem) 
    { 
     //Get the instance of the right type 
     GridDataItem dataBoundItem = e.Item as GridDataItem; 

     //Check the formatting condition 
     if (int.Parse(dataBoundItem["typedestickets"].Text) =="INDEF") 
     { 
      dataBoundItem["typedestickets"].ForeColor = Color.Red; 
      dataBoundItem["typedestickets"].Font.Bold = true; 
      //Customize more... 
     } 
    } 
} 
+0

感谢您的快速答复,但我不明白你的代码,什么是“TicketType应该是什么?你为什么试图将databounditem投射到Int? 谢谢 – Slrg 2012-03-05 10:45:52

+0

我的意思是TicketType的列名和int作为列的类型。例如:如果要将名称为“Column1”的string类型的列绑定到标签,请使用dataBoundItem [“Column1”]。Text – PraveenVenu 2012-03-05 10:47:43

+0

GridTemplateColumn的uniqueName是typedestickets。所以我试着用: if(int.Parse(dataBoundItem [“typedestickets”] .Text)> 100) { dataBoundItem [“typedestickets”]。ForeColor = Color.Red; dataBoundItem [“typedestickets”]。Font.Bold = true; //自定义更多... } 但它不工作 错误“输入字符串格式不正确” – Slrg 2012-03-05 10:57:27