开发者

How can i use Xml Serialization with gridview?

i try to use xml serilization in gridview but it returns me: InvalidOperationException was unhandled by user code

My code:


using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Xml.Serialization;
using System.IO;


namespace WebAppl_serilization
{
    public partial class _Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            FileStream myStream = new FileStream("GridView.XML", FileMode.Create);

            XmlSerializer myXs = new XmlSerializer(typeof(GridView));

            myXs.Serialize(myStream, gv);


            myStream.Close();
            Console.WriteLine("Devam etmek için bir tuşa basın");
            Console.ReadLine();

            FileStream mySecondFS = new FileStream("GridView.XML", FileMode.Open);
            XmlSerializer mySecondXs = new XmlSerializer(typeof(GridView));
            GridView test = (GridView)mySecondXs.Deserialize(mySecondFS);
            mySecondFS.Close();
            //foreach (GridView grd in test)
            //{
            //    Console.Write(grd.);
            //}
       开发者_高级运维     Console.ReadKey();
        }
    }
}

i t throw me: XmlSerializer myXs = new XmlSerializer(typeof(GridView)); error message: InvalidOperationException was unhandled by user code Detail: 'System.Web.UI.WebControls.GridView' was an error reflecting type.

my html source:

   <div>
    <asp:GridView ID="gv" runat="server" AutoGenerateColumns="false">
    <Columns>
    <asp:BoundField DataField="Kitap" HeaderText="Kitap" />
    </Columns>
    </asp:GridView>
    </div>


I doubt the GridView is serializable. A better option would be to serialize the data, not the GridView.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜