How bind Listbox or DropDownlist

P

Patrik Zdarsa

Hi,
I'm try VS 2005 and need UPDATE database record in viewform, all working
when every filed is type TextBox (html INPUT) but I need change one TextBox
to Listbox or dropdownlist and read data from another table and store it in
table1 in parameter "stav". Load data to ListBox is not problem but when I
try update record there is error "stav is null", is any way how to bind
listbox or dropdownlist.

Code:
<UpdateParameters>
<asp:parameter Name="puvod" Type="String" />
<asp:parameter Name="stav" Type="String" />
</UpdateParameters>

<asp:TextBox ID="puvodTextBox" runat="server" Text='<%# Bind("puvod")
%>'></asp:TextBox><br />
<asp:dropdownlist ID="stavListbox" runat="server"
DataSourceID="SqlDataSource2" DataTextField="rolename"
DataValueField="rolename"></asp:dropdownlist>

thank you
Patrik
 
R

RCS

The easiest way is to use the wizard to do this, but from the code below,
the only thing you are missing is, you need to bind the dropdownlist
selectedvalue to your Update command. So make this change:

<asp:dropdownlist ID="stavListbox" runat="server"
DataSourceID="SqlDataSource2" DataTextField="rolename"
DataValueField="rolename"
SelectedValue='<%#Bind("stav")%>'></asp:dropdownlist>

This isn't tested, but I believe that should work.. HTH
 

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

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,051
Latest member
CarleyMcCr

Latest Threads

Top