Grid load state using optional parameters

3 posts, 1 answers
  1. kellyroberts
    kellyroberts avatar
    45 posts
    Member since:
    Jul 2007

    Posted 03 Apr 2013 Link to this post

    Sorry for the cryptic title, not sure how  best to describe it.

    I have a page used to search records in a table with about 4000 records.  The query for the search uses 10 optional parameters provided via textboxes, dropdowns and datepickers.  When the page loads, the grid should start empty.  The user selects as many paramas suit their search needs and clck a button. i.e. dept='finance' and role='csr' and startdate > 'somedate'.  all parameters are optional and ANDed together using something like

    Example SQL

    ALTER PROC test (
        @Dept varchar(50)=null,
        @Role varchar(50)=null,
        @Startdate datetime=null ) AS

    SELECT some, bunch, of, fields
    FROM sometable
    WHERE
        (Dept = @Dept or isNull(@Dept,'')='')
        AND (Role = @Role or isNull(@Role,'')='')
        AND (startdate > @somedate or isNull(@somedate,0)=0)

    * Grid must start with zero records on page load
    * If the user select no parameters then ALL records will be returned.

    As it stands now when the page loads ALL 4000 records are returned because I have CancelSelectonNullParameter=false in the SQL DataSource. This can usually causes a timeout.

    I know I can do some of this via custom paging but thats not really what I want. I want the page to load with zero records in the grid but if the user clicks search with no parameters set then yes all recods can be returned.  at which point normal paging will occur.

    Thanks
    Kelly

  2. Answer
    Angel Petrov
    Admin
    Angel Petrov avatar
    1006 posts

    Posted 08 Apr 2013 Link to this post

    Hi Kelly,

    In order to first display the grid with no records I suggest that you bind it initially to an empty collection. Later when you submit a query you will have to rebind the grid and bind it to the result returned. In order to achieve this I suggest that you use advance data-binding as demonstrated in this demo.

    All the best,
    Angel Petrov
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. kellyroberts
    kellyroberts avatar
    45 posts
    Member since:
    Jul 2007

    Posted 08 Apr 2013 Link to this post

    Thanks Angel.  Heres what I did.

    1) Configure all layout / functionality of the grid in design mode.
    2) remove the datasource properties of grid and mastertable view.  grid loads in this state.
    3) add to NeedDataSource the following pseudo:  if page.ispostback then grid.datasource = mysqldatasource.

    This seems to work well.
Back to Top