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

[Solved] Invalid first item

2 Answers 133 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Clive Hoggar
Top achievements
Rank 1
Clive Hoggar asked on 26 Jun 2009, 11:17 AM
Hi

I have implemented a country list using an sql datasource of countries for text and abbreviations
for values, but I would like to have a default initial item "-- select country -- "  which creates a
validation failure using standard 'required field validator' for example.

This seems to be a common requirement but I did not find a simple solution in the docs.
I mus be missing something. What is the best way to do this?

I tried adding an item in the database table with an empty string for the abbreviation but this
did not seem to cause validation to fail if no selection was made.

Thanks as ever for you help

Clive

2 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 26 Jun 2009, 12:02 PM
Hello Clive,

Set the InitialValue property of RequireFiledValidator to the text  "-- select country -- " in order to exclude from validating as an item. See the example.

ASPX:
 
<telerik:RadComboBox ID="RadComboBox1" runat="server" AllowCustomText="true" Text="-- select country --" 
    DataSourceID="SqlDataSource1" DataTextField="CompanyName"
</telerik:RadComboBox> 
<br /> 
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="RadComboBox1" 
    ErrorMessage="RequiredFieldValidator" InitialValue="-- select country --"
</asp:RequiredFieldValidator> 

Thanks,
Shinu
0
Clive Hoggar
Top achievements
Rank 1
answered on 26 Jun 2009, 03:18 PM
Thanks. It works fine. I just knew it would be elegant.
Clive
Tags
ComboBox
Asked by
Clive Hoggar
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Clive Hoggar
Top achievements
Rank 1
Share this question
or