Preventing databind in PageLoad

10 posts, 0 answers
  1. Patrik Johansson
    Patrik Johansson avatar
    274 posts
    Member since:
    May 2010

    Posted 07 Feb 2011 Link to this post

    How do we prevent data binding form occuring in PageLoad and, here's the catch, still get the RadGrid to display including the filters, which we use as a search form? Something like:

            if (e.RebindReason != GridRebindReason.InitialLoad)
                ((RadGrid)sender).DataSource = new object[] { };

    Will prevent the data binding, but it will also prevent the user from ever doing a real search :)

  2. Patrik Johansson
    Patrik Johansson avatar
    274 posts
    Member since:
    May 2010

    Posted 07 Feb 2011 Link to this post

    Can answer my own question, to help others who may face the same problem. Basically, what we did was to create an empty "resultset" from the Business Layer, and bound to that:

    if (e.RebindReason == GridRebindReason.InitialLoad)
        ((RadGrid)sender).DataSource = new List<BookTransaction>[] { };
    else
    {
        ((RadGrid)sender).DataSource = eodsObjectDataSourceBookTransaction;
     
    }

    (Please note that we are using Entity Framework thus working with real objects, BookTransaction is an entity).
  3. Patrik Johansson
    Patrik Johansson avatar
    274 posts
    Member since:
    May 2010

    Posted 10 Feb 2011 Link to this post

    Turns out this affected updates/inserts also (for obvious reasons). Is there a way to prevent databind at PageLoad(), but still be able to use automatic dataoperations etc as you would normally do? The only thing we want to do is to prevent the RadGrid from binding at PageLoad(), but still be displayed as the searchform is implemented as filters in the grid, but the rest should be the same.

    I know you can use the RadGrid1_UpdateCommand but that solution I feel is a bit to complicated and hard to maintain, and it doesn't work to well using Entity Framework (where objects are used). I guess you would be forced to use statements like

    MyObject.MyProperty = updatedValues.myNewValue

    which is hard to maintain over time.


  4. Nikolay Rusev
    Admin
    Nikolay Rusev avatar
    2289 posts

    Posted 10 Feb 2011 Link to this post

    Hello Patrik,

    Yes, the approach from your last post should do the trick for you.

    Best wishes,
    Nikolay
    the Telerik team
    Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
  5. Patrik Johansson
    Patrik Johansson avatar
    274 posts
    Member since:
    May 2010

    Posted 10 Feb 2011 Link to this post

    Yes, it will, but when wokring with objects, it will force you to use reflection to be able to fill the object properties with the values from the EditForm, which is a bit complex.

    An alternative solution, which perhaps isn't the prettiest, but should be easier to maintain, would be to have a filterExpression that would make sure you got no hits, which would result in an empty RadGrid (even though it would do a roundtrip to the database). In our case, we actually export the filterExpression in LINQ to the Business Layer, so this roundtrip wouldn't be to coslty (no rows would be sent from the database). Telerik, what would be the best method of implementing such a solution? I guess what we are talking about would be some kind of default filterExpression which would only last the first databind (PageLoad), which is then replaced with "real" filterExpressions as the search form/filter form is used (which should be handled by itself, stanard procedure).
  6. Patrik Johansson
    Patrik Johansson avatar
    274 posts
    Member since:
    May 2010

    Posted 11 Feb 2011 Link to this post

    We experimented a bit with filterExpressions by simply setting it to "false" by default:

    FilterExpression="false"

    and this seem to work quite well, and is a solution much easier to maintain we think. In our case, we export the LINQ filterExpression to our BusinessLayer and DataLayer, so we won't actually fetch any unnecessary data, but I guess it could be used by anyone wanting to have an empty grid on pageload no matter what, if you are prepared to do the databind and load data, even though it wont be displayed by the RadGrid.
  7. Nikolay Rusev
    Admin
    Nikolay Rusev avatar
    2289 posts

    Posted 16 Feb 2011 Link to this post

    Hello Patrik,

    You will need at least binding to empty collection in order RadGrid to render it's structure.

    Best wishes,
    Nikolay
    the Telerik team
    Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
  8. Patrik Johansson
    Patrik Johansson avatar
    274 posts
    Member since:
    May 2010

    Posted 16 Feb 2011 Link to this post

    Nikolay, what is this latest replyan answer to? I mean, isn't it a repeate of what was written in the second reply above? :)
  9. Nikolay Rusev
    Admin
    Nikolay Rusev avatar
    2289 posts

    Posted 22 Feb 2011 Link to this post

    Hello Patrik,

    Yes it is repeated with the statement in the second reply.

    Nikolay
    the Telerik team
    Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!
  10. Suresh
    Suresh avatar
    3 posts
    Member since:
    Oct 2017

    Posted 26 Oct 2017 Link to this post

    Hello All and Telerik Admin,

    I have tried one trick that is... I added an "if condition" of Page.IsPostback

    If page is postback, I let the "OnNeedDataSource" code run else nothing.. And it seems working...

     

    Could you please confirm if this approach is good to go with?

     

Back to Top