Click here to Skip to main content
15,907,906 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
So i have question i have dropdownlist in Gridview soo first i need to pass it nothing if someon edit it and gave him value it will update here is code snippet
<asp:DropDownList runat="server" ID="compn" CssClass="Dropdowni" SelectedValue='<%# Bind("Company_ID") %>'
                            DataSourceID="ObjectDataSource5" DataTextField="Name_Ge" 
            DataValueField="Code5" Enabled="false"

'compn' has a SelectedValue which is invalid because it does not exist in the list of items.
Parameter name: value
here is the error what it is giving mee

What I have tried:

<asp:ListItem Text="Select One" Value=""></asp:ListItem>

here is what i have tried but when i go on a edit it is showing me only select one in db i have some records
Updated 6-Mar-16 20:49pm

1 solution

You need to remove the ``SelectedValue`` property from the initial load.
Remove following-
SelectedValue='<%# Bind("Company_ID") %>'

The modified code should looks something like-
<asp:dropdownlist runat="server" id="compn" cssclass="Dropdowni" datasourceid="ObjectDataSource5" datatextfield="Name_Ge" datavaluefield="Code5" enabled="false" xmlns:asp="#unknown">

Now, if you want something to be selected, you can always do that in code behind.

Hope, it helps :)
Please let me know if you need further guidance on this.
Share this answer
GTR0123 7-Mar-16 3:14am    
Somehow it doesn't work for me :/
Suvendu Shekhar Giri 7-Mar-16 3:25am    
Can you post details of what error came this time?
GTR0123 7-Mar-16 3:28am    
sry sry my mistakee :D now i make it thnx for help

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