需要学习如何将选定的值存储到会话中 [英] Need to learn how to store selected values into a session

查看:89
本文介绍了需要学习如何将选定的值存储到会话中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我正在使用表控件,并且我有这段代码
它遍历选定的记录.

示例代码:

这就是我所拥有的:

Hello world, I am using table controls and I have this code
It loops through selected records.

example code:

this is what I have:

MyTableControl tbl =
    (MyTableControl)this.Page.FindControlRecursively("MyTableControl");
if (tbl != null)
{
    MyTableControlRecordControl[] rows = tbl.GetSelectedRecordControls();
    this.Page.Session["MyTableControl"] =rows;
}


public MyTableControlRecordControl[] GetSelectedRecordControls()
{
    ArrayList selectedList = new ArrayList(25);
    foreach (MyTableControlRecordControl recControl in this.GetRecordControls())
    {
        if (recControl.MyTableRecordRowSelection.Checked) 
        {
            selectedList.Add(recControl);
        }
    }

    return (MyTableControlRecordControl[])(selectedList.ToArray(Type.GetType("test.UI.Controls.TablePage.MYTableControlRow")));
}




多亏了几个程序员的帮助.粗体和下划线的文本.
我必须将会话中的信息发送到另一个页面并填充另一个
会话中具有值的表控件.




Thanks to the help of a couple programmers. The text that is bold and underline.
I have to send the information in the session to another page and populate a different
table control with values in the session.

推荐答案

如果我正确地理解了您的话,可以采取以下措施:


Session.Add("Key", rows);
Something along the lines of this if I''ve understood you correctly:


Session.Add("Key", rows);


使用会话变量来保存行集合.

Use a session variable to hold the rows collection.

Session["SelectedRows"] = rows;



您必须将其强制转换后才能再次使用:



You''ll have to cast it to use it again:

MyTableControlRecordControl[] rows = Session["SelectedRows"] as MyTableControlRecordControl[];


确保在Page Directive或web.Config中,sessionState设置为TRUE
Make sure that in Page Directive or in web.Config the sessionState is set to TRUE
EnableSessionState="True" 



不是这样的只读



not Readonly like this

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Test.aspx.cs" Inherits="Test" EnableSessionState="ReadOnly" %>



确保GetSelectedRecordControls()返回的对象不是null.

同时确保MyTableControlRecordControl可序列化.

是的,您必须在如上所述使用会话存储的变量之前对其进行强制转换.



make sure that GetSelectedRecordControls() return a object not a null.

Also ensure that MyTableControlRecordControl is serializable.

and yes you have to cast it before using Session Stored variable as described above.


这篇关于需要学习如何将选定的值存储到会话中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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