Click here to Skip to main content
15,881,882 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
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);
            }
        }

I am getting some values in above code how to add that to session
Posted
Updated 26-Aug-12 22:00pm
v2
Comments
AmitGajjar 27-Aug-12 4:33am    
you would like to store your Table in Session!!! it's not good practice. why you need to store in Session ?

Why would you ever want to do this? I could see storing the data used to populate the control by why the entire control itself? Tons more overhead with no additional benefit.

Yes you can store any object you want in sessions, including control instances. But, upon return trips, the instance you have in session will no longer map to the instance built when ASP.NET constructs the object model, therefore, any changes made to the object in session will not be reflected in the page output. The object model is
rebulit on each request.


--Amit
 
Share this answer
 
XML
protected void Btn_Calculate_Click(object sender, EventArgs e)
        {

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

            objResourceList = (List<ResourceDTO>)Session["ResourceDTOList"];
             ResourceDTO objResourceDTO = new ResourceDTO();
             foreach (ResourceDTO resrc in objResourceList)
             {

                 objResourceDTO.ProblemId = resrc.ProblemId;
                 objResourceDTO.ItemId= resrc.ItemId;
                 objResourceDTO.Profit = resrc.Profit;


                 string sql_prblm = string.Format("insert into ProblemProduct(ProblemId,ItemId,Profit)values('{0}','{1}','{2}')", objResourceDTO.ProblemId, objResourceDTO.ItemId, objResourceDTO.Profit);
                 prblmob.InsertProblemproduct(sql_prblm);

             }
            List<ProblemDto> objproblemlist = new List<ProblemDto>();
            ProblemDto objproblemdto = new ProblemDto();
            objproblemlist = (List<ProblemDto>)Session["ProblemDtoList"];
            foreach (ProblemDto prb in objproblemlist)
            {
                objproblemdto.ProblemId = prb.ProblemId;
                objproblemdto.ResourceId = prb.ResourceId;
                objproblemdto.Availability= prb.Availability;
                string sql_prblm1 = string.Format("insert into ProblemResources(ProblemId,ResourceId,Availability)values('{0}','{1}','{2}')", objproblemdto.ProblemId, objproblemdto.ResourceId, objproblemdto.Availability);
                prblmob.InsertProblemproduct(sql_prblm1);
            }
            foreach (ProblemDto problem in objproblemlist)
            {
                foreach (ResourceDTO resource in objResourceList)
                {

                     TextBox txtProfit = (TextBox)Table1.FindControl(problem.ResourceId + "_" + resource.ItemId);
                     problem.ProblemId = prblmob.Maxid();
                      problemid = problem.ProblemId;
                     int itemid = resource.ItemId;
                     int resourceid = problem.ResourceId;
                     txtProfit.ID = txtProfit.Text;
                     string sql_qry = string.Format("insert into Allocation(ProblemId,ItemId,ResourceId,Allocation) values('{0}','{1}','{2}','{3}')", problemid, resource.ItemId, problem.ResourceId, txtProfit.Text);
                     prblmob.InsertProblemproduct(sql_qry);
                }
            }
 
Share this answer
 
Hello,

You can store objects to Session.

System.web.UI.WenControls.Table myTable= new System.web.UI.WenControls.Table();
//Add rows to the table
Session["ObjSession"]= MyTable;

restore the session values

SessionStored= (System.web.UI.WenControls.Table) Session["ObjSession"];


Thanks!!!
 
Share this answer
 

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