RadGrid OnNeedDataSource problem

6 posts, 2 answers
  1. Mark
    Mark avatar
    23 posts
    Member since:
    Sep 2014

    Posted 08 Dec 2014 Link to this post

    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)



  2. Mark
    Mark avatar
    23 posts
    Member since:
    Sep 2014

    Posted 09 Dec 2014 in reply to Mark Link to this post

    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.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Answer
    Eric
    Eric avatar
    16 posts
    Member since:
    Feb 2013

    Posted 09 Dec 2014 in reply to Mark Link to this post

    The ItemDataBound event is the proper place to do that kind of manipulation.

    The NeedsDataSource event is fired, and then at a later time, the items are then bound. Each items being bound calls the ItemDataBound event and allows you to handle whatever you need to when that items is binding.
  5. Answer
    Eyup
    Admin
    Eyup avatar
    3012 posts

    Posted 11 Dec 2014 Link to this post

    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.

     
  6. Mark
    Mark avatar
    23 posts
    Member since:
    Sep 2014

    Posted 11 Dec 2014 in reply to Eric Link to this post

    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 ?
  7. Eyup
    Admin
    Eyup avatar
    3012 posts

    Posted 16 Dec 2014 Link to this post

    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.

     
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017