This is a migrated thread and some comments may be shown as answers.

Combobox selected value is null

1 Answer 155 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
kd
Top achievements
Rank 1
kd asked on 06 Jan 2012, 12:09 PM
Hi All,
I have 2 comboboxes on page both i have bind load on demand, both are working well but i want to get selected value of first combobox on second combobox OnItemsRequested Event but when second combobox event OnItemsRequested fires the selected value of first combobox is null my code is follws
<telerik:RadComboBox ID="rcbCategory" runat="server" EmptyMessage="Select Category"
                            OnItemsRequested="rcbCategory_OnItemsRequested" EnableLoadOnDemand="true" EnableViewState="true">
                        </telerik:RadComboBox>
 
<telerik:RadComboBox ID="rcbSubCategory" runat="server" OnItemsRequested="rcbSubCategory_OnItemsRequested"
                            EnableLoadOnDemand="true" EmptyMessage="Select Sub-Category">
                        </telerik:RadComboBox>
 
 
C#
protected void rcbCategory_OnItemsRequested(object sender, RadComboBoxItemsRequestedEventArgs e)
        {
            rcbCategory.DataSource = Category.GetAll();
            rcbCategory.DataValueField = "ID";
            rcbCategory.DataTextField = "CategoryName";
            rcbCategory.DataBind();
        }
 
        protected void rcbSubCategory_OnItemsRequested(object sender, RadComboBoxItemsRequestedEventArgs e)
        {
            rcbSubCategory.DataSource = SubCategory.GetAll(rcbCategory.SelectedValue);
            rcbSubCategory.DataValueField = "ID";
            rcbSubCategory.DataTextField = "CategoryName";
            rcbSubCategory.DataBind();
        }

1 Answer, 1 is accepted

Sort by
0
Ivana
Telerik team
answered on 06 Jan 2012, 02:28 PM
Hi,

You could try the following:

<telerik:RadComboBox ID="rcbCategory" runat="server" EmptyMessage="Select Category"
    OnClientSelectedIndexChanged="OnClientSelectedIndexChanged" OnItemsRequested="rcbCategory_OnItemsRequested"
    EnableLoadOnDemand="true" EnableViewState="true">
</telerik:RadComboBox>
<telerik:RadComboBox ID="rcbSubCategory" runat="server" OnItemsRequested="rcbSubCategory_OnItemsRequested"
    EnableLoadOnDemand="true" EmptyMessage="Select Sub-Category" >
</telerik:RadComboBox>
<asp:HiddenField runat="server" ID="hiddenField1" Value=" " />
<script type="text/javascript">
    function OnClientSelectedIndexChanged(sender, args) {
        $find("<%= rcbSubCategory.ClientID%>").requestItems(args.get_item().get_value());
    }
</script>
protected void rcbSubCategory_OnItemsRequested(object sender, RadComboBoxItemsRequestedEventArgs e)
{
    string rcbCategory_SelectedValue = e.Text;
}

You could refer to the following help article for more information of load on demand: Load On Demand Overview and the implementation of the online demo: Related ComboBoxes.

Regards,
Ivana
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now
Tags
ComboBox
Asked by
kd
Top achievements
Rank 1
Answers by
Ivana
Telerik team
Share this question
or