Wednesday, 9 July 2014

How to read Xml File Using gridview in asp.net

How to read Xml File Using gridview in asp.net



source Of xml file
<?xml version="1.0" encoding="utf-8" ?>
<EmployeeInformation>

  <Employee>

    <sno>101</sno>

    <firstname>Pankaj </firstname>
      <lastname>Lohani</lastname>
      <address>hyderbad</address>

  </Employee>

  <Employee>

    <sno>102</sno>

    <firstname>sharath </firstname>
      <lastname>Lohani</lastname>
      <address>goa</address>

  </Employee>

  <Employee>

    <sno>103</sno>

    <firstname>rakesh </firstname>
      <lastname>Lohani</lastname>
      <address>delhi</address>

  </Employee>
  <Employee>
    <sno>105</sno>

    <firstname>rakkaj </firstname>
      <lastname>shiva</lastname>
      <address>hyderbad</address>

  </Employee>


</EmployeeInformation>


ASpx.page (Design view):
------------------------
    <asp:GridView ID="grddata1" runat="server">
    
    


    </asp:GridView>

Aspx.cs (code View File)


   protected voidPage_Load(object sender, EventArgs e)
    {

        var xmlfilepath = Server.MapPath("mydata.xml");
        DataSet dsemp = newDataSet();
        dsemp.ReadXml(xmlfilepath);
        grddata1.DataSource = dsemp.Tables[0].DefaultView;
        grddata1.DataBind();

    }





0 comments:

Post a Comment