Cascading WebDropDown

Posted by Kranthi under ASP.NET on 12/14/2010 | Points: 10 | Views : 3267 | Status : [Member] | Replies : 4
How to Populate WebDropDown using StateWebDropDown and CityWebDropDown




Responses

Posted by: Chvrsri on: 12/14/2010 [Member] [Moderator] [MVP] Silver | Points: 25

Up
0
Down
Hi Kranthi,

Do you mean you want a change in city value with respect to the state selected ?

If yes use this

In Default.aspx page

<table>

<tr>
<td>
COUNTRY :
</td>
<td>
<asp:DropDownList ID="ddl1" runat="server" AutoPostBack="True" OnSelectedIndexChanged="ddl1_SelectedIndexChanged">
</asp:DropDownList>
</td>
</tr>

<tr>
<td>
STATE :
</td>
<td>
<asp:DropDownList ID="ddl2" runat="server"></asp:DropDownList>
</td>
</tr>
</table>


Now Bind the data in Default.aspx.cs PageLoad Event


protected void Page_Load(object sender, EventArgs e)

{

if (!IsPostBack)
{
SqlConnection con = new SqlConnection("server=server-name;user id=user-id;password=pwd;database=dbname");
con.Open();

SqlDataAdapter da = new SqlDataAdapter("SELECT * FROM Country", con);
DataSet ds = new DataSet();
da.Fill(ds, "Country");
ddl1.DataSource = ds;
ddl1.DataTextField = "CountryName";
ddl1.DataValueField = "CountryID";
ddl1.DataBind();
con.Close();
}
}


Now the Selected index change event for DropDownList 1

protected void ddl1_SelectedIndexChanged(object sender, EventArgs e)

{
SqlConnection con = new SqlConnection("server=server-name;user id=user-id;password=pwd;database=dbname");
string sri = ddl1.SelectedValue.ToString();
con.Open();
SqlDataAdapter da = new SqlDataAdapter("select * from State where CountryID='" + sri + "'", con);
DataSet ds1 = new DataSet();
da.Fill(ds1, "State");
ddl2.DataSource = ds1;
ddl2.DataTextField = "StateName";
ddl2.DataValueField = "CountryID";
ddl2.DataBind();
con.Close();
}


Thanks,
Radha Srikanth

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

Posted by: T.saravanan on: 12/14/2010 [Member] [MVP] Silver | Points: 25

Up
0
Down
Hi,

Try this links...

http://dotnetguts.blogspot.com/2008/06/finding-country-from-visitors-ip-in.html

http://www.dotnetspark.com/kb/1864-get-country-names-from-system-using-systemglobalization.aspx

My Suggestion is just create a tables for Country, State and City based on Country ID.To store the details into that table and refer that tables.

If you want to bind a data in dropdown based on country selection in one dropdown means refer Chvrsri Code...

Cheers :)


Thanks,
T.Saravanan

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

Posted by: Kranthi on: 12/14/2010 [Member] Starter | Points: 25

Up
0
Down
am using WebDropDown(It is infrajistics tool) am not using DropDownList

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

Posted by: Chvrsri on: 12/15/2010 [Member] [Moderator] [MVP] Silver | Points: 25

Up
0
Down
Hi try this link

http://samples.infragistics.com/2010.1/WebFeatureBrowser/Default.aspx

After visiting that link, in the right side panel you will find webdropdown. there you will find the samples relating to it.

Hope this helps

Thanks,
Radha Srikanth

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

Login to post response