DataTable From DataGrid

Ice725

Freshman
Joined
Apr 19, 2004
Messages
31
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#....

Code:
DataView view2 = new DataView(DataGrid1.DataTable????,"TheCity='"+city+"', PlusMinus DESC",DataViewRowState.CurrentRows);

Obviously there is no DataGrid1.DataTable Property. Is there a way to extract a DataTable?
 
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.
 
Back
Top