Now that I see your code I think that I can suggest something that will work. You're already storing the data table in session, so you don't need an additional session variable your code can check for the existence of the data table in session. If I understand the issue correctly then what you want is the first time through to create the table and store it in session, and each subsequent time you want to add a new row to the existing table. First you create a helper function that returns a data table. This is where you check the session:
private DataTable ItemTable()
{
if (Session["tablevalues"] == null)
{
DataTable dt = new DataTable();
dt.Columns.Add("Items");
dt.Columns.Add("Price");
Session["tablevalues"] = dt;
}
return dt;
}
The above code will create the data table in session if it does not exist and then return it. It it already exists then it returns what's there. You now change your button handler as follows:
foreach (GridViewRow row in GridView1.Rows)
{
CheckBox box1 = (CheckBox)row.FindControl("CheckBox1");
if (box1.Checked)
{
DataTable dt = ItemTable();
DataRow dr = dt.NewRow();
string name1 = row.Cells\[2\].Text;
double cost1 = Convert.ToDouble(row.Cells\[3\].Text);
dr\["Items"\] = name1;
dr\["Price"\] = cost1;
dt.Rows.Add(dr);
GridView2.DataSource = dt;
GridView2.DataBind();
cost = cost + cost1;
Label12.Visible = true;
Label12.Text = "Total Price " + cost ;
Session\["tablevalues"\] = dt;
}
The line of code, DataTable dt = ItemTable(), is going to get either a new table or table with the rows you added. You then add your new row, update the grid, and store the table in session. I hope that's what you were looking for... Ray Wampler http://wwww.RayWampler.com