Read data from xml and bind to asp:DataGrid : DataGrid XML Bind « Data Binding « ASP.Net






Read data from xml 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("Employees.xml"))
    
    dgEmployees.DataSource = objDataSet.Tables(0).DefaultView
    dgEmployees.DataBind()
    
  End Sub

</script>

<html>
  <body>
  <asp:DataGrid id="dgEmployees" runat="server" />
  </body>
</html>

<%-- Employees.xml
<?xml version="1.0" standalone="yes"?>
<NewDataSet>
  <Employees>
    <FirstName>Z</FirstName>
    <LastName>X</LastName>
  </Employees>
  <Employees>
    <FirstName>W</FirstName>
    <LastName>R</LastName>
  </Employees>
</NewDataSet>
--%>

           
       








Related examples in the same category