I have two related comboboxes (copied the code from
http://demos.telerik.com/aspnet-ajax/combobox/examples/functionality/multiplecomboboxes/defaultvb.aspx).
The problem is that I have another button on the page that invokes a 'save' function where I want to extract the selectedvalue to save in the DB.
In this function, I get RadComboBoxGeneralField.SelectedValue=-1 (the first item in the combobox), when actually on the page another item is selected!!
When I get RadComboBoxGeneralField.Text it shows the item text (as in the page for example "Mathematics"),
but RadComboBoxGeneralField.SelectedItem.Text shows the first item in the list!
It looks as if the control just doesn't do the select.
Code attached below:
The first shows a list of Broad Fields:
telerik:RadComboBox ID="RadComboBoxBroadField" runat="server" OnClientSelectedIndexChanged="fnLoadGeneralField" telerik:RadComboBox>
The second shows a list of General Fields:
<telerik:RadComboBox ID="RadComboBoxGeneralField" runat="server" OnItemsRequested="RadComboBoxGeneralField_ItemsRequested" OnClientItemsRequested="ItemsLoaded" OnClientSelectedIndexChanged="fnLoadSpecificField" ></telerik:RadComboBox>
JavaScript:
<
script type="text/javascript">
//global variables for the general and specific comboboxes
var generalfieldCombo;
var specificfieldCombo;
function pageLoad()
{
// initialize the global variables
// in this event all client objects are already created and initialized
generalfieldCombo = $find("<%= RadComboBoxGeneralField.ClientID %>");
specificfieldCombo = $find(
"<%= RadComboBoxSpecificField.ClientID %>");
}
function
fnLoadGeneralField(combo, eventArqs)
{
var item = eventArqs.get_item();
generalfieldCombo.clearItems();
generalfieldCombo.set_text(
"Loading...");
// if a broad field is selected
if (item.get_index() > 0)
{
// this will fire the ItemsRequested event of the
// general field combobox passing the broadfieldID as a parameter
generalfieldCombo.requestItems(item.get_value(), false);
}
else
{
// the <Choose> item was chosen
generalfieldCombo.set_text("N/A");
generalfieldCombo.clearItems();
}
}
function ItemsLoaded(combo, eventArqs)
{
if (combo.get_items().get_count() > 0)
{
// pre-select the first item
combo.set_text(combo.get_items().getItem(0).get_text());
combo.get_items().getItem(0).highlight();
}
else
combo.set_text("N/A");
}
</script>
Server Code (VB.NET)
The BroadField is loaded through the code on page load using DataBind().
Protected
Sub RadComboBoxGeneralField_ItemsRequested(ByVal o As System.Object, ByVal e As Telerik.Web.UI.RadComboBoxItemsRequestedEventArgs) Handles RadComboBoxGeneralField.ItemsRequested
LoadGeneralField(
CInt(e.Text))
End Sub
Public
Sub LoadGeneralField(ByVal intBroadFieldId As Integer)
Dim dsDB As New DataSet
' Filling the dataset (code ommitted)
If dsDB.Tables(0).Rows.Count > 0 Then
RadComboBoxGeneralField.DataTextField =
"GF_Desc"
RadComboBoxGeneralField.DataValueField = "GF_Id"
RadComboBoxGeneralField.DataSource = dsDB.Tables(0)
RadComboBoxGeneralField.DataBind()
End If
End Sub