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

CheckBox in RadComboBox

1 Answer 131 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
kia
Top achievements
Rank 1
kia asked on 23 Oct 2010, 11:32 AM
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!!!

1 Answer, 1 is accepted

Sort by
0
Calleigh
Top achievements
Rank 1
answered on 28 Oct 2010, 01:29 PM
This happens because RadComboBox items loaded via Load On Demand are not persisted at server-side.
Tags
ComboBox
Asked by
kia
Top achievements
Rank 1
Answers by
Calleigh
Top achievements
Rank 1
Share this question
or