How to Assign Session Value in C# for this

Posted by Jayakumars under C# on 2/18/2017 | Points: 10 | Views : 335 | Status : [Member] [MVP] | Replies : 2
Hi

How to Assign Session value from Array value in C# and compare if statement from session value all element in C# how will do this

for ex:
when i button click event i pass different different ID after submit i need
to assign session value like this

for ex:
1 post Id =4
2 post Id =8
3 post Id =11
after how to contain this ids using sesssion like this
Session["SID"]=4,8,11

after another button click for checking

if (Session["SID"].ToString().Contains(4,8,11))
{
--- then
}
Else
{
--- Else part
}


Mark as Answer if its helpful to you


Responses

Posted by: Key123 on: 2/20/2017 [Member] Starter | Points: 25

Up
0
Down
you can assign array to session variable,
eg:
int[] a = new int[]{1,2,3};

Session["values"] = a;
then you have to cast the session variable into int array and do the required operations,
int[] a = (int[])Session["values"]



Jayakumars, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Jayakumars on: 2/21/2017 [Member] [MVP] Bronze | Points: 25

Up
0
Down
hi
how to find contains this using if statemnt like this

if(Session["values"].tostring().contains(a))

{

}

int[] a


Mark as Answer if its helpful to you

Jayakumars, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response