Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I refresh correct data in Gridview upon pagination and sort?

Status
Not open for further replies.

jbailey268

Programmer
May 25, 2005
51
US
I have a gridview that is linked to SqlDataSource1 whose query is (by default) select * from clients. The form allows searching by 1st & last name.
Now when values are entered in text boxes for first and last name, and I enter "JOHN" and "WIL" and press go - what I do is make sqldatasource1.selectCommand= "Select * from clients where fname = <the value in fname > and lname = <value in lname>. (pseudo code.)

ANyway the grid populates correctly I get all the John Wilsons and the John Williams etc.
But there are 3 pages in the grid. When I click to page 2 the grid repopulates as if the SQLDataSOurce defaults back to all Clients. This also occurs when I click the column header(s) since I allowed sorting.
I tried storing Session("name") variable to the user defined query. Someone suggests looking at the Post Back features or the ONPageChange event. But I am not really changing the page per se, just moving to a differne gridview page not a different aspx.
I am using 2005 Visual Studio. Perplexing. Why would the SQLDatasource revert if I set it at runtime?

Thanks in advance for your consideration. I hope the solution is simple, relatively new to .NET.
 
(before someone yells at you to get over to the ASP.Net section)

Heres the kicker, you ARE doing a postback. you are running a function (SERVER SIDE), which means the page is being re-server to the user, and you don't keep track of both the page you are on and the select statement.

Your next/prev/column sorts know what the sql statement is for anything. The search button knows to add the first and last name query parameters. both neither the grid control or the search button know to process the other.

You're going to want something like a function that runs whether the user changes pages, or searches. (or find a way to tuck your search params into the dridview all the time)

-The answer to your problem may not be the answer to your question.
 
Thanks for you quick response. I appreciate your help. I will move my question over to ASP.NET side.

I'm not really changing pages, just moving to the 2nd or 3rd group of data in a grid I'm still on the same aspx.
You said: "Your next/prev/column sorts know what the sql statement is for anything" -

If so, why does it seem to forget and go back and employ the original query setting and show all rows?
I would think my dilemma is a common/routine thing not something way out there.

 
I am not sure how you have your datagrid setup, but if you used the query wizard then there should have been a section for specifying parameters. You may be able to rewrite you select(if inline) to deal with your two textbox values all the time. otherwise i would suggest using a stored proc and doing the "hook-up" by hand.

-The answer to your problem may not be the answer to your question.
 
Thanks again. I wrote a function binddata() that executes a session variable that held the query.
And I execute in the if not postback in the load event.

Thanks for your help. It's great when it works.
I like it especially since you don't get that page flicker effect upon sorting columns or pagination.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top