You must Sign In to post a response.
Category: XML
#667397
If you don't want to popstback then you can AJAXUpdate panel and use Selected index change event for binding XML values to dropdownlists.
check following link it may help you
http://www.csgnetwork.com/directcountrystatecitydrop.html
http://www.c-sharpcorner.com/uploadfile/rohatash/dropdownlist-with-country-state-and-city-in-asp-net/
Thanks
Koolprasd2003
Editor, DotNetSpider MVM
Microsoft MVP 2014 [ASP.NET/IIS]
check following link it may help you
http://www.csgnetwork.com/directcountrystatecitydrop.html
http://www.c-sharpcorner.com/uploadfile/rohatash/dropdownlist-with-country-state-and-city-in-asp-net/
Thanks
Koolprasd2003
Editor, DotNetSpider MVM
Microsoft MVP 2014 [ASP.NET/IIS]
#667401
#667405
Please check the following code:
XmlFile.xml
-----------
Default.aspx
------------
Default.aspx.cs
---------------
Thanks & Regards
Paritosh Mohapatra
Microsoft MVP (ASP.Net/IIS)
DotNetSpider MVM
XmlFile.xml
-----------
<data>
<Country id="1" name="India" />
<Country id="2" name="Australia" />
<Country id="3" name="USA" />
<State id="1" name="Maharastra" cid="1" />
<State id="2" name="West Bengal" cid="1" />
<State id="3" name="Orissa" cid="1" />
<State id="4" name="Melbourne" cid="2" />
<State id="5" name="New Jersy" cid="3" />
<City id="1" name="Mumbai" sid="1" />
<City id="2" name="Pune" sid="1" />
<City id="3" name="Kolkata" sid="2" />
<City id="4" name="Kharagpur" sid="2" />
<City id="5" name="Bhubaneswar" sid="3" />
<City id="6" name="Cuttack" sid="3" />
<City id="7" name="AusCity1" sid="4" />
<City id="8" name="USACity2" sid="5" />
</data>
Default.aspx
------------
<div>
<asp:DropDownList ID="DdlCountry" runat="server" AutoPostBack="True"
onselectedindexchanged="DdlCountry_SelectedIndexChanged">
</asp:DropDownList>
<asp:DropDownList ID="DdlState" runat="server" AutoPostBack="True"
onselectedindexchanged="DdlState_SelectedIndexChanged">
</asp:DropDownList>
<asp:DropDownList ID="DdlCity" runat="server">
</asp:DropDownList>
</div>
Default.aspx.cs
---------------
public static DataSet ds;
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
ds = new DataSet();
ds.ReadXml(Server.MapPath("~/XMLFile.xml"));
BindCountry();
}
}
public void BindCountry()
{
DdlCountry.DataTextField = "name";
DdlCountry.DataValueField = "id";
DdlCountry.DataSource = ds.Tables["Country"];
DdlCountry.DataBind();
BindState(DdlCountry.SelectedValue);
}
public void BindState(string cid)
{
DdlState.DataTextField = "name";
DdlState.DataValueField = "id";
DataView dv = new DataView(ds.Tables["State"]);
dv.RowFilter = "cid = " + cid;
DdlState.DataSource = dv.ToTable();
DdlState.DataBind();
BindCity(DdlState.SelectedValue);
}
public void BindCity(string sid)
{
DdlCity.DataTextField = "name";
DdlCity.DataValueField = "id";
DataView dv = new DataView(ds.Tables["City"]);
dv.RowFilter = "sid = " + sid;
DdlCity.DataSource = dv.ToTable();
DdlCity.DataBind();
}
protected void DdlCountry_SelectedIndexChanged(object sender, EventArgs e)
{
BindState(DdlCountry.SelectedValue);
}
protected void DdlState_SelectedIndexChanged(object sender, EventArgs e)
{
BindCity(DdlState.SelectedValue);
}
Thanks & Regards
Paritosh Mohapatra
Microsoft MVP (ASP.Net/IIS)
DotNetSpider MVM
#667464
Hi Paritosh,
I tried with different way and that is works fine. but it is very simple. Thank for your reply Paritosh.
I tried with different way and that is works fine. but it is very simple. Thank for your reply Paritosh.
#667512
Hi Anitha,
Could you send code which you tried in different way and which is very simple.
Could you send code which you tried in different way and which is very simple.
Return to Return to Discussion Forum