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

Back Color Lost on Sorting

3 Answers 66 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Stuart Ferguson
Top achievements
Rank 1
Stuart Ferguson asked on 01 Jul 2011, 10:51 AM
I have put some additional logic into the ItemDataBound event to handle the conditional colour formatting which works perfectly on the initial screen display.  However when i click on one of my column headers to sort my data by the column the formatting is lost on the sorted column. 

Can anyone shed any light on why this is happening.

Here is my code from my ItemDataBound Event

protected void gridTxnEnquiry_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e)
{
    if (e.Item is GridDataItem)
    {           
        GridDataItem dataItem = (GridDataItem)e.Item;
         DataRow dr = ((DataRowView)e.Item.DataItem).Row;
 
        // Set the Back Colour depending on the Record Type
        int rectype = int.Parse(dr["RecordType"].ToString());
         switch (rectype)
        {
            case 0:
            dataItem.BackColor = Color.Blue
            break;           
            case 1:
            dataItem.BackColor = Color.Red
            break;
        }
    }
}

3 Answers, 1 is accepted

Sort by
0
Accepted
Princy
Top achievements
Rank 2
answered on 01 Jul 2011, 11:11 AM
Hello Stuart,

Try setting "SortingSettings-EnableSkinSortStyles" for retaining backcolor when sorting.

aspx:
<telerik:RadGrid ID="RadGrid1" runat="server" AutoGenerateEditColumn="false" AllowSorting="true"  SortingSettings-SortedBackColor="Blue"
 SortingSettings-EnableSkinSortStyles="false" DataSourceID="SqlDataSource1">
</telerik:RadGrid>

Thanks,
Princy.
0
Stuart Ferguson
Top achievements
Rank 1
answered on 01 Jul 2011, 12:09 PM
Hi Princy,

Would that not mean however the rows that are formatted Red would have that cell back colour set to blue?  I need the column basically to retain the colour that has been set in the ItemDataBound event.

Regards,

Stuart
0
Stuart Ferguson
Top achievements
Rank 1
answered on 01 Jul 2011, 02:07 PM
Hi Princy,

Sorry misread your answer, this has sorted the issue.

Thanks,

Stuart
Tags
Grid
Asked by
Stuart Ferguson
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Stuart Ferguson
Top achievements
Rank 1
Share this question
or