CheckedItems returns 0

2 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" 
                                                         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


    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.

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

    protected void Page_Load(object sender, EventArgs e)
        if (!IsPostBack)
            DataTable data = GetData(new SqlCommand("SELECT CountryName,CountryId FROM Country"));
            cboBenchmarkCompanies.DataSource = data; ;
    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();
        return data;

    Please provide your full code if it doesn't help.
  3. DevCraft R3 2016 release webinar banner
Back to Top