This is a migrated thread and some comments may be shown as answers.

Row.HtmlAttributes["class"]="css_class_name" is not working.

1 Answer 374 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Nikhil
Top achievements
Rank 1
Nikhil asked on 11 Feb 2013, 12:30 PM
Hi,
I need to give a specific class to a row based on some condition, so i used following code to add class to that row

 @(Html.Kendo().Grid((IEnumerable<model>))
                           .Name("ABCDSource")
                           .Columns(columns =>
                           {
                               columns.Bound(d => d.col).Title("col").
                               columns.Bound(d => d.col1).Title("col1");
                               columns.Bound(d => d.col2).Title("col2");
                               columns.Bound(d => d.col3).Title("col3");
                           })
.RowAction(row=>
                               {
                                  
                                   row.HtmlAttributes.Add("style", "background:red;");
                                // "DataItem" is the Order object to which the current row is bound to
                                   if (row.DataItem.Istrueval== true)
                                   {
                                       //Set the background of the entire row
                                       row.HtmlAttributes["style"] = "background-color:blue";
                                       row.HtmlAttributes["class"] = "deleted-row";
                                   }
     
                               })....... 

I have added these properties to the row
1.style and
2. class
but both attributes are not getting applied to that row. And rest of the code don't have any syntactical error.  

Please could you suggest a solution? 

1 Answer, 1 is accepted

Sort by
0
Dimo
Telerik team
answered on 12 Feb 2013, 12:08 PM
Hello Nikhil,

Assuming that you are using server-side databinding, the described approach should work. The following code produces the expected result on my side:

.RowAction(row =>
{
    //row.HtmlAttributes.Add("style", "background:red"); // works either way
    row.HtmlAttributes["style"] = "background:blue"; // works either way
    row.HtmlAttributes["class"] = row.DataItem.ProductID;
})

Try debugging to verify that the IF statement is evaluated to TRUE.

Greetings,
Dimo
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Tags
Grid
Asked by
Nikhil
Top achievements
Rank 1
Answers by
Dimo
Telerik team
Share this question
or