Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Sorting/Paging

0 views
Skip to first unread message

brian richards

unread,
Jul 16, 2003, 4:14:55 PM7/16/03
to
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.DataGridSortCommandEventArgs 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.DataGridPageChangedEventArgs 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
}


S. Justin Gengo

unread,
Jul 16, 2003, 5:13:13 PM7/16/03
to
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:
www.aboutfortunate.com

"Out of chaos comes order."
Nietzche


"brian richards" <brian...@hotmail.com> wrote in message
news:u1i4Za9...@TK2MSFTNGP12.phx.gbl...

brian richards

unread,
Jul 17, 2003, 8:48:30 AM7/17/03
to
Yes I ended up rewriting the page index change function to retrieve the
sort state.
Thanks

private void dg_LocationSummary_PageIndexChanged(object source,
System.Web.UI.WebControls.DataGridPageChangedEventArgs e)
{
//I think somehow dvLocationSummary is losing it's sort here
dg_LocationSummary.CurrentPageIndex = e.NewPageIndex;

dvLocationSummary.Sort = ViewState["sortitem"] + " " +
ViewState["sortorder"];
BindGrid();
}


"S. Justin Gengo" <gen...@krause.com> wrote in message
news:vhbfv9s...@corp.supernews.com...

0 new messages