更新时间:2023-02-09 14:49:31
关注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 .