Click here to Skip to main content
15,890,336 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
C#
protected void Btn_Next_Click(object sender, EventArgs e)
        {
            bool flag = false;
            pobj.InsertProblem();
            int problemid = pobj.Maxid();
            List<resourcedto> objResourceList = new List<resourcedto>();
            foreach (GridViewRow rw in GridView1.Rows)
            {
                CheckBox chk = (CheckBox)rw.FindControl("CheckBox1");
                TextBox txt = (TextBox)rw.FindControl("TxtProfit");
                if ((chk.Checked == true) && (txt.Text != ""))
                {
                    ResourceDTO objResourceDTO = new ResourceDTO();
                    objResourceDTO.ItemName = chk.Text;
                    objResourceDTO.Profit = Convert.ToInt32(txt.Text);
                    objResourceDTO.ItemId = Convert.ToInt32(GridView1.DataKeys[rw.RowIndex].Value);
                    objResourceDTO.ProblemId = problemid;
                    objResourceList.Add(objResourceDTO);
                    //string sql_prblm = string.Format("insert into ProblemProduct(ProblemId,ItemId,Profit)values('{0}','{1}','{2}')", problemid, itemid, profit);
                    //pobj.InsertProblemproduct(sql_prblm);    
                    flag = true;
                }
                Session["ResourceDTOList"] = objResourceList;
            }
            if (flag)
            {
                Response.Redirect("ProblemResource.aspx");
            }
            else
            {
                ClientScript.RegisterStartupScript(this.GetType(), "key", "alert('Select something first')", true);
            }
        }



I have used generics on click of next button it should move to problem resource page in that page i have to assign that session to list. please help out
Posted
Updated 24-Aug-12 22:44pm
v2

Not sure I would have stored it like this, but, I think you're learning how the session works ( I think I pointed you in that direction ). Did you read articles or just copy the one bit of code I gave you ?

In the other page,

List<resourcedto>objResourceList = (List<resourcedto>)Session["ResourceDTOList"];

There's much that's wrong with this code, but it will work, and it seems you're taking baby steps for now, so I don't want to overload you with detail. I assume no-one is using this code, I can't imagine someone who doesn't know what the session is, would be paid to write web code.
 
Share this answer
 
v2
Comments
Lakshmimsridhar 25-Aug-12 5:31am    
i knew that how to store it in session. but using genrics i dont know. what you had given above its not working. i tried it before itself then posted that. Anyways thanks for your reply.
Christian Graus 25-Aug-12 5:32am    
You need to define 'not working'. If you put a value in to the session, it will come out. My code is correct. Your code has other issues. Use the debugger to work out what is going on, put breakpoints in EVERY point that uses that session key and see what happens.
Lakshmimsridhar 25-Aug-12 5:40am    
i am getting error like resourcedto is a type but used like a variable
Christian Graus 25-Aug-12 5:43am    
IT means what it says. resourcedto is a class type, but your syntax makes it look like a variable. See, if you told us you were getting an error and what it was, we could help better. Post the code, or if it's the code above, tell us what line has the error
Lakshmimsridhar 25-Aug-12 6:11am    
Okay tell me in what way i can retrive that session values in next page
XML
private void Allocate()
      {

          List<ResourceDTO> objResourceList = new List<ResourceDTO>();

          objResourceList = (List<ResourceDTO>)Session["ResourceDTOList"];

          List<ProblemDto> objproblemlist = new List<ProblemDto>();
          objproblemlist = (List<ProblemDto>)Session["ProblemDtoList"];

          TableHeaderRow hrow = new TableHeaderRow();
          TableHeaderCell hcell1 = new TableHeaderCell();
          hcell1.Text = "&nbsp;";
          hrow.Controls.Add(hcell1);
          foreach (ResourceDTO item in objResourceList)
          {
              TableHeaderCell hcell2 = new TableHeaderCell();
              hcell2.Text = item.ItemName;
              hrow.Controls.Add(hcell2);
          }
          Table1.Controls.Add(hrow);

          foreach (ProblemDto problem in objproblemlist)
          {
              TableHeaderRow hrow1 = new TableHeaderRow();
              TableHeaderCell hcell3 = new TableHeaderCell();
              hcell3.Text = problem.Resource_Name;
              hrow1.Controls.Add(hcell3);
              foreach (ResourceDTO resource in objResourceList)
              {
                  TableHeaderCell hcell4 = new TableHeaderCell();
                  TextBox txtProfit = new TextBox();
                  txtProfit.Width = 60;
                  hcell4.Controls.Add(txtProfit);
                  hrow1.Controls.Add(hcell4);
              }
              Table1.Controls.Add(hrow1);
          }
 
Share this answer
 
Comments
Christian Graus 27-Aug-12 8:55am    
Cool - this is doing exactly what I said to do re: reading from the session. One small tip:

List<resourcedto> objResourceList = new List<resourcedto>();
objResourceList = (List<resourcedto>)Session["ResourceDTOList"];


This creates an object and discards it. Just do:

List<resourcedto> objResourceList = (List<resourcedto>)Session["ResourceDTOList"];
Lakshmimsridhar 8-Sep-12 7:16am    
you told in somewhat different which gives error. afterwards i tried i got

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