如何创建ViewState数组并追加 [英] How to create array of ViewState and append

查看:80
本文介绍了如何创建ViewState数组并追加的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好我有一个List <   pre     lang   =  c# >  GenericCollection <   PolicyPolicyRelation  >  obj = new GenericCollection <   PolicyPolicyRelation  > (); <   / pre  >  


在每个PostBack中,我想通过追加将数据保存在viewstate中。但是我无法追上它的替代品。

并且在追加之后我想获取视图数组以分配给gridview.Can你能告诉我该怎么做。

解决方案

在你的Page_Load事件上写下这段代码



  public 列表< datetime> DateArray { get ;  set ; } 
protected void Page_Load( object sender,EventArgs e)
{
this .DateArray = new List< ;日期时间>();
if (ViewState [ DateArray]!= null
this .DateArray =(List< datetime>) ViewState [ DateArray];
this .DateArray.Add(DateTime.Now);
ViewState [ DateArray] = this .DateArray;
if (!IsPostBack)
{

}
}
< / datetime > < / datetime > < / datetime >


Hi I have one List <pre lang="c#">GenericCollection<PolicyPolicyRelation> obj = new GenericCollection<PolicyPolicyRelation>();</pre>


In every PostBack I want to keep the datas in viewstate by appending.But I am not able to append its replacing.

and after appending I want to fetch the array of viewsate to assign to a gridview.Can u please tell how to do.

解决方案

write this code on you Page_Load event

public List<datetime> DateArray { get; set; }
 protected void Page_Load(object sender, EventArgs e)
        {
            this.DateArray = new List<datetime>();
            if (ViewState["DateArray"] != null)
                this.DateArray = (List<datetime>)ViewState["DateArray"];
            this.DateArray.Add(DateTime.Now);
            ViewState["DateArray"] = this.DateArray;
            if (!IsPostBack)
            {

            }
        }
</datetime></datetime></datetime>


这篇关于如何创建ViewState数组并追加的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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