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

Initial values for multicolumn combobox (to force select).

1 Answer 89 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
JD.
Top achievements
Rank 1
JD. asked on 18 Jun 2012, 01:56 AM
Hi,

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"
                    DataSourceID="EntityDataSource2"
                    SelectedValue='<%# Bind("FKCurrencyCode") %>'
                    onitemdatabound="cbCurrencyCode_ItemDataBound"  >
      <Items>
          <telerik:RadComboBoxItem runat="server" Text="- Select -" Value="- Select -" />
      </Items>
     <HeaderTemplate>
            <ul>
                <li class="col1">Code</li>
                <li class="col2">Name</li>
            </ul>
        </HeaderTemplate>
        <ItemTemplate>
            <ul>
                <li class="col1">
                    <%# DataBinder.Eval(Container.DataItem, "CurrencyCode")%></li>
                <li class="col2">
                    <%# DataBinder.Eval(Container.DataItem, "CurrencyName")%></li>
            </ul>
        </ItemTemplate>
                </telerik:RadComboBox>
  
                <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;
         //((DataRowView)e.Item.DataItem)["CurrencyCode"].ToString();
         e.Item.Value = ((DAL.MasterCurrency)e.Item.DataItem).CurrencyCode;
         //((DataRowView)e.Item.DataItem)["CurrencyCode"].ToString();
     }


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?

Regards












1 Answer, 1 is accepted

Sort by
0
Peter
Telerik team
answered on 18 Jun 2012, 12:44 PM
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">
       <Items>
           <telerik:RadComboBoxItem runat="server" Text="RadComboBoxItem1" Value="RadComboBoxItem1" />
           <telerik:RadComboBoxItem runat="server" Text="RadComboBoxItem2" Value="RadComboBoxItem2" />
           <telerik:RadComboBoxItem runat="server" Text="RadComboBoxItem3" Value="RadComboBoxItem3" />
       </Items>
   </telerik:RadComboBox>
   <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 -"
 

Greetings,
Peter
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.
Tags
ComboBox
Asked by
JD.
Top achievements
Rank 1
Answers by
Peter
Telerik team
Share this question
or