How to load using Linq.
Code Behind:
protected void Page_Load(object sender, EventArgs e)
{
string filePath = Server.MapPath("employee.xml");
DataSet AuthorsDataSet = null;
try
{
AuthorsDataSet = new DataSet();
AuthorsDataSet.ReadXml(filePath);
myGrid.DataSource = AuthorsDataSet;
myGrid.DataMember = "authors";
myGrid.DataBind();
}
catch (Exception ex)
{
throw ex;
}
finally
{
if (AuthorsDataSet != null)
AuthorsDataSet = null;
}
}
HTML :
<asp:GridView ID="myGrid" runat="server"
AutoGenerateColumns="False" CellPadding="4" HeaderStyle-BackColor="blue" HeaderStyle-ForeColor="White"
HeaderStyle-HorizontalAlign="Center" HeaderStyle-Font-Bold="True">
<Columns>
<asp:BoundField HeaderText="Employee Name" DataField="au_id" />
<asp:BoundField HeaderText="Employee ID"
DataField="au_lname" ItemStyle-HorizontalAlign="Right" />
</Columns>
</asp:GridView>
XML file:
<Authors_Table>
<authors>
<au_id>172-32-1176</au_id>
<au_lname>White</au_lname>
<au_fname>Johnson</au_fname>
<phone>408 496-7223</phone>
<address>10932 Bigge Rd.</address>
<city>Menlo Park</city>
<state>CA</state>
<zip>94025</zip>
<contract>true</contract>
</authors>
<authors>
<au_id>213-46-8915</au_id>
<au_lname>Green</au_lname>
<au_fname>Margie</au_fname>
<phone>415 986-7020</phone>
<address>309 63rd St. #411</address>
<city>Oakland</city>
<state>CA</state>
<zip>94618</zip>
<contract>true</contract>
</authors>
<authors>
<au_id>238-95-7766</au_id>
<au_lname>Carson</au_lname>
<au_fname>Cheryl</au_fname>
<phone>415 548-7723</phone>
<address>589 Darwin Ln.</address>
<city>Berkeley</city>
<state>CA</state>
<zip>94705</zip>
<contract>true</contract>
</authors>
<authors>
<au_id>267-41-2394</au_id>
<au_lname>Hunter</au_lname>
<au_fname>Anne</au_fname>
<phone>408 286-2428</phone>
<address>22 Cleveland Av. #14</address>
<city>San Jose</city>
<state>CA</state>
<zip>95128</zip>
<contract>true</contract>
</authors>
<authors>
<au_id>274-80-9391</au_id>
<au_lname>Straight</au_lname>
<au_fname>Dean</au_fname>
<phone>415 834-2919</phone>
<address>5420 College Av.</address>
<city>Oakland</city>
<state>CA</state>
<zip>94609</zip>
<contract>true</contract>
</authors>
</Authors_Table>