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!

Storing a Sort Expression to a variable

Status
Not open for further replies.

DotNetDunce

Programmer
Aug 23, 2001
47
0
0
US
Does anyone know how to save a sort order or sort expression to a variable after a user has sorted a gridview? When a user clicks a column and the gridview sorts I would like to capture that into a variable to pass to another page. Any help is appreciated!
 
there are a number of ways to handle this. the "best" solution will be determined by your architecture.

1. Do you use DataTables or POCOs to represent your data?
2. Are you passing the sort to a new page, or are you posting back to the same page (assuming webforms).
3. How long do you need to keep the sort is scope? between:
Postbacks
Form page 1 to page 2
For the life of current session
Persisted between sessions (login>logout, login again)

I would guess the simplest solution will be to keep the name of the column(string) and the direction(bool) of the sort. from there you can piece together a sort expression.

Jason Meckley
Programmer
Specialty Bakers, Inc.

faq855-7190
 
Where we use it most, we are posting back to the same page so we use viewstate to hold the sort expression and direction. If you are posting or redirecting to another page then you can use session, but a query string would work as well
 
Thanks for the help!

I need to hold the sort order so that a table inside a report displayed in a reportviewer control on the next page can mimic what is in the gridview of the previous page. How do I capture what is set in the gridview? I need to know how to grab it so I can pass it on. I apologize for needing specifics or examples. So, Jason, how do I grab the column and sort direction from the gridview? Thanks again for your help!
 
There is a Sorting and Sorted event of the gridbview. Look there for the code you need.
 
You will need to capture the sort direction in the GridViewSorting/Sorted event. put this information somewhere (viewstate?) then when you click export to report get the sort values from viewstate and pass them in the url to the report. how the report uses this and gets the data is up to you.

Jason Meckley
Programmer
Specialty Bakers, Inc.

faq855-7190
 
That's just what I was looking for! Thanks for the information, Jason! Learn something new everyday!

Melinda
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top