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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Why doesn't gridview show correct data when pagination or column 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 different 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.
 
I don't know much about the sql datasource, but when I implement paging the simple way is to go back to the database, get all your results, then take the current page index and add 1 to it, then rebind the grid (usually I implement caching to avoid another trip to the database).

I would step through the code and take a look at the PageIndexChanged event. Perhaps the sqldatasource has something already built into it, but it sounds like it is just requerying the database with no values (which you already know).

Regards,

J
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top