Ask a Question related to ASP.NET General, Design and Development.
-
S. Justin Gengo #1
Re: Sorting/Paging
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...forcing> 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 thantha> 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> 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
> }
>
>
S. Justin Gengo Guest
-
Paging and sorting
I have a datagrid that implements sorting. Once a click on a new page number, my sort gets lost. How can I combine sorting and paging? -
Help with simple datagrid paging and sorting issue
Please help! I have a simple web app that displays some search fields, posts back to itself onclick of the search button, and shows the results... -
Sorting and paging
I have set up numerous datagrid controls and had a recurring problem with the sorting and paging features. They simply don't work and generate and... -
DataGrid - sorting/paging problem
Hi. I have created a datagrid (datagrid1) without any columns on a aspx page. Then aspx.vb adds columns from a database. It is somthing like... -
Sorting with Paging
Hi all When I tried to implement sorting on Datagrid that has paging is sorts only the displayed page (When I navigate to another page It looses...



Reply With Quote

