2017-08-01 5 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

あなたはWebフォームを使用していますか? MVC? WPF? – Seano666

+0

私はウェブフォームを使用しています – 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"; 
} 
} 
関連する問題