在项目我想将Gridview.Columns暂存在ViewState中,然后再将ViewState的值转换回DataControlFieldCollection,可出现“ Type 'System.Web.UI.WebControls.DataControlFieldCollection' in Assembly 'System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' is not marked as serializable.“的错误,我想应该是DataControlFieldCollection没序列化不能转换吧。请问怎样才能解决这个问题。代码如下:
protected void Button1_Click(object sender, EventArgs e)
{
ViewState["GridViewColumns"] = GridView1.Columns;
DataControlFieldCollection collection =(DataControlFieldCollection) ViewState["GridViewColumns"];//出错
}
此类型不能序列化,因此不能放到ViewState里面去,你得想办法换一种思路