“System.Web.UI.WebControls.Lis ... [英] 'System.Web.UI.WebControls.Lis...

查看:81
本文介绍了“System.Web.UI.WebControls.Lis ...的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我制作了一个属性,如下所示。



I have made a property, which looks like below.

public ListItem[] DropDownListItems
        {
            get { return (ListItem[])ViewState["DropDownListItems"]; }
            set { ViewState["DropDownListItems"] = value; }
        }



这就是我赋予它价值的方式




And this is how i assign it values

ListItem[] litem = new ListItem[7];
litem[0] = new ListItem("View", "RowView");
litem[1] = new ListItem("ReadView", "RowReadView");
litem[2] = new ListItem("WriteView", "RowWriteView");
litem[3] = new ListItem("DeleteView", "RowDeleteView");
this.DropDownListItems=litem;





但是我得到了以下错误



'汇编中的'System.Web.UI.WebControls.ListItem''未标记为可序列化

如何解决它



But I get the following error

''System.Web.UI.WebControls.ListItem'' in Assembly is not marked as serializable
How to resolve it

推荐答案

您收到错误,因为 ListItem 不能由本机序列化像Array,ArrayList和Hashtable这样的框架。



类似的讨论:使用ViewState在回发中保持ListItemCollection值 [ ^ ]

它说:

1。 ListItemCollection类未标记为Serializable,因此它们不能直接存储在ViewState集合中(不能持久存储在任何其他持久存储中,有文件或数据库.......)。 .net 2.0 ListItemCollection类实现了StateManager接口,我们可以调用这个方法让它帮助我们生成可以持久保存的数据....



2对于ListItemCollection,我们可以覆盖我们的自定义控件的LoadViewState和SaveViewState方法,并手动将继承状态值存储到ViewState集合......(这也是asp.net的buildin ListControl在他们的实现)。另外,当我们创建ListItemCollection属性的字段

实例....时,我们必须调用TraceViewState方法(在IStateManager接口中),以确保我们对ListItemCollection实例的更改将是坚持....






以下MS支持文章也可以提供帮助:如何:使用Visual C#.NET序列化Web服务器控件 [ ^ ]
You get an error because ListItem is not natively serializable by the framework like Array, ArrayList and Hashtable.

Similar discussion at length: Persisting ListItemCollection values across postback, using ViewState[^]
It says:
1. ListItemCollection class is not marked as Serializable, so they can not be directly stored in ViewState collection(can not be persisted in any other persistent storage suc has file or database.......). The .net 2.0 ListItemCollection class implement the StateManager interface, we can call this method to let it help us do generate the data which can be persisted....

2. For the ListItemCollection, we can just override our custom control''s LoadViewState and SaveViewState methods and manually store heir state value into ViewState collection...... (this is also what asp.net''s buildin ListControl do in their implementation). In addition, we have to call the TraceViewState method(in IStateManager interface) when we created the ListItemCollection property''s field
instance.... to make sure that our change on the ListItemCollection instance will be persisted....



Following MS Support article can also help: HOW TO: Serialize Web Server Controls by Using Visual C# .NET[^]


这篇关于“System.Web.UI.WebControls.Lis ...的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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