CheckBox in RadComboBox

2 posts, 0 answers
  1. kia
    kia avatar
    17 posts
    Member since:
    Oct 2010

    Posted 23 Oct 2010 Link to this post

    Hi
    I want to use Asp:CheckBox in RadComboBox that users can select any item from my RadComboBox items
    I use this Asp code:
    <telerik:RadComboBox ID="drpEmailAddress" runat="server"
        Width="98%" Skin="Outlook"
        EmptyMessage="Select" EnableLoadOnDemand="True" ShowMoreResultsBox="true"
        EnableVirtualScrolling="true" EnableAutomaticLoadOnDemand="true" OnItemsRequested="drpEmailAddress_ItemsRequested">
        <ItemTemplate>                                        
            <asp:CheckBox runat="server" ID="chkAddress" Text='<%#Eval("Address")%>'/>
        </ItemTemplate>                                                        
    </telerik:RadComboBox>

    and this Cs Code for ItemsRequested event:
    protected void drpEmailAddress_ItemsRequested(object o, RadComboBoxItemsRequestedEventArgs e)
    {
        var q = GetData(e.Text);
        int itemOffset = e.NumberOfItems;
        int endOffset = Math.Min(itemOffset + 20, q.Count);
        e.EndOfItems = endOffset == q.Count;
        e.Message = GetStatusMessage(endOffset, q.Count); 
          drpEmailAddress.DataTextField = "Address";
          drpEmailAddress.DataValueField = "AddressId";

        drpEmailAddress.DataSource = q.Take(20);
        drpEmailAddress.DataBind();
    }

     

    private static string GetStatusMessage(int offset, int total)

     

    {

     

      if (total <= 0)

     

     

        return "Nothing found";

     

     

      return String.Format(" <b>1 </b> <b>{0} </b> <b>{1}</b>", offset, total);

     

    }


    When users selecting items (checking CheckBox) i can't get selected items in my CS code!!!
    I use this code for get selected items in my Cs:
    protected void btnSend_Click(object sender, EventArgs e) 
        var q = (from a in drpEmailAddress.Items 
                         where (a.FindControl("chkAddress") as CheckBox).Checked 
                 select a).ToList();
    }

    but q is empty!!!
  2. Calleigh
    Calleigh avatar
    9 posts
    Member since:
    Sep 2010

    Posted 28 Oct 2010 Link to this post

    This happens because RadComboBox items loaded via Load On Demand are not persisted at server-side.
Back to Top