I am taking a XML file and binding it to a DataGrid. I have an issue. There are two child nodes in the XML file and I want the second node to be bound to the DataGrid.
Here is an example of the XML file:
<Root>
<Header>
<value1>0000000</value1>
<value2>1</value2>
<value3>100.00</value3>
</Header>
<Transactions>
<Txn>
<Login></Login>
<UserName>Bob</User>
<Customer>Bob Smith</Customer>
</Txn>
</Transactions>
</Root>
I want to bind the Transactions to the DataGrid. Currently, when I bind the above XML file to the DataGrid, all I get is the Header values being populated. I would like the code to skip the Header and just bind the Transactions.
Here is my C# code in the Default.aspx.cs file:
public void LoadXML()
{
try
{
serverPath = Server.MapPath("App_Data/" + xmlFileName);
DataSet dsDataSet = new DataSet();
dsDataSet.ReadXml(serverPath);
dgDataGrid.DataSource = dsDataSet;
dgDataGrid.DataBind();
}
catch
{
}
}
I will be grateful for any help.
Thank you in advance.
ReadXML will have loaded the xml structure into separate tables. If you bind to dsDataSet.Tables[2] it’ll show all of your transactions.