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

RadGrid formatting only works on original page load

4 Answers 83 Views
Grid
This is a migrated thread and some comments may be shown as answers.
AndyL
Top achievements
Rank 1
AndyL asked on 02 Dec 2008, 04:12 PM
Hi

I have a problem whereby I am applying a certain style to different rows on the RadGrid depending on a condition. (It's like outlook where an unread item is bold). I apply the style just after databinding like this (where I crossreference a couple of datatables)...

 

'bold unread items
For Each gd As Telerik.Web.UI.GridDataItem In gvDocumentListing.MasterTableView.Items
gd.Font.Bold =
True
For Each dr As DataRow In dtRead.Rows
If gd.Item("DocID").Text = dr.Item("DocID") Then
gd.Font.Bold = False
Exit For
End If
Next
Next

The problem is that it only works on the original page load, but if I sort the grid or move to a different page all the items appear with normal styling. I checked that it is running the formatting code but it's just not applying it after postback.

Any help would be appreciated.

Thanks
AndyL

4 Answers, 1 is accepted

Sort by
0
Vlad
Telerik team
answered on 03 Dec 2008, 07:08 AM
Hello AndyL,

You do not need to loop all items instead of this you can use ItemDataBound to achieve the same:

If TypeOf e.Item Is GridDataItem Then
    Dim myDataRowView As DataRowView = CType(e.Item.DataItem, DataRowView) ' in case of DataRowView
    If myDataRowView("MyField") = MyValue Then
       e.Item.Font.Bold = True
    End If
End If

All the best,
Vlad
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
AndyL
Top achievements
Rank 1
answered on 03 Dec 2008, 04:37 PM
Hi Vlad

Actually, that's not the problem. I have to loop through because whether an item is going to be bold or not is stored in the database. The data in the row does not say if it will be bold or not. It is another table I have to crossreference. I am still stuck with the same problem.

The formatting works perfectly but only on the first load.

If I post back to the grid with sorting or paging functions, it executes the code I showed you (I execute it after each datasource change), but it doesn't mark any items as bold or change any formatting from standard. It only works when the grid is first loaded.

I hope you can help and thanks for replying.

Thanks
AndyL
0
Accepted
Iana Tsolova
Telerik team
answered on 05 Dec 2008, 03:08 PM
Hi AndyL,

Could please specify where are you calling the preceding code? Can you try executing it on RadGrid PreRender event and check if it makes any difference?

Let me know how it goes.

Sincerely yours,
Iana
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
AndyL
Top achievements
Rank 1
answered on 05 Dec 2008, 05:48 PM
Thank you Iana, moving the code to the PreRender event has fixed the problem.

I was previously calling it from a function I put in the SortCommand and Paging event.

Thanks
AndyL
Tags
Grid
Asked by
AndyL
Top achievements
Rank 1
Answers by
Vlad
Telerik team
AndyL
Top achievements
Rank 1
Iana Tsolova
Telerik team
Share this question
or