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

has a SelectedValue which is invalid because it does not exist in the list of items

3 Answers 288 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
L
Top achievements
Rank 1
L asked on 10 May 2008, 06:51 AM
hi

i have this code that give me this error

dt2 = x.getCompany
drpCompany.DataSource = dt2
drpCompany.DataTextField =
"COM_CompanyName"
drpCompany.DataValueField = "COM_CompanyCode"
drpCompany.SelectedValue = sqlreader("COM_CompanyName").ToString
drpCompany.DataBind()

'drpCompany' has a SelectedValue which is invalid because it does not exist in the list of items.
Parameter name: value


How do I overcome this? Thanks

3 Answers, 1 is accepted

Sort by
0
Veselin Vasilev
Telerik team
answered on 10 May 2008, 07:30 AM
Hi Lui Nai Wah,

I suggest that you call the DataBind() method before setting the SelectedValue:

dt2 = x.getCompany  
drpCompany.DataSource = dt2  
drpCompany.DataTextField = "COM_CompanyName"   
drpCompany.DataValueField = "COM_CompanyCode" 
drpCompany.DataBind()  
drpCompany.SelectedValue = sqlreader("COM_CompanyName").ToString  
 

I hope this helps.

Greetings,
Veskoni
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
L
Top achievements
Rank 1
answered on 10 May 2008, 05:10 PM
hi

Yes, it looks like it does not produce any error but the initial selected value should be from the reader not from the datatable. I ran thru the breakpoint and it indicate that the DataTextField overrides the intial value of the reader.

How should I go about it solving this? Thanks
0
L
Top achievements
Rank 1
answered on 10 May 2008, 05:19 PM
hi

I have solved it. Thanks
Tags
ComboBox
Asked by
L
Top achievements
Rank 1
Answers by
Veselin Vasilev
Telerik team
L
Top achievements
Rank 1
Share this question
or