Hi,
I use Session for passing a string from one web form to another. But I want the Session name to change dynamically and I don't know how to do it.
For example, I want to have a loop where I tried like this
Code
for (var u=7;u20;u++)
{
var lineString = 'u'"] as List).ToArray()) %>';
....
}So Session should change to Session["7"], Session["8"],....Session["20"]
Can anybody help me please how to achieve this?
Thanks

Jignesh TrivediRank #16 · 50.3K reputationPosted Jun 2, 2014, 8:32 PM EDT
hi,
you mean to say you have collection of session object and you want to create comma separated string?
string lineString="";
for (var u=7;u<=20;u++)
{
lineString = '<%= lineString + Session[u.ToString()].Tostring() + "," %>';
....
}
please provide more information.
NelRank #2,060 · 702 reputationPosted Jun 3, 2014, 4:23 AM EDT
Thanks, but now even though I declared lineString and u I get a message that they don't exist in the current context
Jignesh TrivediRank #16 · 50.3K reputationPosted Jun 3, 2014, 7:43 PM EDT
I think this is because of '<%=....
Are you perform this operation in view?
Try after removing this tag...
string lineString="";
for (var u=7;u<=20;u++)
{
lineString = lineString + Session[u.ToString()].Tostring() + ","
....
}
hope this will help you.