asp.net - Combo box with multiple columns and related values -
is possible show multiple columns , headers inside of combo box/dropdown list in asp.net , show related columns values, example, if click on country name should show me cities country , clicking on city name should show me related places.
is there third part control available? have checked telerik , have combo box multiple columns not related values.
i hope started.

<telerik:radcombobox id="radcombobox1" runat="server" autopostback="true" onselectedindexchanged="radcombobox1_selectedindexchanged"> <itemtemplate> <table width="100%"> <tr> <td> <%# eval("name") %> </td> <td> <%# eval("population")%> </td> </tr> </table> </itemtemplate> </telerik:radcombobox> <telerik:radcombobox id="radcombobox2" runat="server" autopostback="true" onselectedindexchanged="radcombobox2_selectedindexchanged"> <itemtemplate> <table width="100%"> <tr> <td> <%# eval("name") %> </td> <td> <%# eval("population")%> </td> </tr> </table> </itemtemplate> </telerik:radcombobox> <telerik:radcombobox id="radcombobox3" runat="server"> <itemtemplate> <table width="100%"> <tr> <td> <%# eval("name") %> </td> <td> <%# eval("population")%> </td> </tr> </table> </itemtemplate> </telerik:radcombobox> public class country { public int id { get; set; } public string name { get; set; } public int population { get; set; } } public class state { public int id { get; set; } public int countryid { get; set; } public string name { get; set; } public int population { get; set; } } public class city { public int id { get; set; } public int stateid { get; set; } public string name { get; set; } public int population { get; set; } } public list<country> countries { { return new list<country> { new country {id = 1, name = "united states", population = 1000}, new country {id = 2, name = "canada", population = 2000}, new country {id = 3, name = "mexico", population = 3000} }; } } public list<state> states { { return new list<state> { new state {id = 1, countryid = 1, name = "california", population = 100}, new state {id = 2, countryid = 1, name = "new york", population = 200}, new state {id = 3, countryid = 2, name = "quebec", population = 300}, new state {id = 4, countryid = 2, name = "ontario", population = 400} }; } } public list<city> cities { { return new list<city> { new city {id = 1, stateid = 1, name = "los angeles", population = 10}, new city {id = 2, stateid = 1, name = "san diego", population = 20}, new city {id = 3, stateid = 1, name = "san francisco", population = 30}, new city {id = 4, stateid = 1, name = "san joe", population = 40}, new city {id = 5, stateid = 2, name = "new york", population = 50}, new city {id = 6, stateid = 2, name = "paterson", population = 60}, new city {id = 7, stateid = 2, name = "newark", population = 70}, new city {id = 8, stateid = 2, name = "smithtown", population = 80}, }; } } protected void page_load(object sender, eventargs e) { if(!ispostback) { radcombobox1.datasource = countries; radcombobox1.datavaluefield = "id"; radcombobox1.datatextfield = "name"; radcombobox1.databind(); radcombobox1.items.insert(0, new radcomboboxitem("select country", "")); } } protected void radcombobox1_selectedindexchanged( object sender, radcomboboxselectedindexchangedeventargs e) { radcombobox2.items.clear(); radcombobox3.items.clear(); int countryid; if (int32.tryparse(e.value, out countryid)) { radcombobox2.datasource = states.where(s => s.countryid == countryid); radcombobox2.datavaluefield = "id"; radcombobox2.datatextfield = "name"; radcombobox2.databind(); radcombobox2.items.insert(0, new radcomboboxitem("select state", "")); } } protected void radcombobox2_selectedindexchanged( object sender, radcomboboxselectedindexchangedeventargs e) { radcombobox3.items.clear(); int stateid; if (int32.tryparse(e.value, out stateid)) { radcombobox3.datasource = cities.where(c => c.stateid == stateid); radcombobox3.datavaluefield = "id"; radcombobox3.datatextfield = "name"; radcombobox3.databind(); radcombobox3.items.insert(0, new radcomboboxitem("select city", "")); } }
Comments
Post a Comment