Ice725 Posted March 29, 2005 Posted March 29, 2005 I am using a DataView to Sort my DataGrid. I set the Datasource for the Datagrid to my DataView, then I bind my DataGrid. Works fine. If user selects another option, I would like to RE-Sort my already sorted DataGrid. In order to do this, I will need to obtain a DataTable to pass into the NEW DataView I am using C#.... DataView view2 = new DataView(DataGrid1.DataTable????,"TheCity='"+city+"', PlusMinus DESC",DataViewRowState.CurrentRows); [/Code] Obviously there is no DataGrid1.DataTable Property. Is there a way to extract a DataTable? Quote
kahlua001 Posted March 29, 2005 Posted March 29, 2005 You can store your datatable into viewstate and extract from there, or repopulate on postback. Quote
Ice725 Posted March 29, 2005 Author Posted March 29, 2005 I'm not familiar with viewstate, can you give me some sample code? Quote
kahlua001 Posted March 29, 2005 Posted March 29, 2005 Storing your datatable in viewstate may or may not be a good idea, it depends on the size of the datatable and the tolerable size of your resulting viewstate. But after you fill your datatable, you save it to your viewstate like.. ViewState("dtProducts") = myDatatable Upon postback, you retrieve your datatable from your viewstate so you can do what you do with the dataview and rebind Private Sub btnClick( s as object...) Dim myDataTable As Datatable myDataTable = ViewState("dtProducts") End Sub Viewstate is much like a Session variable but its scope is only at page level, typically it gets saved into a Viewstate hidden field in your page's html form, this is how it gets persisted between postbacks. Quote
Ice725 Posted March 30, 2005 Author Posted March 30, 2005 Hey thanks alot Kahlua, I did not know about this... Very helpful! Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.