‘DropDownList1’ has a SelectedValue which is invalid because it

Usually when you try to  use DropDown Control in GridView Control there are certain things you have be careful about.

You can configure DropDownList in GridView for update any column value. To do that you can follow the step by step


But when you are trying to fill the DropDownList with datasource which does not have values in GridView’s column to which you want to bind then you will usually get the Error “Selected value whic is invalid….” because GridView trying to assign or select the value from DropDownList but in dropdownlist’s datasource there is nothing such record.

For instance.. you are trying to bind the “country” column from employee table. and you bind Dropdownlist from another table with list of continents. In that case if one of the row have country value which is not in dropdownlist it will throw the Error “select value which is invalid..”.

So, when ever you try to use dropdownlist within the Templated Column in GridView just make sure that the all possible values of the column should be in Dropdownlist.

code to bind the Dropdownlist in Template column
<asp:TemplateField HeaderText=”buyer_country” SortExpression=”buyer_country”>
<asp:Label runat=”server” Text='<%# Bind(“buyer_country”) %>’ ID=”Label1″></asp:Label>
<asp:DropDownList ID=”DropDownList1″ runat=”server”
AppendDataBoundItems=”true” DataSourceID=”LinqDataSource2″
DataTextField=”car_model” DataValueField=”car_model” SelectedValue='<%# Bind(“buyer_country”) %>’>
<asp:HiddenField ID=”HiddenField1″ runat=”server” />

<asp:LinqDataSource ID=”LinqDataSource2″ runat=”server”
TableName=”car_cars” Select=”new (car_make, car_model)”>

Here you can see the DropDownList is binded with buyer_contry of other datasource but datasourceId is LinqDatasource2. DropDownList Datasource should contains all possible values of “buyer_country” data.


hi there, I am software engineer, working in e-commerce company and passionate about all thing digital. On this blog, I share my experiments with different technology.

Posted in SQL Server

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

What people say about post?
seo hizmeti on Awesome wordpress ecommerce…

Enter your email address to subscribe to this blog and receive notifications of new posts by email.

Join 39 other followers

%d bloggers like this: