Drop Down List in FormView

J

Jeremy Olmstead

Is there a way to convert a TextBox to a DropDownList in a FormView
control? I was able to get the DropDown box to get the "SelectedValue"
in edit mode, but the update fails. No error, it just leaves the value
as it was.

<asp:FormView ID="customerEdit" runat="server" DataKeyNames="CustomerID"
DataSourceID="billingData" DefaultMode="Edit">
<EditItemTemplate>
<table border="0" cellpadding="3" class="pageContent">
<tr>
<td align="right">
Name:</td>
<td>
<asp:TextBox ID="NameTextBox" runat="server" Text='<%# Bind
("Name") %>' Width="164px"></asp:TextBox>
<span class="error">*</span></td>
</tr>
<tr>
<td align="right">
Country:</td>
<td>
<asp:DropDownList ID="countryDrop" runat="server"
SelectedValue='<%# Bind("Country") %>'>
<asp:ListItem Selected="True">United States</asp:ListItem>
<asp:ListItem>Afghanistan</asp:ListItem>
....more items
</asp:DropDownList>
</EditItemTemplate>
</asp:FormView>

<asp:SqlDataSource ID="billingData" runat="server" ConnectionString="<%
$ ConnectionStrings:ConnectionString %>"
ProviderName="<%$ ConnectionStrings:ConnectionString.ProviderName
%>" SelectCommand="SELECT * FROM [Customers] WHERE ([CustomerID] = ?)"
UpdateCommand="UPDATE [Customers] SET [Name] = ?, [CompanyName] = ?,
[Addr1] = ?, [Addr2] = ?, [City] = ?, [State] = ?, [PostalCode] = ?,
[Country] = ?, [Phone] = ?, [Fax] = ? WHERE [CustomerID] = ?">
<SelectParameters>
<asp:SessionParameter DefaultValue="0" Name="CustomerID"
SessionField="customerID"
Type="Int32" />
</SelectParameters>
<UpdateParameters>
<asp:parameter Name="Name" Type="String" />
<asp:parameter Name="CompanyName" Type="String" />
<asp:parameter Name="Addr1" Type="String" />
<asp:parameter Name="Addr2" Type="String" />
<asp:parameter Name="City" Type="String" />
<asp:parameter Name="State" Type="String" />
<asp:parameter Name="PostalCode" Type="String" />
<asp:parameter Name="Country" Type="String" />
<asp:parameter Name="Phone" Type="String" />
<asp:parameter Name="Fax" Type="String" />
<asp:parameter Name="CustomerID" Type="Int32" />
</UpdateParameters>
</asp:SqlDataSource>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,037
Messages
2,570,371
Members
47,013
Latest member
JewellChes

Latest Threads

Top