Click here to Skip to main content
15,894,337 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

How to assign dataview value to view state?

C#
datatable dt=new datatable()
DataView dvData = new DataView(dt);
dvData.RowFilter = Condition;

ViewState[ViewStatedtName] = dvData;


I am getting error. Please help me.
Posted
v2

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, put dataview.Table to viewstate. It'll resolve your problem.
C#
DataView dv = ds.Tables[0].DefaultView;
ViewState.Add("key", dv.Table);

 
Share this answer
 
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 .
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900