Show Data from Xml file into two gridview based on a condition

XML FILE----

<Employees>
  <
NO1>
    <
Name>aaa</Name>
    <
ZIP>333</ZIP>
    <
Address>aaa</Address>
    <
City>aa City</City>
    <
State>aa</State>
  </
NO1>
  <
NO2>
    <
Name>bbb</Name>
    <
ZIP>239</ZIP>
    <
Address>bbb</Address>
    <
City>bb City</City>
    <
State>bbb</State>
  </
NO2>
  <
NO3>
    <
Name>ccc</Name>
    <
ZIP>100</ZIP>
    <
Address>ccc</Address>
    <
City>Bcc City</City>
    <
State>ccc</State>
  </
NO3>
</
Employees>

Code to show these data into two Gridview/Datatables filtered by ZIP code

using System;
using
System.Collections.Generic;
using
System.Linq;
using
System.Web;
using
System.Web.UI;
using
System.Web.UI.WebControls;
using
System.Data;
public
partial class _Default : System.Web.UI.Page
{
    DataRow row2;
    protected void Page_Load(object sender, EventArgs e)
    {    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        DataSet ds = new DataSet();
        ds.ReadXml(Server.MapPath("~/test.xml"));
        DataTable dt = new DataTable();
        DataTable dt1 = new DataTable();
        for (int i = 0; i < ds.Tables.Count; i++)
        {
            if (Convert.ToInt32(ds.Tables[i].Rows[0]["ZIP"].ToString()) > 200)
            {
                dt.Merge(ds.Tables[i]);
            }
            else
            {
                dt1.Merge(ds.Tables[i]);
            }
        }
        GridView1.DataSource = dt;
        GridView1.DataBind();
        GridView2.DataSource = dt1;
        GridView2.DataBind();
    }
}


You need to add two gridview and one button on your aspx page.

Ebook Download
View all
Learn
View all