Last post Dec 06, 2016 12:58 PM by march11
Sep 27, 2016 01:51 PM|Shuklaji123|LINK
I don't understand what's wrong with this piece of code,
<asp:TemplateField HeaderText="EmpGender" SortExpression="EmpGender">
<asp:DropDownList ID="DropDownList1" runat="server" selectedvalue='<%# Bind("EmpGender") %>'>
<asp:ListItem Text="Select Gender" Value="Select Gender"></asp:ListItem>
repeatedly getting this error
Sep 27, 2016 03:03 PM|march11|LINK
Because you appear to have values coming from both a database and those you have entered as list items on the control.
Go to the control properties and set this value AppendDataBoundItems="True"
This should allow both values to be reported. But this logic seems flawed, you may need to rethink what you are trying to do with Male/Female drop down. Kind of a Boolean field if you care to code it that way. Because its more acceptable for gender to change
in todays' society you may need to consider a selection, but generally it will not.
Sep 27, 2016 03:30 PM|oned_gk|LINK
Ensure that EmpGender always have Male or Female value, not null, blank or other value
Sep 27, 2016 03:56 PM|march11|LINK
You could also try and set a default gender, just as a quick fix until you decide how you want to solve this. so lets say most of the time the gender will be male....
<asp:ListItem Text="Select Gender" Value="Male"></asp:ListItem>
this way the code will see a valid value since Male is in the list.
Sep 28, 2016 07:29 AM|Nan Yu|LINK
The value coming from <%# Bind("EmpGender") %>, which is passed to the SelectedValue property, does not match an item in its collection. Most likely causes: 1.DropDownList has no items because the evaluation happens before the list gets
bound;2.The list is bound but is missing this particular value 3.The value returned could be null . You could try to add value property to male/female list item . Then debug your application to check what is the "EmpGender" value .
Sep 28, 2016 08:17 AM|Shuklaji123|LINK
AppendDataBoundItems simply don't work...Yes, there are three items in the Collection also, Select Gender, Male and Female... Cannot get any best solution. Plesae suggest any other ...Thanks
Sep 28, 2016 04:23 PM|march11|LINK
You need to find out what is coming back from the database.
Your ASP code shows the status of the template field in Edit mode. Do you open gridview in Edit mode or does the DDL open in Insert or item template? You will need to change those setting in each template if you have added the Dropdown list box to each
Dec 01, 2016 01:27 PM|Shuklaji123|LINK
Thanks so much for the reply, will let you soon..
Dec 05, 2016 05:20 PM|march11|LINK
You should select the answer that best help you solve your question, not your own response.
Dec 06, 2016 06:03 AM|Shuklaji123|LINK
ok, thanks for guiding me
Dec 06, 2016 12:58 PM|march11|LINK
You can do so by selecting Mark As Answer at the top of any of the posts. You can select more than one post as the answer.