List< ABC > lstABC = new List< Abc >();//MyList
ViewState["Test"] = lstAbc; //passed to viewstate
Datatable dt = (Datatable)ViewState["Test"]; // but datatable Not accepting viewstate with binded list values.
List< ABC > lstABC = new List< Abc >();//MyList
ViewState["Test"] = lstAbc; //passed to viewstate
Datatable dt = (Datatable)ViewState["Test"]; // but datatable Not accepting viewstate with binded list values.
2
Answers
DataTable DT = new DataTable();
2)add columns to that Datatable
add the rows to that Datatable
DT.Rows.Add(DateTime.Now, "someString"); //repeat for more rows
store the dataTable in the viewstate
Viewstate["VSDT"] = DT;
5)Where you want to call that DataTable
Create a new DT
I would suggest to first make sure the class of the object you are passing in the ViewState is serializable
Then, as toly P said, you want to create your datatable, instantiate the columns and add rows. For this you could either use your object type (example 1), or you could use every parameter inside of it.. let’s say an id (int) and a name (string) (example 2)
Example 1:
Example 2:
You don’t want to store the datatable in the ViewState because it isn’t serializable. Instead, you store the list and instantiate the DataTable on each load.