Click here to Skip to main content
15,942,757 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
How to Load XML data and SQL table Data in GridView  Dynamically in ASP.NET

Take Two Buttons then one GridView  and  one SQLDataSource

Go to Add New Item, select Dataset, Drag and Drop TableAdapter then
Establish the connection and Next, then choose Command Type Next, then Click on Query Builder
Select the Tables and link then (if more than one table you are selecting) then select the fields which all r u want to display

Now Add One XML File and write the fields which all u want to show

<!-- XML Table Data -->
<pre lang="xml"><bookstore>

  <book category="COOKING">
    <title lang="en">Everyday Italian</title>
    <author>Giada De Laurentiis</author>

  <book category="CHILDREN">
    <title lang="en">Harry Potter</title>
    <author>J K. Rowling</author>

  <book category="WEB">
    <title lang="en">XQuery Kick Start</title>
    <author>James McGovern</author>
    <author>Per Bothner</author>
    <author>Kurt Cagle</author>
    <author>James Linn</author>
    <author>Vaidyanathan Nagarajan</author>

  <book category="WEB">
    <title lang="en">Learning XML</title>
    <author>Erik T. Ray</author>


Now go for C# Coding 

//On Click Button1 Load XML Table Data in GridView1
protected void Button1_Click(object sender, EventArgs e)
        XmlDocument doc = new XmlDocument();

        DataSet ds = new DataSet();
        ds.ReadXml(new XmlNodeReader(doc));
        GridView1.DataSource = ds.Tables[0];

//On click Button2 Load SQL Table Data in Same Gridview1
protected void Button2_Click(object sender, EventArgs e)
        DataSet1 ds1 = new DataSet1();

        DataSet1TableAdapters.DataTable1TableAdapter adap = new DataSet1TableAdapters.DataTable1TableAdapter();

        DataTable dt = new DataTable();

        GridView1.DataSource = ds1.DataTable1;
<pre lang="text"><pre lang="text">
Now in same Gridview we can show data from XML or SQL table
Onclick Button, Dynamically....

I hope It will help for Beginner of XML in ASP.NET
Md. Saud
Updated 12-Jan-12 1:28am
thatraja 27-Dec-11 9:25am    
Not a question. Post it as a Tip/Trick
Mahid khan 10-Jan-15 2:20am    
i want both table load in gridview at same time
Md. Saud 28-Apr-15 2:39am    
as i have explained in Query Builder while selecting the tables you can have multiple tables.

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