View Single Post
  #4 (permalink)  
Old 07-01-2008, 10:44 PM
poornima poornima is offline
D-Web Sr.Programmer
 
Join Date: Dec 2007
Posts: 189
poornima is on a distinguished road
Smile Re: How to populate items to Drop downlist without postback?

Hi,
See the following example.
My need is to get the state list in one DropDownlist according to the country name in another DropDownlist.
Consider My xml(countryContent.xml) like this,
<xml>
<country Name="US">
<state countryId="1" stateName="ottawa" />
<state countryId="1" stateName="SovietUnion" />
<state countryId="1" stateName="u" />
<state countryId="1" stateName="UUU " />
</country>
<country Name="India">
<state countryId="2" stateName="Agra" />
<state countryId="2" stateName="AndraPradesh" />
<state countryId="2" stateName="Kerala" />
<state countryId="2" stateName="Maharastra" />
<state countryId="2" stateName="Mumbai" />
<state countryId="2" stateName="TamilNadu" />
<state countryId="2" stateName="U.P" />
</country>
</xml>

In PageLoad,write the following coding
protected void Page_load(object sender,EventArgs e)
{
DataTable dataTable = new DataTable();
DataRow dr;
dataTable.Columns.Add("countryName", typeof(string));
if (!IsPostBack)
{
XmlDocument xdoc = new XmlDocument();
XmlTextReader xtr = new XmlTextReader(Server.MapPath("countryContent.xml") );
xdoc.Load(xtr);
XmlNodeList xnl = xdoc.DocumentElement.SelectNodes("country");
foreach (XmlNode xnode in xnl)
{
dr = dataTable.NewRow();
dr[0] = xnode.Attributes[0].Value;
dataTable.Rows.Add(dr);
}
countryDropDownList.DataSource = dataTable;
countryDropDownList.DataValueField = "countryName";
countryDropDownList.DataBind();
}
}
Like this, write the coding for state DropDownlist.
This will avoid page refresh
Reply With Quote