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

CheckedItems returns 0

4 Answers 130 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
RBeco
Top achievements
Rank 1
RBeco asked on 27 Apr 2014, 11:34 AM
I have a RadCombobox on my page as follows:

  <telerik:RadComboBox ID="cboBenchmarkCompanies" runat="server" 
                                                     CheckBoxes="true" 
                                                     DataTextField="Value"
                                                     DataValueField="Key"
                                                     EnableLoadOnDemand="False"
                                                     OnClientItemChecking="CheckMaxBenchmarkCompanies"
                                                     meta:resourcekey="cboBenchmarkCompanies" />

I load the list in the onload with:
            if (!this.IsPostBack) {
                var allCompanies = _applicationUserRepository.GetAllSurveyUsers();
                cboBenchmarkCompanies.DataSource = allCompanies;
                cboBenchmarkCompanies.DataBind(); }

If i then try to retrieve the checked items after pressing a save button, i always get back an empty collection instead of my checked items:
foreach (var checkedItem in cboBenchmarkCompanies.CheckedItems ){

What am I doing wrong?

4 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 28 Apr 2014, 05:44 AM
Hi,

Unfortunately I couldn't replicate the issue at my end. Please have a look into the sample code snippet which works fine at my end.

ASPX:
<telerik:RadComboBox ID="cboBenchmarkCompanies" runat="server" CheckBoxes="true"  DataTextField="CountryName" DataValueField="CountryId" />
<telerik:RadButton ID="radbtnCheckedItems" runat="server" Text="CheckedItems" OnClick="radbtnCheckedItems_Click">
</telerik:RadButton>

C#:
protected void Page_Load(object sender, EventArgs e)
{
    if (!IsPostBack)
    {
        DataTable data = GetData(new SqlCommand("SELECT CountryName,CountryId FROM Country"));
        cboBenchmarkCompanies.DataSource = data; ;
        cboBenchmarkCompanies.DataBind();
    }
}
protected void radbtnCheckedItems_Click(object sender, EventArgs e)
{
    int checkeditemsCount=cboBenchmarkCompanies.CheckedItems.Count;
    foreach (Telerik.Web.UI.RadComboBoxItem item in cboBenchmarkCompanies.CheckedItems)
    {
        //your code
    }
}
private static DataTable GetData(SqlCommand selectCommand)
{
    selectCommand.Connection = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);
    SqlDataAdapter adapter = new SqlDataAdapter(selectCommand);
    DataTable data = new DataTable();
    adapter.Fill(data);
    return data;
}

Please provide your full code if it doesn't help.
Thanks,
Shinu.
0
Gauri
Top achievements
Rank 1
answered on 16 Jul 2018, 04:51 PM

Shinu,

It works when you load the radcombobox from pagebehind. But when you load the radcombobox using 

webservice and ondemandload it doesn't return any data for checkeditems

0
Marin Bratanov
Telerik team
answered on 16 Jul 2018, 05:29 PM
Hi Gauri,

This is the reason why load-on-demand is listed as a limitation of the checbox feature. The following article lists the other known limitation and also offers a solution: https://docs.telerik.com/devtools/aspnet-ajax/controls/combobox/functionality/checkbox-support#limitations.


Regards,
Marin Bratanov
Progress Telerik
Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
0
Gauri
Top achievements
Rank 1
answered on 16 Jul 2018, 05:39 PM

Thanks.

I think you should atleas add a message ot error message when ondemand is used along with CheckBox- true

I used a work around.

For someone else in the same shoe... here it is....

 

I need one to many radcombobox and grid on a page.

I wrote a function to load the unused values in the radcombobox. i.e. If it has values

1 abc

2. bcd

3 cde

4 def

If you add bcd and def next time only abc and cde will be shown in the radcombobox.

Load radcombobox on page_load using the function

use the same function to load the combobox after addingthe value or deleting it from the grid.

Hope it helps others.

 

Tags
ComboBox
Asked by
RBeco
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Gauri
Top achievements
Rank 1
Marin Bratanov
Telerik team
Share this question
or