I'm new to asp.net. I'm trying to create two linked dropdownlist i.e if first one is changed then the content of the second list should change accordingly. Also, based on those selections I want to display a table of data(please suggest what to use listview,gridview or repeater). My database is in mysql.using c#
-
i dont know how to do it. i mean i can create normal dropdownlist.As i said am new in this.i mean am switching from php,this is quite complicated.iamsolankiamit– iamsolankiamit2012-08-19 14:43:19 +00:00Commented Aug 19, 2012 at 14:43
-
1why don't you pick a book or search for a tutorial online and learn Asp.Netcodingbiz– codingbiz2012-08-19 14:46:21 +00:00Commented Aug 19, 2012 at 14:46
-
i did search a lot of them.first i had huge problem with mysql connection through c# it got solved after a lot of research ,had to waste quite alot of time.So i thought that i should ask here which is better coz that way i'd save some time and get some help from better answersiamsolankiamit– iamsolankiamit2012-08-19 14:51:43 +00:00Commented Aug 19, 2012 at 14:51
-
Spending time on searching for answers is NEVER a waste of time! If you think otherwise, maybe reconsider your decision on becoming a programmer.walther– walther2012-08-19 14:52:29 +00:00Commented Aug 19, 2012 at 14:52
-
okay i didn't waste time but i wanted to complete the job at hand.iamsolankiamit– iamsolankiamit2012-08-19 14:56:10 +00:00Commented Aug 19, 2012 at 14:56
2 Answers
Sentence "I'm newbie" doesn't matter here, because principles are all the same. You want to create two linked dropdownlists. So do it.
What would you do then in php? You guess right, do an ajax call to the server.
Here you have multiple options to choose from. Since you're comming from php background, I'd suggest using jquery.ajax to make the call. So you'd create the first dropdownlist with the values you need and hook the event using jquery, to handle when the user changes the selected value. Make the call using jquery to the web service with the selected value. You receive an answer from a webservice (search for tutorials, there are plenty of them on the web) and use the jquery again, this time to populate the second dropdownlist.
2 Comments
You basically need to do something like this:
<asp:DropDownList ID="DDL1" AutoPostBack="true" runat="server" OnSelectedIndexChanged="DDL1_SelectedIndexChanged">
</asp:DropDownList>
In the code-behind, you basically do the binding for your second drop down list in the method called DDL1_SelectedIndexChanged (ie after someone changes the selection in the first drop down list)
protected void DDL1_SelectedIndexChanged(object sender, EventArgs e)
{
// databind for second drop down list
}