如何为查看状态分配dataview值 [英] How to Assign dataview value to view state
本文介绍了如何为查看状态分配dataview值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何将数据视图值分配给查看状态?
datatable dt = new datatable()
DataView dvData = new DataView(dt );
dvData.RowFilter =条件;
ViewState [ViewStatedtName] = dvData;
我收到错误。请帮助我。
解决方案
关注DataView未被标记为可序列化的内容 System.data是什么意思? [ ^ ]。
这意味着您要存储的对象(DataView)没有标记为SerializableAttribute。
现在,您在使用ViewState而不是使用Session时出现此错误的原因是因为ViewState始终是序列化的,但对于Session来说并不一定如此。进程内会话存储在服务器的内存中,无需序列化。必须序列化SQLServer会话以存储在数据库中。
因此,无论何时想要在ViewState(或序列化会话)中存储对象,它都必须是标有SerializableAttribute。
和 viewview中的dataview [ ^ ]
而不是将dataview放到viewstate,把dataview.Table
到viewstate。它会解决你的问题。
DataView dv = ds.Tables [ 0 ]。DefaultView;
ViewState.Add( key,dv.Table);
而不是将dataview放到viewstate,把dataview.Table放到viewstate。
另外代码如果存在语法错误,请按以下方式进行操作。
ViewState [ViewStatedtName] = dvData;
如果上面的解决方案没有解决你的错误信息。
Hi,
How to assign dataview value to view state?
datatable dt=new datatable()
DataView dvData = new DataView(dt);
dvData.RowFilter = Condition;
ViewState[ViewStatedtName] = dvData;
I am getting error. Please help me.
解决方案
Follow What does "DataView is not marked as serializable in System.data" mean?[^].
It means that the object you want to store (DataView) isn''t marked with a SerializableAttribute.
Now, the reason you''re getting this error with ViewState and not with Session is because the ViewState is always serialized but that''s not necessarily true of Session. In-Process sessions are stored in the server''s memory and require no serialization. SQLServer sessions have to be serialized for storage in a database.
So, anytime you want to store an object in the ViewState (or a serialized Session), it must be marked with a SerializableAttribute.
and dataview in viewstate[^]
instead of putting dataview to viewstate, putdataview.Table
to viewstate. It''ll resolve your problem.
DataView dv = ds.Tables[0].DefaultView; ViewState.Add("key", dv.Table);
instead of putting dataview to viewstate, put dataview.Table to viewstate.
Also the code shouldfollow as below if there is a syntax error.
ViewState["ViewStatedtName"] = dvData;
If the above solution doesn''t resolve post ur error message .
这篇关于如何为查看状态分配dataview值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文