Hi There
I've got a dual combobox which I would like to prepopulate with values from querystring to keep the state persistent.
The problem is that when I load the child dropdown from server side and set the selected value, and then change the parent dropdown from the client side, it does not fire the child dropdown to populate with new values based on parent combo.
Any suggestions?
Here is my code :
Any help will be appreciated.
Many thanks!
I've got a dual combobox which I would like to prepopulate with values from querystring to keep the state persistent.
The problem is that when I load the child dropdown from server side and set the selected value, and then change the parent dropdown from the client side, it does not fire the child dropdown to populate with new values based on parent combo.
Any suggestions?
Here is my code :
<telerik:RadComboBox ID="ddnRegion" runat="server" Skin="Default" OnClientSelectedIndexChanging="LoadTowns" Width="180px" EnableLoadOnDemand="true" /> |
<br /> |
<br /> |
<telerik:RadComboBox ID="ddnTown" runat="server" Width="180px" Skin="Default" EnableLoadOnDemand="true" |
OnClientItemsRequested="ItemsLoaded" OnItemsRequested="ddnTown_ItemsRequested" /> |
<script type="text/javascript"> |
function LoadTowns(combo, eventarqs) { |
var townCombo = $find("<%=ddnTown.ClientID%>"); |
var item = eventarqs.get_item(); |
townCombo.set_text("Loading..."); |
if (item.get_index() > 0) { |
townCombo.requestItems(item.get_value(), false); |
} |
else { |
townCombo.set_text(" "); |
townCombo.clearItems(); |
} |
} |
function ItemsLoaded(combo, eventarqs) { |
var townCombo = $find("<%=ddnTown.ClientID%>"); |
if (combo.get_items().get_count() > 0) { |
combo.set_text(combo.get_items().getItem(0).get_text()); |
combo.get_items().getItem(0).highlight(); |
} |
combo.showDropDown(); |
} |
</script> |
protected void Page_Load(object sender, EventArgs e) |
{ |
if (!Page.IsPostBack && !Page.IsCallback) |
{ |
//first populate dropdowns |
LoadRegions(); |
if (Request.QueryString["region"] != null && Request.QueryString["region"] != "" && Request.QueryString["town"] != null && Request.QueryString["town"] != "") |
{ |
LoadTowns(Request.QueryString["region"]); |
} |
LoadServices(); |
} |
} |
void LoadRegions() |
{ |
CMSManager manager = new CMSManager(dbConn()); |
ddnRegion.DataSource = manager.GettblRegions(); |
ddnRegion.DataTextField = "RegionName"; |
ddnRegion.DataValueField = "RegionId"; |
ddnRegion.DataBind(); |
ddnRegion.Sort = RadComboBoxSort.Ascending; |
ddnRegion.SortItems(); |
ddnRegion.Items.Insert(0, new RadComboBoxItem("[Select a Region]")); |
foreach (RadComboBoxItem item in ddnRegion.Items) |
{ |
item.ToolTip = item.Text; |
} |
if (Request.QueryString["region"] != null && Request.QueryString["region"] != "") |
{ |
ddnRegion.SelectedIndex = ddnRegion.Items.IndexOf(ddnRegion.Items.FindItemByValue(Request.QueryString["region"])); |
} |
} |
void LoadTowns(string regionId) |
{ |
CMSManager manager = new CMSManager(dbConn()); |
ddnTown.DataSource = manager.GettblTownsByRegionID(Convert.ToInt32(regionId)); |
ddnTown.DataTextField = "TownName"; |
ddnTown.DataValueField = "TownId"; |
ddnTown.DataBind(); |
ddnTown.Sort = RadComboBoxSort.Ascending; |
ddnTown.SortItems(); |
ddnTown.Items.Insert(0, new RadComboBoxItem("[Select a Town]")); |
foreach (RadComboBoxItem item in ddnTown.Items) |
{ |
item.ToolTip = item.Text; |
} |
if (Request.QueryString["region"] != null && Request.QueryString["region"] != "" && Request.QueryString["town"] != null && Request.QueryString["town"] != "") |
{ |
ddnTown.SelectedIndex = ddnTown.Items.IndexOf(ddnTown.Items.FindItemByValue(Request.QueryString["town"])); |
} |
} |
protected void ddnRegion_ItemsRequested(object o, RadComboBoxItemsRequestedEventArgs e) |
{ |
LoadRegions(); |
} |
protected void ddnTown_ItemsRequested(object o, RadComboBoxItemsRequestedEventArgs e) |
{ |
LoadTowns(e.Text); |
} |
Any help will be appreciated.
Many thanks!