Click here to Skip to main content
15,896,439 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi I have a web site in vs 2010 asp.net in my form there are a gridview and a sqldatasource and my code is :
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="employeeid" SortExpression="employeeid">
<EditItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("employeeid") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Bind("employeeid") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="name" SortExpression="name">
<EditItemTemplate>
<asp:TextBox ID="TextBox2" runat="server" Text='<%# Bind("name") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label2" runat="server" Text='<%# Bind("name") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="gender" SortExpression="gender">
<EditItemTemplate>
<asp:DropDownList ID="DropDownList1" runat="server" SelectedValue='<%# Bind("gender") %>'>
<asp:listitem>gender</asp:listitem>
<asp:listitem>male</asp:listitem>
<asp:listitem>female</asp:listitem>
</asp:DropDownList>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label3" runat="server" Text='<%# Bind("gender") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="city" SortExpression="city">
<EditItemTemplate>
<asp:TextBox ID="TextBox4" runat="server" Text='<%# Bind("city") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label4" runat="server" Text='<%# Bind("city") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
Posted
Updated 29-Sep-15 6:33am
v2
Comments
rezaeti 29-Sep-15 12:36pm    
when i click on edit button on gridview following error shown how to solve error?
'DropDownList1' has a SelectedValue which is invalid because it does not exist in the list of items.
Parameter name: value

1 solution

The SelectedValue property's value is not found in your listitem. Suppose you are getting selected value "10" but that is not present in your dropdownlist item. So you are getting exception. Whatever you are putting value as SelectedValue property that must be present in your dropdownlist Item.

Try code like below:
ASP.NET
<asp:dropdownlist id="DropDownList1" runat="server" selectedvalue="<%# Bind("gender") %>" xmlns:asp="#unknown">	
	<asp:listitem text="gender" value="0"></asp:listitem>
	<asp:listitem text="male" value="1"></asp:listitem>
	<asp:listitem text="female" value="2"></asp:listitem>
</asp:dropdownlist>

Here I used value as 0,1,2 - you need to change what ever you are getting from "gender" column data.
 
Share this answer
 
Comments
rezaeti 30-Sep-15 17:13pm    
very very very thanks! I learned from you ManasKumarM

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