Forums
New posts
Search forums
Members
Current visitors
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Search forums
Menu
Log in
Register
Install the app
Install
Forums
Archive
Archive
ASP .Net
ASP .Net Datagrid Control
How to keep a DataGrid in sync with a DataSet when sorting
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
[QUOTE="Travis Murray, post: 4263213"] Hi Pat, Welcome to the world of .Net. There are several reasons this could be happening, and several ways that you can fix it. The most likely reason for this behavior centers around how you bind the data to your DataGrid. For simplicity, let's say you have this SQL statement as the SelectCommand.CommandText property of your DataAdapter. Select * from Customers In your Page_Load event handler, you use the Fill method of your DataAdapter to populate your DataSet, and it puts all of your customers in, unsorted. Then, in your DataGrid_SortCommand event handler, you append an Order By statement to this SQL Statement before you call the Fill method. Your data is now sorted, and displays correctly in your DataGrid. Then, in your DataGrid_EditCommand event handler, you use the Fill method to populate the DataSet before binding it to the grid. However, it reverts back to the original SQL statement - without the Order By clause. This happens because by default, web applications are stateless. Every time your page does a round trip to the server, new DataSets and DataAdapters are being created. Unless you use some form of state management, everything reverts back to the default values. One way to fix this is to store you SortExpression in a Session variable. Then, you can append it to the CommandText before every fill of the DataSet. Another way would be to store the DataSet itself in a Session variable. Using a DataView can make sorting a bit easier, but it would not alleviate the problem that you are having. If you post the code in your Page_Load, DataGrid_SortCommand, and DataGrid_EditCommand event handlers, we can probably pinpoint the problem pretty quickly. -- Travis Murray MCSD, MCT Artiem Consulting, Inc. [URL]http://www.artiem.com[/URL] Learn ASP.Net In Jamaica in 2005! Visit [URL]http://www.artiem.com/jamaica.aspx[/URL] for more details. [/QUOTE]
Verification
Post reply
Forums
Archive
Archive
ASP .Net
ASP .Net Datagrid Control
How to keep a DataGrid in sync with a DataSet when sorting
Top