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

[Solved] How to preselect an item in combobox with checkbox

1 Answer 198 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
iomega 55
Top achievements
Rank 1
iomega 55 asked on 19 Aug 2009, 05:00 AM
Hi:
 In this sample Radcombox with checkboxes

How can I select the first option in the codebehind, so Its text can appear in the textbox and its correspondent checkbox is checked.

Thanks in advance.

1 Answer, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 19 Aug 2009, 05:43 AM
Hi,

Try the following code snippet in the ItemDataBound event of the RadComboBox to achieve the desired scenario.

ASPX:
 
  <telerik:RadComboBox ID="RadComboBox2" DataSourceID="SqlDataSource1" EmptyMessage="All Types"  AllowCustomText="true" DataTextField="ProductName" DataValueField="ProductID" runat="server" OnItemDataBound="RadComboBox2_ItemDataBound" OnPreRender="RadComboBox2_PreRender"
                <ItemTemplate> 
                    <asp:CheckBox runat="server" ID="chk1" onclick="onCheckBoxClick(this)" /> 
                    <asp:Label runat="server" ID="Label1" AssociatedControlID="chk1"
                        <asp:Image  runat="server" ID="MyImage" ImageUrl='<%#Eval("Image") %>' /> 
                       <%#Eval("ProductName")%> 
                                 
                    </asp:Label> 
                    
                </ItemTemplate> 
            </telerik:RadComboBox> 

CS:
 
protected void RadComboBox2_ItemDataBound(object sender, RadComboBoxItemEventArgs e) 
    { 
        if (e.Item.Index == 0) 
        { 
            RadComboBoxItem comboItem = (RadComboBoxItem)e.Item; 
            CheckBox chkbx = (CheckBox)comboItem.FindControl("chk1"); 
            chkbx.Checked = true
        } 
        RadComboBox2.SelectedIndex = 0; 
 
    } 


Regards
Princy
Tags
ComboBox
Asked by
iomega 55
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Share this question
or