Replacing TEXTBOX with DROPDOWNLISTBOX in Formview

M

mosscliffe

I have an existing textbox in a formview edit or insert and I wish to
convert it to a DROPDOWNLIST BOX but I can not figure out the syntax
to create the bind that was in the textbox, to how that should be coded
for the DDL

Can anyone please advise

ORIGINAL

<asp:TextBox ID="GenIDTextBox" runat="server" Text='<%# Bind("GenID")
%>'>
</asp:TextBox>

PROPOSED

<asp:DropDownList ID="DropDownList1" runat="server"
DataSourceID="AccessDataSourceTest"
DataTextField="GenName" DataValueField="GenID">
</asp:DropDownList>

<asp:AccessDataSource ID="AccessDataSourceTest" runat="server"
DataFile="~/App_Data/TreesAll.mdb"
SelectCommand="SELECT [GenName], [GenID] FROM [Genus] ORDER BY
[GenName]">
</asp:AccessDataSource>
 
M

mosscliffe

Miracles - never cease.

I think I solved it myself, but any comments or advice would be
appreciated

Solution

Add to the DDL definition the following

SelectedValue='<%# Bind("GenID") %>'

so new DDL is

<asp:DropDownList ID="DropDownList1" runat="server"
DataSourceID="AccessDataSourceTest"
DataTextField="GenName" DataValueField="GenID"
SelectedValue='<%# Bind("GenID") %>' >
</asp:DropDownList>

Tim
 
P

Patrice

Correct. The current value is Text for the TextBox and SelectedValue for the
drop down.. Seems to make sense to me...
 

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
473,774
Messages
2,569,598
Members
45,144
Latest member
KetoBaseReviews
Top