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

rgAltRow

1 Answer 232 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Prathibarani
Top achievements
Rank 1
Prathibarani asked on 19 Nov 2013, 07:12 PM
Hi,

we are using latest version of RadGrid. We used radgrid default skin and modified the colors of rgRow and rgAltRow to suit our needs. It is working perfectly fine.

On one of the pages, when page loads, grid gets loaded. When user selects one of the item in dropdown list, in code we loop thru grid rows and based on certain conditions, we set row visible property to true or false. That means we are hiding some of the rows. In this scenario, rgrow or altrow color doesn't work. If the hidden row is rgRow, then rgaltrow color shows up for 2 rows and vice versa. So, what I want is, check for row (rgrow or altrow) and then make the next row the other. If rgrow is hidden, next row is rgAltrow. But make it as rgRow so alternate colors and rest are applied.

I appreciate your response.
Thanks,
Prathiba

1 Answer, 1 is accepted

Sort by
0
Venelin
Telerik team
answered on 22 Nov 2013, 10:19 AM
Hi Prathiba,

I am afraid that there is no built-in functionality to do this but you can easily implement it. Just subscribe the the grid's PreRender event and iterate through all rows. Then change the corresponding css classes:

C#:

protected void RadGrid1_PreRender(object sender, EventArgs e)
{
    int counter = 0;
    foreach (GridDataItem item in RadGrid1.Items)
    {
        if (item.Visible)
        {
            if (counter % 2 == 0)
            {
                item.CssClass = "rgAltRow";
            }
            else
            {
                item.CssClass = "rgRow";
            }
 
            counter++;
        }      
    }
}

Note: the solution assumes that rgRow and rgAltRow are the only classes on the rows. If you however have more classes make sure you are not overwriting them. The method can be made to be more clever and to take this in account too.

I hole this helps.

Regards,
Venelin
Telerik
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
Tags
Grid
Asked by
Prathibarani
Top achievements
Rank 1
Answers by
Venelin
Telerik team
Share this question
or