How to read XML data based on condition and display in gridview?

In this article I am going to explain about how to read xml data based on condition and display it. This can be help your project to get particular xml records for manipulation.

Description :

I have data in the xml file likebelow

<?xml version="1.0" encoding="utf-8" ?>

In the above XML file I want to get only above 110 employee no records and display it in the gridview.

Client side

I have placed file upload control to get xml file data and gridview to display it.

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
<html xmlns="">
<head runat="server">
<title>Filter Xml Data and Display it in the Grid View</title>
<form id="form1" runat="server">
<table width="600" align="center" cellspacing="0" cellpadding="0">
<td colspan="2" height="40">
<b>Upload XML data into Gridview based on condition</b>
<td height="30">
Select XML file to upload
<td height="30">
<asp:FileUpload ID="FileUpload1" runat="server" />
<td colspan="2" height="40" align="center">
<asp:Button ID="Button1" runat="server" Text="Upload and load data"
onclick="Button1_Click" />
<td colspan="2" height="2" align="center">
<asp:GridView ID="GridView1" runat="server">

Server side

In server side I load all xml data in to datatable and then filter in datatable itseld and display it in the gri dview refer below code sample

using System.Data;
public partial class _Default : System.Web.UI.Page
protected void Page_Load(object sender, EventArgs e)

protected void Button1_Click(object sender, EventArgs e)
if (FileUpload1.HasFile)
string filename = FileUpload1.FileName;

void ExportToGrid(string path)
DataSet ds = new DataSet();
DataTable dt = new DataTable();
DataRow[] dr;
DataTable dtfilter = new DataTable();
//Here i load all xml data in to dataset
dt = ds.Tables[0];
//Filter here above employe no ten records
dr = dt.Select("eno > 110");
dtfilter = dr.CopyToDataTable();
GridView1.DataSource = dtfilter;
catch (Exception ex)

//Delete after read data from server path
if (System.IO.File.Exists(path))

Output :


Source code:

Client Side: ASP.NET
Code Behind: C#


I hope this code snippet is helping you to know about filter xml data through DataTable and display in the gridview.


  • ReadXml_Source (43969-75237-ReadXml-Source.rar)
  • Comments

    No responses found. Be the first to comment...

  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name: