DataGrid paging + SqlDataSource
-
Hi, I've a DataGrid and its bound to a SqlDataSource with a SelectCommand. Now I have to populate this grid with data based on search criteria specified by user. By default it loads all records because that is what the SelectCommand in the SqlDatasource does. But when the user makes a search criteria and cicks on Search, I change the SelectCommand and call DataBind on the Grid. But once I click on Page 2, it takes the default SelectCommand of the SqlDataSource and shows all records, which is default state. Is there a work around, or am I doing something wrong with these controls? Regards, Blumen
“The thing for you is a burial permit. You have only to speak and I will see that you get it.”
-
Hi, I've a DataGrid and its bound to a SqlDataSource with a SelectCommand. Now I have to populate this grid with data based on search criteria specified by user. By default it loads all records because that is what the SelectCommand in the SqlDatasource does. But when the user makes a search criteria and cicks on Search, I change the SelectCommand and call DataBind on the Grid. But once I click on Page 2, it takes the default SelectCommand of the SqlDataSource and shows all records, which is default state. Is there a work around, or am I doing something wrong with these controls? Regards, Blumen
“The thing for you is a burial permit. You have only to speak and I will see that you get it.”
I wouldn't change select command via code. On every postback the select command is going to back to the select command that you set in the markup. How you should do this is write one stored proc for example... create proc dbo.search (@nameValue varchar(10) = null) select * from yourTable where nameField = isnull(@nameValue, nameFeild) Something like the above will return all records if the parameter is null. You should not have to change the select command. Actually, though if your original query pulls back all the records then you could save all the data in a databale and store it in session, viewstate or cache depending on the size and use a dataview to filter.
I didn't get any requirements for the signature
-
I wouldn't change select command via code. On every postback the select command is going to back to the select command that you set in the markup. How you should do this is write one stored proc for example... create proc dbo.search (@nameValue varchar(10) = null) select * from yourTable where nameField = isnull(@nameValue, nameFeild) Something like the above will return all records if the parameter is null. You should not have to change the select command. Actually, though if your original query pulls back all the records then you could save all the data in a databale and store it in session, viewstate or cache depending on the size and use a dataview to filter.
I didn't get any requirements for the signature
I was thinking about storing the search condition in ViewState, something similar to: http://www.eggheadcafe.com/tutorials/aspnet/c67c4daa-83c2-4baa-aea4-2c8855527acb/aspnet-gridview-filterin.aspx[^] I have lots of search criteria, its for a Resume management application. User can search resumes based on various criteria.
“The thing for you is a burial permit. You have only to speak and I will see that you get it.”
-
I was thinking about storing the search condition in ViewState, something similar to: http://www.eggheadcafe.com/tutorials/aspnet/c67c4daa-83c2-4baa-aea4-2c8855527acb/aspnet-gridview-filterin.aspx[^] I have lots of search criteria, its for a Resume management application. User can search resumes based on various criteria.
“The thing for you is a burial permit. You have only to speak and I will see that you get it.”
You could do it that way, but it depends how many records you are searching. Where is the data being stored between postbacks? The sqldatasource isn't going to open a connection to the database on every postback only to filter the data after it has been returned will it? The other issue with using viewstate to store your search criteria is that is if the user leaves that page, they have to start all over. I would use a stored proc with parameters and store the criteria in session state.
I didn't get any requirements for the signature