Go Back   CodingForums.com > :: Server side development > ASP.NET

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rating: Thread Rating: 6 votes, 3.67 average.
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 04-07-2011, 06:03 PM   PM User | #1
preetpalkapoor
New to the CF scene

 
Join Date: Apr 2011
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
preetpalkapoor is an unknown quantity at this point
Dynamic drop down list by using asp.net, c# and sql server

Hi

I am trying to bind data with 2 dropdowns.

I am having 2 tables (sql server):
1)country:
country_id(primary key)
country_name
2)state:
state_id(primary key)
state_name
country_id(foreign_key)

now i tried to bind the data with 2 dropdown list
ddp1 and ddp2.
such that when i select the country from first dropdown(ddp1) then the state corresponding to that country should come in the second dropdown(ddp2).

Can some one please help me .

Thanks .
preetpalkapoor is offline   Reply With Quote
Old 04-08-2011, 04:04 PM   PM User | #2
Mike_O
Regular Coder

 
Join Date: Apr 2009
Posts: 244
Thanks: 1
Thanked 20 Times in 20 Posts
Mike_O is an unknown quantity at this point
Hi preetpalkapoor,

If you're asking how to bind data, here is an example:
http://www.dotnetheaven.com/UploadFi...ndatagrid.aspx

Now, if you're asking when to bind data in your second dropdown, well, you would do that in the event of making a selection in your first dropdown. I think OnSelectedIndexChanged should do it. So, your first dropdown will look something like this:

Code:
<asp:DropDownList ID="ddp1" runat="server" ... OnSelectedIndexChanged="GetStates" ...>
...
</asp:DropdownList>
Then in your codebehind, you will have method:

Code:
protected void GetStates(object sender, EventArgs e)
{
   //Get states from SQL
   //Bind results to ddp2
}

Easy. Oh, and one tip from me (since you happen to be using C#): Use the "Using" statement to create your objects (the disposable ones, that is)

Regards,
Mike
Mike_O is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 10:12 PM.


Advertisement
Log in to turn off these ads.