我想知道是否可以根据变量动态创建具有不同名称的不同会话变量?
我试图以这种方式完成,但似乎不喜欢我的变量
protected void myGridView_RowDataBound(object sender, GridViewRowEventArgs e)
{
LinkButton lb = (LinkButton)e.Row.FindControl("MyLinkButton");
Label options = (Label)e.Row.FindControl("MyLabel");
if (e.Row.RowType == DataControlRowType.DataRoow)
{
Session[lb] = options;
//I was trying to use this to create Session Variables with Different Names Dynamically
}
}
所以我的最终结果是我将拥有以下会话,而不必手动创建所有这些会话。
Session["Value"] = "MyOption"
Session["Value1"] = "MyOption1"
Session["Value2"] = "MyOption2"
Session["Value3"] = "MyOption3"