【问题标题】:How to paint cells in row (Telerik)?如何在行中绘制单元格(Telerik)?
【发布时间】:2018-01-08 06:57:48
【问题描述】:

我有下一个处理 fowFormatting 我的单元格的代码:

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 上绘制一些行中的单元格?

【问题讨论】:

  • 您在使用 WebForms 吗? MVC? WPF?
  • 我正在使用网络表单

标签: asp.net webforms telerik


【解决方案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";
}
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-03-17
    • 1970-01-01
    • 2017-12-14
    • 1970-01-01
    • 2012-04-21
    • 2016-11-12
    • 1970-01-01
    相关资源
    最近更新 更多