Click here to Skip to main content
11,490,801 members (76,678 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# ASP.NET
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.
Posted 28-Jan-13 22:53pm
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

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.
DataView dv = ds.Tables[0].DefaultView;
ViewState.Add("key", dv.Table);
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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 .
  Permalink  

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

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 476
1 Andy Lanng 288
2 Sascha Lefèvre 240
3 OriginalGriff 178
4 Maciej Los 160
0 Sergey Alexandrovich Kryukov 9,713
1 OriginalGriff 8,475
2 Sascha Lefèvre 3,544
3 Maciej Los 3,106
4 Richard Deeming 2,370


Advertise | Privacy | Mobile
Web04 | 2.8.150520.1 | Last Updated 29 Jan 2013
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100