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

Alternating row color of a particular column

1 Answer 79 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Savyo
Top achievements
Rank 1
Savyo asked on 23 May 2012, 02:14 PM
Hi,
      Can you please provide me a method to make the alternating row color of a particular column to blue color. Im using skin. How can I accomplish it in code behind.
Savyo

1 Answer, 1 is accepted

Sort by
0
Jayesh Goyani
Top achievements
Rank 2
answered on 23 May 2012, 02:23 PM
Hello Savyo,

protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
    {
        if (e.Item.ItemType == GridItemType.Item || e.Item.ItemType == GridItemType.EditItem)
        {
            GridDataItem item = e.Item as GridDataItem;
            item["ID"].ForeColor = System.Drawing.Color.Red;
        }
        else if (e.Item.ItemType == GridItemType.AlternatingItem || e.Item.ItemType == GridItemType.EditItem)
        {
            GridDataItem item = e.Item as GridDataItem;
            item["ID"].ForeColor = System.Drawing.Color.Yellow;
        }
}

OR

protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
    {
        
 
 
        if (e.Item is GridDataItem)
        {
            GridDataItem item = e.Item as GridDataItem;
            if (item.ItemIndex % 2 == 0)
            {
                item["ID"].ForeColor = System.Drawing.Color.Red;
            }
            else
            {
                item["ID"].ForeColor = System.Drawing.Color.Yellow;
            }
        }
}


Note : "ID" is column UniqueName.

Thanks,
Jayesh Goyani
Tags
Grid
Asked by
Savyo
Top achievements
Rank 1
Answers by
Jayesh Goyani
Top achievements
Rank 2
Share this question
or