Click here to Skip to main content
15,896,727 members
Home / Discussions / ASP.NET
   

ASP.NET

 
QuestionSession array Pin
Sandraa9-Feb-09 9:59
Sandraa9-Feb-09 9:59 
AnswerRe: Session array Pin
Ranjit Viswakumar9-Feb-09 16:12
Ranjit Viswakumar9-Feb-09 16:12 
GeneralRe: Session array Pin
Sandraa11-Feb-09 8:40
Sandraa11-Feb-09 8:40 
GeneralRe: Session array Pin
Sandraa11-Feb-09 8:49
Sandraa11-Feb-09 8:49 
Questionsenerio Pin
suni_dotnet9-Feb-09 5:48
suni_dotnet9-Feb-09 5:48 
AnswerRe: senerio Pin
Ray Wampler9-Feb-09 6:34
Ray Wampler9-Feb-09 6:34 
GeneralRe: senerio Pin
suni_dotnet9-Feb-09 6:57
suni_dotnet9-Feb-09 6:57 
GeneralRe: senerio Pin
Ray Wampler9-Feb-09 7:21
Ray Wampler9-Feb-09 7:21 
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
GeneralRe: senerio Pin
Ray Wampler9-Feb-09 7:24
Ray Wampler9-Feb-09 7:24 
GeneralRe: senerio Pin
suni_dotnet9-Feb-09 7:37
suni_dotnet9-Feb-09 7:37 
Question"A validation error has occurred".... script attacks... Pin
markymark829-Feb-09 4:19
markymark829-Feb-09 4:19 
AnswerRe: "A validation error has occurred".... script attacks... Pin
led mike9-Feb-09 4:51
led mike9-Feb-09 4:51 
GeneralRe: "A validation error has occurred".... script attacks... Pin
markymark829-Feb-09 5:01
markymark829-Feb-09 5:01 
GeneralRe: "A validation error has occurred".... script attacks... Pin
Paddy Boyd9-Feb-09 5:21
Paddy Boyd9-Feb-09 5:21 
GeneralRe: "A validation error has occurred".... script attacks... Pin
markymark829-Feb-09 5:24
markymark829-Feb-09 5:24 
GeneralRe: "A validation error has occurred".... script attacks... Pin
Paddy Boyd9-Feb-09 5:27
Paddy Boyd9-Feb-09 5:27 
GeneralRe: "A validation error has occurred".... script attacks... Pin
markymark829-Feb-09 5:31
markymark829-Feb-09 5:31 
GeneralRe: "A validation error has occurred".... script attacks... Pin
markymark829-Feb-09 5:48
markymark829-Feb-09 5:48 
AnswerRe: "A validation error has occurred".... script attacks... Pin
Ranjit Viswakumar9-Feb-09 16:16
Ranjit Viswakumar9-Feb-09 16:16 
GeneralRe: "A validation error has occurred".... script attacks... Pin
markymark829-Feb-09 22:33
markymark829-Feb-09 22:33 
QuestionUser control datalist populating?? Pin
tadhg889-Feb-09 2:59
tadhg889-Feb-09 2:59 
QuestionASP.NET MVC Framework Pin
Brendan Vogt9-Feb-09 2:47
Brendan Vogt9-Feb-09 2:47 
AnswerRe: ASP.NET MVC Framework Pin
ToddHileHoffer9-Feb-09 3:32
ToddHileHoffer9-Feb-09 3:32 
AnswerRe: ASP.NET MVC Framework Pin
Ranjit Viswakumar9-Feb-09 16:25
Ranjit Viswakumar9-Feb-09 16:25 
QuestionUsing an ASP.NET User Web Control on a WSS WebPart Pin
Ken Mazaika9-Feb-09 2:16
Ken Mazaika9-Feb-09 2:16 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.