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

How To Capture Previous GridRows BackColor (as set by AlternatingItemStyle)?

1 Answer 40 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Marge
Top achievements
Rank 1
Marge asked on 04 Aug 2011, 04:43 PM
Hello,
 My Goal: To use the default AlternatingItemStyle. To evaluate each grid row, if that grid rows Order column = PreviousRow's Order column, then set the CurrentRows.BackColor = PreviousRows.Backcolor.

My Problem seems to be, that the BackColor doesn't exist in the RadGrid_ItemDataBound() event.
I don't want to set my own AlternatingItemStyle in a .CSS for this, because My Whole Site is managed via Telerik Skins, and if I want to chagne the skin, i don't want to have to change this AlternatingStyle to match.

How can I capture what the Color is?

My Code:

 

 

//Changing the backcolor so that rows w/ the same order number show the same color
if (e.Item is GridDataItem && e.Item is GridTableRow)
{
    int rowNumber =  e.Item.DataSetIndex;
      
    if (rowNumber >= 1)
    {
        GridDataItem previousRow = RadGrid1.Items[rowNumber - 1];
        GridDataItem currentRow = (GridDataItem)e.Item;
        string prevMilestoneOrder = previousRow["Order"].Text;
        //Set current row back color to previous row back color if they have the same order
        if (prevMilestoneOrder.Equals(currentRow["Order"].Text))
            currentRow.BackColor = previousRow.BackColor;              //<------- previousRow.BackColor does not exist yet
    }
}

 

 


1 Answer, 1 is accepted

Sort by
0
Tsvetina
Telerik team
answered on 10 Aug 2011, 08:20 AM
Hi Taras,

The backcolor is not available because CSS classes are used to provide the styles for RadGrid. Therefore, instead of looking for a backcolor, you should look at the CSS class. Sample code is available below:
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
{
    if (e.Item is GridDataItem)
    {
        //perform your logic about the item here
        if (e.Item.ItemType == GridItemType.Item)
        {
            e.Item.CssClass = "rgAltRow";
        }
        else e.Item.CssClass = "rgRow"; //else means here that e.Item.ItemType == GridItemType.AlternatingItem
    }
}

I hope this helps.

Regards,
Tsvetina
the Telerik team

Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

Tags
Grid
Asked by
Marge
Top achievements
Rank 1
Answers by
Tsvetina
Telerik team
Share this question
or