Click here to Skip to main content
15,884,472 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I have a parsed object of xml, that i need to bind to grid view.But my problem is this object contains collection and subcollections inside that. all these things i need to bind to a single grid view. can any one help me with good and simple approach?
Posted
Comments
Aniket Yadav 9-Mar-12 1:54am    
Provide us the sample code of what you have tried.
Oshtri Deka 9-Mar-12 3:50am    
So what data you wish to show in gridview? All or subset?

1 solution

Bind xml file and display data of xml file in grid view . here is the code

JavaScript
<script  runat="server">
    void Page_Load(Object sender, EventArgs e)
    {
        DataSet authorsDataSet;
        string filePath = Server.MapPath("Authors.xml");
        authorsDataSet = new DataSet();
        //Read the contents of the XML file into the DataSet
        authorsDataSet.ReadXml(filePath);                    
        authorsGird.DataSource = authorsDataSet.Tables[0].DefaultView;
        authorsGird.DataBind();
    }
</script>


below is the html markup of grid view
XML
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Reading XML Data into a DataSet object </title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:GridView id="authorsGird" runat="server"
            AutoGenerateColumns="False" CellPadding="4" HeaderStyle-BackColor="blue" HeaderStyle-ForeColor="White"
            HeaderStyle-HorizontalAlign="Center" HeaderStyle-Font-Bold="True">
            <Columns>
                <asp:BoundField HeaderText="Last Name" DataField="lastName" />
                <asp:BoundField HeaderText="First Name"
                    DataField="firstName" ItemStyle-HorizontalAlign="Right" />
            </Columns>
        </asp:GridView>
    </div>
    </form>
</body>
</html>
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900