注册 登录
编程论坛 ASP.NET技术论坛

网页间传递数组。。。

guming 发布于 2007-11-07 14:33, 2269 次点击
我从页面 A.aspx 将数组用 Session 传给 B.aspx,,结果只传过去一个值????相关代码如下,请各位帮忙看一看:

A.aspx
void test_Click(Object Sender,System.EventArgs e)
{
bool ischecked=false;
foreach(DataGridItem j in sogrid.Items)
{
ischecked=((CheckBox)j.FindControl("printck")).Checked;
if(ischecked)
{
ArrayList cklist=new ArrayList();
cklist.Add(sogrid.DataKeys[(int)j.ItemIndex]); //一DataGrid,其中有CheckBox,将选中的ItemIndex放到ArrayList中
Int32[]test=(Int32[])cklist.ToArray(typeof(Int32));//转为一维数组
Session["jj"]=test; //保存在Session中
Response.Redirect("../test.aspx");
}
}
}

B.aspx
void Page_Load(Object Sender,System.EventArgs e)
{
Int32[]index=(Int32[])Session["jj"];
Response.Write(index.Length); //无论我在 A.aspx中选择了多少行,写出来的数组长度总为 1。但我在A.aspx中将ArrayList转为一维数据后,再写出它的长度和值,都是正确的,而传到了 B.aspx中,就长度就总为 1,也只有一个值。。请问这是怎么一回事啊,,谢谢了
Session.Contents.Remove("jj");
}
4 回复
#2
zhanghy10282007-11-07 14:39
ischecked=((CheckBox)j.FindControl("printck")).Checked;
printck?
#3
guming2007-11-07 17:46
printck  是DataGrid里放置的控件 CheckBox的 ID
#4
witer2007-11-07 22:27
foreach(DataGridItem j in sogrid.Items)
{
ischecked=((CheckBox)j.FindControl("printck")).Checked;
if(ischecked)
{
ArrayList cklist=new ArrayList();
cklist.Add(sogrid.DataKeys[(int)j.ItemIndex]); //一DataGrid,其中有CheckBox,将选中的ItemIndex放到ArrayList中
Int32[]test=(Int32[])cklist.ToArray(typeof(Int32));//转为一维数组
Session["jj"]=test; //保存在Session中
Response.Redirect("../test.aspx");
}

请你自己仔细的看一下你的循环代码,你的代码逻辑写错了
你的ArrayList每一次都会新建一个,不是全局的,每一次Session保存来保存去都是你刚新最后添加的一个项
你如果你改应该把你的ArrayList定义为全局变量
#5
guming2007-11-16 19:35

对的,,后来时也发现了。。谢谢大家

1