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

Grid load state using optional parameters

2 Answers 60 Views
Grid
This is a migrated thread and some comments may be shown as answers.
kellyroberts
Top achievements
Rank 1
kellyroberts asked on 03 Apr 2013, 02:13 PM
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 Answers, 1 is accepted

Sort by
0
Accepted
Angel Petrov
Telerik team
answered on 08 Apr 2013, 11:37 AM
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.
0
kellyroberts
Top achievements
Rank 1
answered on 08 Apr 2013, 12:30 PM
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.
Tags
Grid
Asked by
kellyroberts
Top achievements
Rank 1
Answers by
Angel Petrov
Telerik team
kellyroberts
Top achievements
Rank 1
Share this question
or