DataSet read XML data and bind to asp datagrid : XML DataGrid « XML « ASP.Net






DataSet read XML data and bind to asp datagrid

<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.OleDb" %>

<script language="VB" runat="server">

  Sub Page_Load(Sender As Object, E As EventArgs)

    Dim objDataSet    As New DataSet()

    objDataSet.ReadXml(Server.MapPath("NewEmployees.xml"))
    
    dgEmployees.DataSource = objDataSet.Tables(0).DefaultView
    dgEmployees.DataBind()
    
  End Sub

</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.Read xml data and bind to datagrid in C#
3.Bind data in XML to asp:DataGrid
4.Load XML to asp:DataGrid