aspx Tutorial

.NET Articles,jQuery demo, asp.net with jQuery, online tutorial,Jquery, SilverLight, Javascript, asp.net,JSON, MVC,.NET Articles,demo, Web Services, .NET articles, Sharepoint 2010, visual studio 2010,Aamir Hasan,IT
Advertise Here

Advertize

wwwSW
Posted by Aamir Hasan   on Monday, March 21, 2011 Total Views:  

In this article, we will discuss how to load XML data into a dataset and bind to GridView control. To do this we will use ADO.NET provider’s method.

Let’s start

We will create an PatientList.xml file.

<patients>

  <patient>

    <patientNo>M-2011-1</patientNo>

    <title>Mr.</title>

    <fullName>John</fullName>

    <gender>Male</gender>

    <Birthday>12/14/2000</Birthday>

    <SSN>******123</SSN>

    <maritalStatus>Married</maritalStatus>

    <referredBy>TV</referredBy>

  </patient>

  <patient>

    <patientNo>M-2011-2</patientNo>

    <title>Mr.</title>

    <fullName>Aamir Hasan</fullName>

    <gender>Male</gender>

    <Birthday>12/14/2001</Birthday>

    <SSN>******133</SSN>

    <maritalStatus>Single</maritalStatus>

    <referredBy>TV</referredBy>

  </patient>

  <patient>

    <patientNo>M-2011-3</patientNo>

    <title>Miss</title>

    <fullName>Saba Khan</fullName>

    <gender>Female</gender>

    <Birthday>12/14/1950</Birthday>

    <SSN>******223</SSN>

    <maritalStatus>Married</maritalStatus>

    <referredBy>TV</referredBy>

  </patient>

</patients>

 

Drag and drop GridView control on the page, i have also applied formating on it as shown.

        <asp:GridView ID="GridView1" runat="server" CellPadding="4" ForeColor="#333333"

            GridLines="None">

            <AlternatingRowStyle BackColor="White" />

            <EditRowStyle BackColor="#2461BF" />

            <FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />

            <HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />

            <PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />

            <RowStyle BackColor="#EFF3FB" />

            <SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />

            <SortedAscendingCellStyle BackColor="#F5F7FB" />

            <SortedAscendingHeaderStyle BackColor="#6D95E1" />

            <SortedDescendingCellStyle BackColor="#E9EBEF" />

            <SortedDescendingHeaderStyle BackColor="#4870BE" />

        </asp:GridView>

 

Write following code in code behind.

C#

    protected void Page_Load(object sender, EventArgs e)

    {

       

        System.Data.DataSet ds = new System.Data.DataSet();

        ds.ReadXml(Server.MapPath("PatientList.xml"));

        GridView1.DataSource = ds.Tables[0];

        GridView1.DataBind();

    }

 

VB.NET

Protected Sub Page_Load(sender As Object, e As EventArgs)

        Dim ds As New System.Data.DataSet()

        ds.ReadXml(Server.MapPath("PatientList.xml"))

        GridView1.DataSource = ds.Tables(0)

        GridView1.DataBind()

    End Sub

 

Output

Download

GridView xml file.rar (1.47 kb)

See Live demo

Protected by Copyscape Online Plagiarism Tool

Comments (9) -

sdfsdf
sdfsdf United States
3/24/2011 3:33:05 PM #

sdfsdf

Leigh Macneil
Leigh Macneil United States
3/25/2011 5:19:58 AM #

nice one

Extenze
Extenze United States
3/27/2011 6:53:44 AM #

All the steps are effective. I wish you will keep sharing more effective post like this.

Web Development Australia
Web Development Australia United States
6/16/2011 5:29:59 PM #

We can relate ADO.NET in active x data object. Before, Ado. Net is considered an evolution s ADO objects. However, it was already changed and became a new product.

JayPrakash Sharma
JayPrakash Sharma India
1/5/2012 1:17:32 AM #

Very informative post. It's really helpful for me and helped me lot to complete my task. Thanks for sharing with us. I had found another nice post over the internet which was also explained very well about Populate Grid Control From XML Document Easily, for more details of this post check out this link...

mindstick.com/.../

Thanks Everyone!!

JayPrakash Sharma
JayPrakash Sharma India
1/5/2012 1:18:10 AM #

Very informative post. It's really helpful for me and helped me lot to complete my task. Thanks for sharing with us. I had found another nice post over the internet which was also explained very well about Populate Grid Control From XML Document Easily, for more details of this post check out this link...

mindstick.com/.../

Thanks Everyone!!

josmy
josmy India
2/12/2012 8:45:09 PM #

Thank You Very Much, Very simple example

fddf
fddf People's Republic of China
3/31/2012 9:38:48 PM #

http://www.guccioutletusastore.com

fafafa
fafafa Slovenia
4/23/2012 2:45:52 AM #

http://www.christianlouboutinukk.org   christian louboutin
http://www.tiffanyuks.org   tiffany uk
http://www.gucciukbeltuk.org   gucci belt
http://www.frsaclouisvuittonsac.com   louis vuitton sac
http://www.chanelukoutletuks.org   chanel outlet
http://www.burberryukoutletuk.org   burberry
http://www.poloralphlaurenuko.org   ralph lauren uk

Pingbacks and trackbacks (1)+

Add comment

  Country flag

biuquote
  • Comment
  • Preview
Loading

Advertizement 1
Advertizement 2
Advertizement 3
Advertizement 4
Advertizement 5