Brian,

I've been saving the sort command to view state and then retrieving it on
postback.

--
S. Justin Gengo, MCP
Web Developer / Programmer

Free Code Library At:
[url]www.aboutfortunate.com[/url]

"Out of chaos comes order."
Nietzche


"brian richards" <brian_1001@hotmail.com> wrote in message
news:u1i4Za9SDHA.632@TK2MSFTNGP12.phx.gbl...
> I how do I ensure that Items stay sorted during paging? Right now I have a
> datagrid that binds to a datasource. If I click on a a newpage it goes to
> the page but loses all sorting information. But if I click on a page then
> sort a column it stays on that page and sorts and the columns are sorted
> appropriately.
>
> Basically once I sort the datagrid I want it to stay sorted no matter what
> page it's on. Like wise if a user is on any page index other than 0 (Page
> 1), I think acceptable behavior is to stay on that page rather than
forcing
> them back to page 1. For now though that's not the behavior I'm most
> concerned with. I've included my code at the bottom.
>
>
> Thanks
>
> Brian
>
> p.s. I also thought that maybe doing the sorting in the sql rather than
tha
> datagrid might work since I rebind the grid and thus execute sql anyway.
>
> public void BindGrid()
> {
> UpdateSelectStmt();
> adptr_LocationSummary.Fill(dsLocationSummary1);
> dg_LocationSummary.DataBind();
> }
>
> private void dg_LocationSummary_SortCommand(object source,
> System.Web.UI.WebControls.DataGridSortCommandEvent Args e)
> {
> string sortorder = (ViewState["sortorder"]!=
> null?ViewState["sortorder"].ToString():"ASC");
> string sortitem = (ViewState["sortitem"]!=null ?
> ViewState["sortitem"].ToString():e.SortExpression);
> if(sortitem == e.SortExpression)
> {//reverse sort order
> if(sortorder == "ASC")
> sortorder = "DESC";
> else
> sortorder = "ASC";
> }
> else
> {
> sortorder = "ASC";
> sortitem = e.SortExpression;
> }
> ViewState["sortitem"] = sortitem;
> ViewState["sortorder"] = sortorder;
> dvLocationSummary.Sort = sortitem + " " + sortorder;
> BindGrid();
> }
>
> private void dg_LocationSummary_PageIndexChanged(object source,
> System.Web.UI.WebControls.DataGridPageChangedEvent Args e)
> {
> //I think somehow dvLocationSummary is losing it's sort here
> dg_LocationSummary.CurrentPageIndex = e.NewPageIndex;
> BindGrid();
> }
>
> private void State_SelectedIndexChanged(object sender, System.EventArgs e)
> {
> dg_LocationSummary.CurrentPageIndex = 0;
> BindGrid();
> }
> private void UpdateSelectStmt()
> {
> //change sqlSelectCommand1.Commandtext to reflect the state of
> the filter
> }
>
>