Click here to Skip to main content
16,020,628 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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:
C#
/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:
C#
public partial class _Default : System.Web.UI.Page
    {
        DataTable dtTableA = new DataTable();
        DataTable dtTableB = new DataTable();


C#
//then I'm calling the original data from my database and passing that DataTable into my function.

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);//here I'm calling my method and passing in the 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.
C#
/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.
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900