如何更改Telerik ASP.NET网格的文本颜色

时间:2014-06-11 05:34:49

标签: c# javascript asp.net telerik telerik-grid

<%= Html.Telerik().Grid(Model)
    .Name("Grid")
    .ClientEvents(events => events.OnDataBinding("Grid_onDataBinding"))
%>

<script type="text/javascript">
    function Grid_onDataBinding(e){
        //handling code
    }
</script>

我需要更改databind事件中每列的文字颜色。如何通过Telerik Grid中的JavaScript访问Rowdata

1 个答案:

答案 0 :(得分:2)

您必须处理绑定行时触发的RowDataBound事件。然后,这将允许您访问行(TR)。

...
.ClientEvents(events => events.OnRowDataBound("Grid_onRowDataBound"))

function Grid_onRowDataBound(e) {
    var row = e.row;
    var dataItem = e.dataItem;

    row.className = "your-class-name";
    // Can also use row.cells
    // row.cells[1].innerHTML = "<span class='class-name'>" + dataItem.text + "</strong>";
}

样式

tr.your-class-name {
    color: red;
}