CheckedItems returns 0

5 posts, 0 answers
  1. RBeco
    RBeco avatar
    15 posts
    Member since:
    Apr 2013

    Posted 27 Apr 2014 Link to this post

    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?

  2. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 28 Apr 2014 in reply to RBeco Link to this post

    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.
  3. Gauri
    Gauri avatar
    3 posts
    Member since:
    Jan 2018

    Posted 16 Jul 2018 in reply to Shinu Link to this post

    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

  4. Marin Bratanov
    Admin
    Marin Bratanov avatar
    5126 posts

    Posted 16 Jul 2018 Link to this post

    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.
  5. Gauri
    Gauri avatar
    3 posts
    Member since:
    Jan 2018

    Posted 16 Jul 2018 in reply to Marin Bratanov Link to this post

    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.

     

Back to Top