How to reset the SelectedIndex of a Combobox with an ItemTemplate?

2 posts, 0 answers
  1. toddhd
    toddhd avatar
    21 posts
    Member since:
    Aug 2006

    Posted 16 Feb 2011 Link to this post

    I have a RadComboBox with an ItemTemplate for checkboxes, like this:

        <label class="labelBlack" for="ReportType">
            Report Type</label>
        <telerik:RadComboBox ID="cmbReportType" Name="ReportType" runat="server" DataTextField="Value" DataValueField="Key" TabIndex="17" Width="214"
             MarkFirstMatch="true" AllowCustomText="false" OnClientLoad="OnReportTypeLoad" OnClientDropDownClosing="OnReportTypeDropDownClosing">
                <asp:CheckBox runat="server" ID="chkReportType" Text='<%# Eval("Value")%>'/>
                <asp:HiddenField runat="server" ID="ReportTypeID" Value='<%# Eval("Key") %>' />
    This is part of a "Search" form, and I have a Submit and Clear button on the page. When Clear is clicked, I need to set the index back to the first item in the list. On ComboBoxes that do not use an ItemTemplate, I can just do this (in code behind):
    cmbReportType.SelectedIndex = 0;
    And that works. But it doesn't work when the ItemTemplate is present. I also tried:
    cmbReportType.Items[0].Selected = true;
    Still, no luck. Any thoughts on this?

  2. Helen
    Helen avatar
    1052 posts

    Posted 18 Feb 2011 Link to this post

    Hi Todd,

    The following code works at our side:
    <telerik:RadComboBox ID="cmbReportType" Name="ReportType" runat="server" TabIndex="17" Width="214"
     MarkFirstMatch="true" AllowCustomText="false">
        <asp:CheckBox runat="server" ID="chkReportType" Text='CheckBox>'/>
        <asp:HiddenField runat="server" ID="ReportTypeID" Value='Hidden' />
    <asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Clear" />

    protected void Page_Load(object sender, EventArgs e)
            if (!Page.IsPostBack)
                string path = "combobox.xml";
                StreamReader sr = new StreamReader(Server.MapPath(path));
                //load items from XML string
    protected void Button1_Click(object sender, EventArgs e)
        cmbReportType.SelectedIndex = 0;

    the Telerik team
Back to Top