Friday, 23 August 2013

Add values to dropdownlist thats not represented in the db and still get selected value asp.net

Add values to dropdownlist thats not represented in the db and still get
selected value asp.net

I have a couple of dropdownlists in my gridview from customer table that
binds the selected value from my db.
I noticed that if i only have one customer and would like to edit that
customers gender it's not possible because i populate the dropdownlist
with the SELECT DISTINCT Gender FROM Customer and my first customer is
either Herr or Frau and i can only choose from that value.
I was thinking i could solve this Problem using a Union select select
Gender from ( select Gender = 'Herr' union select Gender = 'Frau' )as
Gender to bring both alternatives but then i get this error message
'DropDownList1' has a SelectedValue which is invalid because it does not
exist in the list of items
So my question is how can i add some alternatives to dropdownlist that's
not already presented in DB and still bind the selectedvalue?
<EditItemTemplate>
<asp:DropDownList ID="DropDownList3" runat="server"
DataSourceID="SqlDataSource1" DataTextField="Gender"
DataValueField="Gender" SelectedValue='<%# Bind("Gender")
%>'>
</asp:DropDownList>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$
ConnectionStrings:EventConnectionString %>"
SelectCommand="SELECT DISTINCT [Gender] FROM
[Customer]"></asp:SqlDataSource>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label2" runat="server" Text='<%#
Bind("Gender") %>'></asp:Label>
</ItemTemplate>

No comments:

Post a Comment