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
}
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...
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...