|
code
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Datagrid paging I lose my sortI have a ds from sql, datagrid has sorting true, 3 databound and 1 template
column sort expression are the data values Does a sort and then I page to second pageand I lose the sort. How can I sort the data and then page the results without losing the sort. Also is there a way that when I do the sort I do not have to go back to the database for the select statement? -- cindy Hi Cindy,
Welcome to ASPNET newsgroup. From your description, you're using the ASP.NET datagrid control to displaying some data from SQLserver, you've also provide paging and sorting function for the datagrid. However, currently you found that after sorting a certain bouldcolumn, if we change the page index , the new paged data is not sorted , yes? As for this problem, it is likely caused by the rebinding of the datagrid after we change the page index. As for ASP.NET 1.X datagrid, we need to perform databinding each time we change the page index or change sort column(expression). So when we first make a sort operation, the datagrid is binded with sorted datasource (generally it would be a sorted DataView...). However, if we continue to make a changing page index operation, again we have put the code the rebind the datagrid with the new page's data, yes? And thus, the problem is that whether the new page's data is also sorted? If it it not sorted , then we'll encounter the behavior you met. So is this the cause of your problem? If so, we need to make sure the new datasource of new page we bind to the datagrid is also sorted as the last sort command's sort expression. To do this, we can store a variable in Page's ViewState to identify the last sort expression and whenever we need to rebind the datagrid, we can sort the datasource through the sort expression stored previously... Hope helps. Thanks, Steven Cheng Microsoft Online Support Get Secure! www.microsoft.com/security (This posting is provided "AS IS", with no warranties, and confers no rights.) -------------------- Show quoteHide quote | Thread-Topic: Datagrid paging I lose my sort microsoft.public.dotnet.framework.aspnet.webcontrols:11750| thread-index: AcXj7D2KqTsezqbkT324nyzRX02Whw== | X-WBNR-Posting-Host: 71.136.160.3 | From: "=?Utf-8?B?Y2luZHk=?=" <cmello@nospam.nospam> | Subject: Datagrid paging I lose my sort | Date: Mon, 7 Nov 2005 14:40:23 -0800 | Lines: 7 | Message-ID: <E59EBCBE-1C80-4C1F-9837-8C7CF0A75***@microsoft.com> | MIME-Version: 1.0 | Content-Type: text/plain; | charset="Utf-8" | Content-Transfer-Encoding: 7bit | X-Newsreader: Microsoft CDO for Windows 2000 | Content-Class: urn:content-classes:message | Importance: normal | Priority: normal | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.0 | Newsgroups: microsoft.public.dotnet.framework.aspnet.webcontrols | NNTP-Posting-Host: TK2MSFTNGXA03.phx.gbl 10.40.2.250 | Path: TK2MSFTNGXA01.phx.gbl!TK2MSFTNGXA03.phx.gbl | Xref: TK2MSFTNGXA01.phx.gbl Show quoteHide quote | X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.webcontrols | | I have a ds from sql, datagrid has sorting true, 3 databound and 1 template | column sort expression are the data values Does a sort and then I page to | second pageand I lose the sort. How can I sort the data and then page the | results without losing the sort. Also is there a way that when I do the sort | I do not have to go back to the database for the select statement? | -- | cindy | do i call save page view state before I rebind? this is problem, is the
variable the data field of the column name? is there a web link somewhere for this? others must have it. -- Show quoteHide quotecindy "Steven Cheng[MSFT]" wrote: > Hi Cindy, > > Welcome to ASPNET newsgroup. > From your description, you're using the ASP.NET datagrid control to > displaying some data from SQLserver, you've also provide paging and sorting > function for the datagrid. However, currently you found that after sorting > a certain bouldcolumn, if we change the page index , the new paged data is > not sorted , yes? > > As for this problem, it is likely caused by the rebinding of the datagrid > after we change the page index. As for ASP.NET 1.X datagrid, we need to > perform databinding each time we change the page index or change sort > column(expression). So when we first make a sort operation, the datagrid is > binded with sorted datasource (generally it would be a sorted DataView...). > However, if we continue to make a changing page index operation, again we > have put the code the rebind the datagrid with the new page's data, yes? > And thus, the problem is that whether the new page's data is also sorted? > If it it not sorted , then we'll encounter the behavior you met. So is > this the cause of your problem? If so, we need to make sure the new > datasource of new page we bind to the datagrid is also sorted as the last > sort command's sort expression. To do this, we can store a variable in > Page's ViewState to identify the last sort expression and whenever we need > to rebind the datagrid, we can sort the datasource through the sort > expression stored previously... > > Hope helps. Thanks, > > Steven Cheng > Microsoft Online Support > > Get Secure! www.microsoft.com/security > (This posting is provided "AS IS", with no warranties, and confers no > rights.) > > > > > -------------------- > | Thread-Topic: Datagrid paging I lose my sort > | thread-index: AcXj7D2KqTsezqbkT324nyzRX02Whw== > | X-WBNR-Posting-Host: 71.136.160.3 > | From: "=?Utf-8?B?Y2luZHk=?=" <cmello@nospam.nospam> > | Subject: Datagrid paging I lose my sort > | Date: Mon, 7 Nov 2005 14:40:23 -0800 > | Lines: 7 > | Message-ID: <E59EBCBE-1C80-4C1F-9837-8C7CF0A75***@microsoft.com> > | MIME-Version: 1.0 > | Content-Type: text/plain; > | charset="Utf-8" > | Content-Transfer-Encoding: 7bit > | X-Newsreader: Microsoft CDO for Windows 2000 > | Content-Class: urn:content-classes:message > | Importance: normal > | Priority: normal > | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.0 > | Newsgroups: microsoft.public.dotnet.framework.aspnet.webcontrols > | NNTP-Posting-Host: TK2MSFTNGXA03.phx.gbl 10.40.2.250 > | Path: TK2MSFTNGXA01.phx.gbl!TK2MSFTNGXA03.phx.gbl > | Xref: TK2MSFTNGXA01.phx.gbl > microsoft.public.dotnet.framework.aspnet.webcontrols:11750 > | X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.webcontrols > | > | I have a ds from sql, datagrid has sorting true, 3 databound and 1 > template > | column sort expression are the data values Does a sort and then I page > to > | second pageand I lose the sort. How can I sort the data and then page > the > | results without losing the sort. Also is there a way that when I do the > sort > | I do not have to go back to the database for the select statement? > | -- > | cindy > | > > Hi Cindy,
ASP.NET page will persist ViewState between mutiple postback requests. So we can just store the latest Sorted Column's expression into ViewState like: private void DataGrid1_SortCommand(object source, System.Web.UI.WebControls.DataGridSortCommandEventArgs e) { string sortexp = e.SortExpression; this.ViewState["DataGrid1_SortExpression"] = sortexp; } Then, next time, when in the DataGrid1's PageIndexChanged event, we should do the following: private void DataGrid1_PageIndexChanged(object source, System.Web.UI.WebControls.DataGridPageChangedEventArgs e) { string sortexp = this.ViewState["DataGrid1_SortExpression"] as string; //GetPagedDataSource(index) is just a function //we used to retrieve data for a certain page DataView dv = GetPagedDataSource(e.NewPageIndex); dv.Sort = sortexp; //rebind datagrid here.... } Also, if there're any other postback events where we need to rebind the DataGrid, we also need to specify the correct Sort Expression for the DataView ( or get the correct Sorted DataCollection) If there're anything unclear, please feel free to post here. Thanks, Steven Cheng Microsoft Online Support Get Secure! www.microsoft.com/security (This posting is provided "AS IS", with no warranties, and confers no rights.) -------------------- | Thread-Topic: Datagrid paging I lose my sort <Gc0i4rC5FHA.1***@TK2MSFTNGXA01.phx.gbl>| thread-index: AcXkiy9OiSAovRdvQBqQ6Uh7zDa2Lw== | X-WBNR-Posting-Host: 71.136.160.120 | From: "=?Utf-8?B?Y2luZHk=?=" <cmello@nospam.nospam> | References: <E59EBCBE-1C80-4C1F-9837-8C7CF0A75***@microsoft.com> Show quoteHide quote | Subject: RE: Datagrid paging I lose my sort microsoft.public.dotnet.framework.aspnet.webcontrols:11768| Date: Tue, 8 Nov 2005 09:38:09 -0800 | Lines: 85 | Message-ID: <16F7EEB2-9B2B-4F73-A037-9CA411A3C***@microsoft.com> | MIME-Version: 1.0 | Content-Type: text/plain; | charset="Utf-8" | Content-Transfer-Encoding: 7bit | X-Newsreader: Microsoft CDO for Windows 2000 | Content-Class: urn:content-classes:message | Importance: normal | Priority: normal | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.0 | Newsgroups: microsoft.public.dotnet.framework.aspnet.webcontrols | NNTP-Posting-Host: TK2MSFTNGXA03.phx.gbl 10.40.2.250 | Path: TK2MSFTNGXA01.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGXA03.phx.gbl | Xref: TK2MSFTNGXA01.phx.gbl Show quoteHide quote | X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.webcontrols | | do i call save page view state before I rebind? this is problem, is the | variable the data field of the column name? is there a web link somewhere | for this? others must have it. | -- | cindy | | | "Steven Cheng[MSFT]" wrote: | | > Hi Cindy, | > | > Welcome to ASPNET newsgroup. | > From your description, you're using the ASP.NET datagrid control to | > displaying some data from SQLserver, you've also provide paging and sorting | > function for the datagrid. However, currently you found that after sorting | > a certain bouldcolumn, if we change the page index , the new paged data is | > not sorted , yes? | > | > As for this problem, it is likely caused by the rebinding of the datagrid | > after we change the page index. As for ASP.NET 1.X datagrid, we need to | > perform databinding each time we change the page index or change sort | > column(expression). So when we first make a sort operation, the datagrid is | > binded with sorted datasource (generally it would be a sorted DataView...). | > However, if we continue to make a changing page index operation, again we | > have put the code the rebind the datagrid with the new page's data, yes? | > And thus, the problem is that whether the new page's data is also sorted? | > If it it not sorted , then we'll encounter the behavior you met. So is | > this the cause of your problem? If so, we need to make sure the new | > datasource of new page we bind to the datagrid is also sorted as the last | > sort command's sort expression. To do this, we can store a variable in | > Page's ViewState to identify the last sort expression and whenever we need | > to rebind the datagrid, we can sort the datasource through the sort | > expression stored previously... | > | > Hope helps. Thanks, | > | > Steven Cheng | > Microsoft Online Support | > | > Get Secure! www.microsoft.com/security | > (This posting is provided "AS IS", with no warranties, and confers no | > rights.) | > | > | > | > | > -------------------- | > | Thread-Topic: Datagrid paging I lose my sort | > | thread-index: AcXj7D2KqTsezqbkT324nyzRX02Whw== | > | X-WBNR-Posting-Host: 71.136.160.3 | > | From: "=?Utf-8?B?Y2luZHk=?=" <cmello@nospam.nospam> | > | Subject: Datagrid paging I lose my sort | > | Date: Mon, 7 Nov 2005 14:40:23 -0800 | > | Lines: 7 | > | Message-ID: <E59EBCBE-1C80-4C1F-9837-8C7CF0A75***@microsoft.com> | > | MIME-Version: 1.0 | > | Content-Type: text/plain; | > | charset="Utf-8" | > | Content-Transfer-Encoding: 7bit | > | X-Newsreader: Microsoft CDO for Windows 2000 | > | Content-Class: urn:content-classes:message | > | Importance: normal | > | Priority: normal | > | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.0 | > | Newsgroups: microsoft.public.dotnet.framework.aspnet.webcontrols | > | NNTP-Posting-Host: TK2MSFTNGXA03.phx.gbl 10.40.2.250 | > | Path: TK2MSFTNGXA01.phx.gbl!TK2MSFTNGXA03.phx.gbl | > | Xref: TK2MSFTNGXA01.phx.gbl | > microsoft.public.dotnet.framework.aspnet.webcontrols:11750 | > | X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.webcontrols | > | | > | I have a ds from sql, datagrid has sorting true, 3 databound and 1 | > template | > | column sort expression are the data values Does a sort and then I page | > to | > | second pageand I lose the sort. How can I sort the data and then page | > the | > | results without losing the sort. Also is there a way that when I do the | > sort | > | I do not have to go back to the database for the select statement? | > | -- | > | cindy | > | | > | > | Hi Cindy,
How are you doing on this issue or does my further response help a little? If there're anything else we can help, please feel free to post here. Thanks, Steven Cheng Microsoft Online Support Get Secure! www.microsoft.com/security (This posting is provided "AS IS", with no warranties, and confers no rights.) -------------------- | X-Tomcat-ID: 159045279 <Gc0i4rC5FHA.1***@TK2MSFTNGXA01.phx.gbl> | References: <E59EBCBE-1C80-4C1F-9837-8C7CF0A75***@microsoft.com> <16F7EEB2-9B2B-4F73-A037-9CA411A3C***@microsoft.com> | MIME-Version: 1.0 microsoft.public.dotnet.framework.aspnet.webcontrols:31023| Content-Type: text/plain | Content-Transfer-Encoding: 7bit | From: stch***@online.microsoft.com (Steven Cheng[MSFT]) | Organization: Microsoft | Date: Wed, 09 Nov 2005 08:48:21 GMT | Subject: RE: Datagrid paging I lose my sort | X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.webcontrols | Message-ID: <51$#XpQ5FHA.***@TK2MSFTNGXA02.phx.gbl> | Newsgroups: microsoft.public.dotnet.framework.aspnet.webcontrols | Lines: 155 | Path: TK2MSFTNGXA02.phx.gbl | Xref: TK2MSFTNGXA02.phx.gbl Show quoteHide quote | NNTP-Posting-Host: tomcatimport2.phx.gbl 10.201.218.182 | | Hi Cindy, | | ASP.NET page will persist ViewState between mutiple postback requests. So | we can just store the latest Sorted Column's expression into ViewState like: | | private void DataGrid1_SortCommand(object source, | System.Web.UI.WebControls.DataGridSortCommandEventArgs e) | { | string sortexp = e.SortExpression; | | this.ViewState["DataGrid1_SortExpression"] = sortexp; | } | | | Then, next time, when in the DataGrid1's PageIndexChanged event, we should | do the following: | | private void DataGrid1_PageIndexChanged(object source, | System.Web.UI.WebControls.DataGridPageChangedEventArgs e) | { | string sortexp = this.ViewState["DataGrid1_SortExpression"] as string; | | //GetPagedDataSource(index) is just a function | //we used to retrieve data for a certain page | DataView dv = GetPagedDataSource(e.NewPageIndex); | | dv.Sort = sortexp; | | //rebind datagrid here.... | | } | | Also, if there're any other postback events where we need to rebind the | DataGrid, we also need to specify the correct Sort Expression for the | DataView ( or get the correct Sorted DataCollection) | | If there're anything unclear, please feel free to post here. Thanks, | | | Steven Cheng | Microsoft Online Support | | Get Secure! www.microsoft.com/security | (This posting is provided "AS IS", with no warranties, and confers no | rights.) | | | | -------------------- | | Thread-Topic: Datagrid paging I lose my sort | | thread-index: AcXkiy9OiSAovRdvQBqQ6Uh7zDa2Lw== | | X-WBNR-Posting-Host: 71.136.160.120 | | From: "=?Utf-8?B?Y2luZHk=?=" <cmello@nospam.nospam> | | References: <E59EBCBE-1C80-4C1F-9837-8C7CF0A75***@microsoft.com> | <Gc0i4rC5FHA.1***@TK2MSFTNGXA01.phx.gbl> | | Subject: RE: Datagrid paging I lose my sort | | Date: Tue, 8 Nov 2005 09:38:09 -0800 | | Lines: 85 | | Message-ID: <16F7EEB2-9B2B-4F73-A037-9CA411A3C***@microsoft.com> | | MIME-Version: 1.0 | | Content-Type: text/plain; | | charset="Utf-8" | | Content-Transfer-Encoding: 7bit | | X-Newsreader: Microsoft CDO for Windows 2000 | | Content-Class: urn:content-classes:message | | Importance: normal | | Priority: normal | | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.0 | | Newsgroups: microsoft.public.dotnet.framework.aspnet.webcontrols | | NNTP-Posting-Host: TK2MSFTNGXA03.phx.gbl 10.40.2.250 | | Path: TK2MSFTNGXA01.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGXA03.phx.gbl | | Xref: TK2MSFTNGXA01.phx.gbl | microsoft.public.dotnet.framework.aspnet.webcontrols:11768 | | X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.webcontrols | | | | do i call save page view state before I rebind? this is problem, is the | | variable the data field of the column name? is there a web link | somewhere | | for this? others must have it. | | -- | | cindy | | | | | | "Steven Cheng[MSFT]" wrote: | | | | > Hi Cindy, | | > | | > Welcome to ASPNET newsgroup. | | > From your description, you're using the ASP.NET datagrid control to | | > displaying some data from SQLserver, you've also provide paging and | sorting | | > function for the datagrid. However, currently you found that after | sorting | | > a certain bouldcolumn, if we change the page index , the new paged data | is | | > not sorted , yes? | | > | | > As for this problem, it is likely caused by the rebinding of the | datagrid | | > after we change the page index. As for ASP.NET 1.X datagrid, we need to | | > perform databinding each time we change the page index or change sort | | > column(expression). So when we first make a sort operation, the | datagrid is | | > binded with sorted datasource (generally it would be a sorted | DataView...). | | > However, if we continue to make a changing page index operation, again | we | | > have put the code the rebind the datagrid with the new page's data, | yes? | | > And thus, the problem is that whether the new page's data is also | sorted? | | > If it it not sorted , then we'll encounter the behavior you met. So | is | | > this the cause of your problem? If so, we need to make sure the new | | > datasource of new page we bind to the datagrid is also sorted as the | last | | > sort command's sort expression. To do this, we can store a variable in | | > Page's ViewState to identify the last sort expression and whenever we | need | | > to rebind the datagrid, we can sort the datasource through the sort | | > expression stored previously... | | > | | > Hope helps. Thanks, | | > | | > Steven Cheng | | > Microsoft Online Support | | > | | > Get Secure! www.microsoft.com/security | | > (This posting is provided "AS IS", with no warranties, and confers no | | > rights.) | | > | | > | | > | | > | | > -------------------- | | > | Thread-Topic: Datagrid paging I lose my sort | | > | thread-index: AcXj7D2KqTsezqbkT324nyzRX02Whw== | | > | X-WBNR-Posting-Host: 71.136.160.3 | | > | From: "=?Utf-8?B?Y2luZHk=?=" <cmello@nospam.nospam> | | > | Subject: Datagrid paging I lose my sort | | > | Date: Mon, 7 Nov 2005 14:40:23 -0800 | | > | Lines: 7 | | > | Message-ID: <E59EBCBE-1C80-4C1F-9837-8C7CF0A75***@microsoft.com> | | > | MIME-Version: 1.0 | | > | Content-Type: text/plain; | | > | charset="Utf-8" | | > | Content-Transfer-Encoding: 7bit | | > | X-Newsreader: Microsoft CDO for Windows 2000 | | > | Content-Class: urn:content-classes:message | | > | Importance: normal | | > | Priority: normal | | > | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.0 | | > | Newsgroups: microsoft.public.dotnet.framework.aspnet.webcontrols | | > | NNTP-Posting-Host: TK2MSFTNGXA03.phx.gbl 10.40.2.250 | | > | Path: TK2MSFTNGXA01.phx.gbl!TK2MSFTNGXA03.phx.gbl | | > | Xref: TK2MSFTNGXA01.phx.gbl | | > microsoft.public.dotnet.framework.aspnet.webcontrols:11750 | | > | X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.webcontrols | | > | | | > | I have a ds from sql, datagrid has sorting true, 3 databound and 1 | | > template | | > | column sort expression are the data values Does a sort and then I | page | | > to | | > | second pageand I lose the sort. How can I sort the data and then | page | | > the | | > | results without losing the sort. Also is there a way that when I do | the | | > sort | | > | I do not have to go back to the database for the select statement? | | > | -- | | > | cindy | | > | | | > | | > | | | |
Error in DataList test query - aspnet 2.0
getting Membership userid to use and store in a custom database Gridview Updates not writing to database after clicking update Dynamically Adding DataLists FormView DataBinding in Insert mode Custom DropDownList Control and ListItem Hyperlink Control Sorting only certain columns in datagrid Enter Key posts the Page VB and get text behing java |
|||||||||||||||||||||||