检索数组&中的值存储在会话中并调用其他页面asp.net c# [英] retrieving values in array & store in session and calling to other page asp.net c#

查看:86
本文介绍了检索数组&中的值存储在会话中并调用其他页面asp.net c#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨我想将值存储在会话中的数组内.我想将其用于其他页面.我该怎么做?我使用会话来存储数组的值,如下所示:

Hi I want to store values inside the array in session. I want to use it to another page. How i can do that? I used session to store values of array as follow:

    int i, randno;
    int[] a = new int[5];
        for ( i = 0; i < 4; i++)
        {
            int flag = 0;
            Random rnd = new Random();
            randno = rnd.Next(1, 15);
            for (int j = 0; j < i; j++)
            {
                if (a[j] == randno)
                    flag = 1;
            }
            if (flag == 0)
            {
                a[i] = randno;

            }
            else
            {
                i--;
            }

        }
Session["values"] = a;

在其他页面中,我使用了代码:

In other page i used code:

int[] a = (int[])Session["values"];
Response.Write(a);

此代码正确吗?因为它没有赋予价值.但是检索到另一个页面后,它给出了数组的最后一个值,在同一页面上,它给出了所有值.我想要数组的所有值.ASP.NET,C#谢谢你.

This code is right? Because its not giving values. But retrieving to another page then it gives last value of the array, on the same page it gives all the values. I want all the values of the array. Asp.net, c# Thank you.

推荐答案

尝试一下

存储数组的所有项目.

string[] a = new string[]{"a","b","c"};
Session["values"] = a;

在下一页中,您可以像这样检索它.

And in the next page, you can retrieve it like this.

string[] a = (string[])Session["values"]

这篇关于检索数组&amp;中的值存储在会话中并调用其他页面asp.net c#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆