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

RadGrid OnNeedDataSource problem

4 Answers 59 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Mark
Top achievements
Rank 1
Mark asked on 08 Dec 2014, 10:18 PM
Hi Telerik, 

I posted a thread a couple of days ago and I thought I had solved my problem but turns out I just moved it.

My problem now is that I have template columns that contain buttons and others that have text that needs to be on a different color depending on the status of the item.

So basically, I used to bind my grid using the 'simple way' (Create data table, add source to the grid and bind)
Once it was bound, I would go through each rows, set the text to the button and set the appropriate CSS on the text label. 

Since I needed to sort and to filter, I saw that I could use the 'OnNeedDataSource' event, which is the second way to bind a grid.

This worked and I could sort/filter my grid.

But now, after the event is called, I tried to change the CSS and the text again but it says that the grid doesnt have any items.

I believe its because it wasnt bound (even though I can see the rows once everything is done)



4 Answers, 1 is accepted

Sort by
0
Mark
Top achievements
Rank 1
answered on 09 Dec 2014, 07:20 PM
Once again, I found the answer myself after looking at the available methods on the gridview.
If you want to change values on specific rows (in my case the text/style according to the row's content), you have to do them in the method OnDataBound. It would really be useful to add this to your documentation because it only says you need OnNeedDataBind and thats it, which isnt the case.
0
Accepted
Eyup
Telerik team
answered on 11 Dec 2014, 12:09 PM
Hello Mark,

For this requirement it is a better idea to use the item specific event handlers provided by RadGrid:
http://www.telerik.com/help/aspnet-ajax/grid-distinguish-differences-between-itemcreated-itemdatabound.html

You can also check the following article:
http://www.telerik.com/help/aspnet-ajax/grid-accessing-cells-and-rows.html

Hope this helps.

Regards,
Eyup
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Mark
Top achievements
Rank 1
answered on 11 Dec 2014, 04:47 PM
Okay, I'll take a look at this but as I replied earlier, OnDataBound worked too, the only thing is that since it wasnt linked to a specific item, I had to go through all of them, which is pretty much equivalent to calling ItemDataBound each time ?
0
Eyup
Telerik team
answered on 16 Dec 2014, 09:51 AM
Hi Mark,

Basically yes, however, the ItemDataBound event is raised nevertheless and it is specially designed for such cases.

Please feel free to turn to us if new questions arise.

Regards,
Eyup
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
Tags
Grid
Asked by
Mark
Top achievements
Rank 1
Answers by
Mark
Top achievements
Rank 1
Eyup
Telerik team
Share this question
or