Read xml data and bind to datagrid in C# : XML DataGrid « XML « ASP.Net






Read xml data and bind to datagrid in C#

<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.OleDb" %>
<script Language="c#" runat="server">
  void Page_Load(object sender, EventArgs e)
  {
    DataSet objDataSet = new DataSet();
    objDataSet.ReadXml(Server.MapPath("NewEmployees.xml"));
    dgEmployees.DataSource = objDataSet.Tables[0].DefaultView;
    dgEmployees.DataBind();
  }
</script>
<html>
  <body>
  <asp:DataGrid id="dgEmployees" runat="server" />
  </body>
</html>

<%--NewEmployees.xml
<?xml version='1.0'?>
<employees>
  <employee id="1">    
      <firstName>Nancy</firstName>
      <lastName>Lee</lastName> 
    <city>Seattle</city>
    <state>WA</state>
    <zipCode>98122</zipCode>   
  </employee>
  <employee id="2">    
      <firstName>Jason</firstName>
      <lastName>Wang</lastName>
    <city>Vancouver</city>
    <state>WA</state>
    <zipCode>98123</zipCode>   
  </employee> 
</employees>

--%>

           
       








Related examples in the same category

1.Bind XML file to DataSet and bind to asp datagrid
2.DataSet read XML data and bind to asp datagrid
3.Bind data in XML to asp:DataGrid
4.Load XML to asp:DataGrid