如何将会话存储到泛型中 [英] How to store session into generics
本文介绍了如何将会话存储到泛型中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
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
推荐答案
不确定我是否会像这样存储它,但是,我认为您正在学习该会话的工作方式(我认为我在那个方向).您读过文章还是只是复制了我给您的一小段代码?
在另一页中,
List< resourcedto> objResourceList =(List< resourcedto>)Session ["ResourceDTOList"];
这段代码有很多错误,但是它可以正常工作,而且看来您现在正在迈出第一步,所以我不想在细节上过多介绍您.我假设没有人正在使用此代码,我无法想象有人不知道会话是什么,就会付钱编写Web代码.
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.
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 = " ";
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);
}
这篇关于如何将会话存储到泛型中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文