Hi, I have a DataList that is bound to a datasource on my default page. The list gets filled with address data (address, city, state, zip, etc...).Depending on the users selection, the list gets bound to datasource A, or else the list gets bound to Datasource B. When the user goes to another page and returns to the default page, I want the values that were in the DataList to show again. I have tried to create a function that makes a new DataTable to hold the users data like this:
/my method to create a new DataTable and store the DataList rows.
protected DataTable CreateHeathCenterAddressTable(DataTable tableSchema)
{
DataTable tableAddressData = new DataTable();
foreach (DataColumn dc in tableSchema.Columns)
{
tableAddressData.Columns.Add(dc.ColumnName,
dc.DataType);
}
return tableAddressData;
}
//I then made my dataTables for each datasource class variables in my code behind for the page:
public partial class _Default : System.Web.UI.Page
{
DataTable dtTableA = new DataTable();
DataTable dtTableB = new DataTable();
SqlDataAdapter SQLDataAdapter = new SqlDataAdapter(prcLocationListByGeography);
DataTable dtViewResult = new DataTable();
SQLDataAdapter.Fill(dtTableA);
healthCenters.DataSource = dtTableA;
healthCenters.DataBind();
SQLDataAdapter.Dispose();
con.Close();
DataTable tableAddressItems = CreateHeathCenterAddressTable(dtTableA);
Session["tableAddressItems"] = tableAddressItems;
}
//I'm doing the same for dtTableB
On my Page_Load I am not sure how to go about loading the Session object, since it could be either TableA or TableB. I tried this with no luck.
/on the page load I'm doing this
if(Session["tableAddressItems"] != null)
{
healthCenters.DataSource = Session["tableAddressItems"];
healthCenters.DataBind();
}
Can I use the same Session variable for both dataTables? I need a little insight.Thank you.