Click here to Skip to main content
15,893,663 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi,

I'm getting an error with this one that says:

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

I'm quite sure that my DataValueField is correct.

C#
locList.DataSource = ds;
locList.DataTextField = Property.NameColumn;
locList.DataValueField = Property.IdColumn;
locList.DataBind();
Posted

C#
locList.DataSource = ds.Tables[0];//assign table not dataset
    locList.DataTextField = Property.NameColumn;//make sure you have write column names properly
    locList.DataValueField = Property.IdColumn;
    locList.DataBind();

Happy Coding!
:)
 
Share this answer
 
Comments
akosidab 16-Apr-13 0:45am    
It's not working.
Aarti Meswania 16-Apr-13 0:45am    
are you using web-application?
akosidab 16-Apr-13 3:58am    
yes
use following


C#
if (!IsPostBack)
          {

        locList.DataSource = ds.Tables[0];
	locList.DataTextField = Property.NameColumn;
	locList.DataValueField = Property.IdColumn;
	locList.DataBind();

          }
 
Share this answer
 
Comments
akosidab 16-Apr-13 0:45am    
It's not working.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900