如何将列表放入viewstate [英] how to put a list into viewstate

查看:64
本文介绍了如何将列表放入viewstate的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨所有

如何将列表项列表放入视图状态

我的代码



hi to all
how can i put a list of list item into a view state
my code

List<ListItem> extraWorkOperations = new List<ListItem>();
ViewState["extraWorkOperations "]=extraWorkOperations ;



提前感谢


thanks in advance

推荐答案

参考 - 推出< t>的基因列表查看状态 [ ^ ]。

Refer - Pushing a Geneic List of <t> to View state[^].
引用:

如果你只是想把东西保存到查看状态:



Here''s another quick way if you just wanted to Save things to the view state:



  1. 标记要存储其列表的类(以及所有父类(如果有))在 ViewState 中作为[ Serializable ]。
  2. 转换列表数组
  3. 存储在 ViewState

  1. Mark the Class (and all parent classes if any) whose List you want to store in the ViewState as [Serializable].
  2. Convert the List to an Array.
  3. Store in ViewState.





但您使用的 ListItem 不是 Serializable

因此,使用公钥/值属性创建自己的类,将其标记为 Serializable 并转换为 Array 并存储在 ViewState 中(如客户类的链接中所述)。



注意

商店列表在 ViewState 中如果你的数量少于列表中的数据。



But the ListItem you have used is not Serializable.
So, create your own class with public key/value properties, mark it Serializable and convert to Array and store in ViewState (as described in that link for Customer Class).

Note
Store List in ViewState if you have less number of Data in List.


这篇关于如何将列表放入viewstate的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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