Initial values for multicolumn combobox (to force select).

2 posts, 0 answers
  1. JD.
    JD. avatar
    37 posts
    Member since:
    Aug 2012

    Posted 17 Jun 2012 Link to this post


    I find combobox little complex in its usage.     This is what i wish to do while using it inside grid control , I am using form template (in grid)...

    1. I want combo to display intital value as "select"   (to force user to select dropdown)
    2. if user does not select it should show error message.  
    3. Above should also be true when user resets this choice back to "select" (initial value)
    4. Since this is multicolumn using template,   it should display 1st row as "select" in all columns available in multicolumn
        or atleast in 1st column.

    I tried doing above but failed on point #2 and Point #4.  

    <telerik:RadComboBox Width="250px" HighlightTemplatedItems="true"
                        runat="server"   ID="cbCurrencyCode" AppendDataBoundItems="True"
                        SelectedValue='<%# Bind("FKCurrencyCode") %>'
                        onitemdatabound="cbCurrencyCode_ItemDataBound"  >
              <telerik:RadComboBoxItem runat="server" Text="- Select -" Value="- Select -" />
                    <li class="col1">Code</li>
                    <li class="col2">Name</li>
                    <li class="col1">
                        <%# DataBinder.Eval(Container.DataItem, "CurrencyCode")%></li>
                    <li class="col2">
                        <%# DataBinder.Eval(Container.DataItem, "CurrencyName")%></li>
                    <br />
      <asp:RequiredFieldValidator runat="server" ID="RequiredFieldValidator2" ControlToValidate="cbCurrencyCode"
    InitialValue="- Select -" ErrorMessage="Please select." ValidationGroup="SearchFormValidationGroup"
    CssClass="validator" />

    protected void cbCurrencyCode_ItemDataBound(object sender, Telerik.Web.UI.RadComboBoxItemEventArgs e)
             e.Item.Text = ((DAL.MasterCurrency)e.Item.DataItem).CurrencyCode;
             e.Item.Value = ((DAL.MasterCurrency)e.Item.DataItem).CurrencyCode;

    a. I also had to write above code, which i feel is unnecessary and there should be a better approach.
    b. Form do get submitted, without doing any selection.  validationcontrol should have stopped, but it did not.
    c. first row in the multicolumn list remains blank.  I want that it should display 'Select' and its value also should be "Select" so that validation can stop form submit.

    I hope i was able to explain.  Any advice?


  2. Peter
    Peter avatar
    6637 posts

    Posted 18 Jun 2012 Link to this post

    Hello J.D.,

    I recommend you use the EmptyMessage property for this case:
    <asp:button runat="server" text="Button" validationgroup="SearchFormValidationGroup" />
       <telerik:RadComboBox ID="cbCurrencyCode" runat="server" EmptyMessage="select" ValidationGroup="SearchFormValidationGroup">
               <telerik:RadComboBoxItem runat="server" Text="RadComboBoxItem1" Value="RadComboBoxItem1" />
               <telerik:RadComboBoxItem runat="server" Text="RadComboBoxItem2" Value="RadComboBoxItem2" />
               <telerik:RadComboBoxItem runat="server" Text="RadComboBoxItem3" Value="RadComboBoxItem3" />
       <asp:requiredfieldvalidator runat="server" id="RequiredFieldValidator2" controltovalidate="cbCurrencyCode"
           errormessage="Please select." validationgroup="SearchFormValidationGroup" cssclass="validator" />

    Note also that this setting has been removed from the required field validator control -
    initialvalue="- Select -"

    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
  3. Telerik UI for ASP.NET Core is out
Back to Top