2017-08-01 15 views
0

我有下次处理fowFormatting我的细胞代码:如何在行(Telerik)中绘制单元格?

private void gridViewRaces_RowFormatting(object sender, RowFormattingEventArgs e) 
    { 
     foreach (var cellColumn in e.RowElement.Data.Cells) 
     { 
      var cellInfo = cellColumn as GridViewCellInfo; 
      if (cellInfo != null) 
      { 
       cellInfo.Style.DrawFill = true; 
       if (cellInfo.ColumnInfo.Name == "columnContactProducerName") 
       { 
        cellInfo.Style.DrawFill = true; 
        cellInfo.Style.BackColor = Color.Yellow; 
       } 
       else if (cellInfo.ColumnInfo.Name == "columnTransport") 
       { 
        cellInfo.Style.BackColor = Color.Yellow; 
       } 
       else 
       { 
        cellInfo.Style.BackColor = ColorTranslator.FromHtml((e.RowElement.Data.DataBoundItem as RaceForListDto).Color); 
       } 
      } 

     } 
     //e.RowElement.BackColor = ColorTranslator.FromHtml((e.RowElement.Data.DataBoundItem as RaceForListDto).Color); 
    } 

,但我的细胞不会画画。如何在dataBinding的行上绘制一些单元格?

+0

您正在使用的WebForms? MVC? WPF? – Seano666

+0

我正在使用webforms – destroyer25t

回答

1

看起来正确的事件是ItemDataBound事件。在这里看到:

http://docs.telerik.com/devtools/aspnet-ajax/controls/grid/appearance-and-styling/conditional-formatting

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["Size"].Text) > 100) 
    { 
     dataBoundItem["Received"].ForeColor = Color.Red; 
     dataBoundItem["Received"].Font.Bold = true; 
     //Customize more... 
    } 
} 
} 

或事件更是使用自定义的CSS类,以便以后可以进行更改,而无需重建项目:

protected void RadGrid1_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e){ 
if (e.Item is GridDataItem) 
{ 
    GridDataItem dataItem = e.Item as GridDataItem; 
    if (dataItem["Country"].Text == "Mexico") 
     dataItem.CssClass = "MyMexicoRowClass"; 
} 
} 
相关问题