Databinding in Gridview while we select a value from dropdown

Posted by Ganesh under ASP.NET on 11/25/2008 | Views : 3581 | Status : [Member] | Replies : 2

I have 2 controls like dropdown (named ddl) and gridview (named gridview1) and a xml file (named AppCatalog.xml).

My xml look like

Already I have bind this record in gridview using dataset. And I have bind the node (<field1>tamilnadu</field1>) in dropdown.

Now what i want is... when I select a value (like tamilnadu) in dropdown, then the full records relevant to "tamilnadu" will be display in gridview (that is my gridview show one record only contains "tamilnadu chennai tnagar"

Guys who is help me earliest is thankful.


Posted by: Jayakumars on: 9/30/2012 [Member] [MVP] Bronze | Points: 25


ds.readxml using the dataset and concatenate your data.

Mark as Answer if its helpful to you

Ganesh, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Majith on: 11/25/2008 [Member] Starter

Hi Ganesh,

Create an Datatable ,data row in order select the particular element.


  DataTable dt = new DataTable(); // creating data table

DataColumn dc = new DataColumn("Id"); //xml element1
DataColumn dc1 = new DataColumn("Name"); // xml element2
string ct = ddl.SelectedItem.ToString(); // dropdown selected item
string dataPath = Server.MapPath("place.xml"); // xml file path
DataSet dSet = new DataSet(); // new dataset
dSet.ReadXml(dataPath); // reading xml file
DataRow[] rows = dSet.Tables[0].Select(" Name = '" + ct + "'");
// selecting particular record
// searching record
foreach (DataRow dr in rows)
DataRow myRow = dt.NewRow();
myRow["Id"] = dr["Id"];
myRow["Name"] = dr["Name"];


grxml.DataSource = dt; // binding from data table

Inline code:

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

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">

<html xmlns="" >
<head runat="server">
<title>Untitled Page</title>
<form id="form1" runat="server">
<br /><br /><br />
<asp:DropDownList ID="ddl" runat="server"></asp:DropDownList>&nbsp;<br />
<br />
<br />
<br />
&nbsp;<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" /></div>
<asp:GridView ID="grxml" runat="server">

hope this help

Ganesh, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response