【问题标题】:Bind asp repeater with static method用静态方法绑定asp中继器
【发布时间】:2012-07-09 08:52:20
【问题描述】:

我的 asp 页面上有一个转发器,我想将该转发器与后面的代码绑定(C#)。在 c# 页面上,我有一个静态方法来绑定转发器。但是我收到错误

“对象未设置为对象的实例”

我拥有的静态方法是..

 [WebMethod(EnableSession = true)]
    public static void LoadData()
    {
        Default oDefault = new Default();
        Page p = new Page();
        if ((List<AllPostInformation>)p.Session["AllNewsPostCollection"] != (List<AllPostInformation>)p.Session["CheckExistData"])
        {
            if ((List<AllPostInformation>)p.Session["AllNewsPostCollection"] != null)
            {
                List<AllPostInformation> o = new List<AllPostInformation>();
                o = (List<AllPostInformation>)p.Session["AllNewsPostCollection"];
                oDefault.rptNews.DataSource = o;
                oDefault.rptNews.DataBind();
            }
            p.Session["CheckExistData"] = p.Session["AllNewsPostCollection"];
        }
    }
  Please Help???

【问题讨论】:

  • p.Session["AllNewsPostCollection"];没有返回任何东西...
  • 我已经在我们的代码中早些时候启动了这个会话,当我调试时我发现 Session["AllNewsPostCollection"] 有所需的数据。

标签: asp.net c#-4.0


【解决方案1】:

您不能实例化 PageHttpSession 对象。您应该必须使用HttpContext.Current.Session 属性来获取 Session 对象的引用。

【讨论】:

  • 我试过了,但这不起作用。在 oDefault.rptNews.DataBind() 上仍然出现同样的错误;
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2019-01-31
  • 2020-02-27
  • 1970-01-01
  • 1970-01-01
  • 2021-11-29
  • 1970-01-01
  • 2012-12-16
相关资源
最近更新 更多