By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,148 Members | 779 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,148 IT Pros & Developers. It's quick & easy.

How bind Listbox or DropDownlist

P: n/a
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
Dec 14 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
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

"Patrik Zdarsa" <pa****@go-on.cz> wrote in message
news:uf*************@TK2MSFTNGP10.phx.gbl...
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

Dec 14 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.