468,133 Members | 1,609 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,133 developers. It's quick & easy.

Using Bound Drop Down Lists in FormView

Hi,

I have created the Insert Template for my FormView on an aspx page
using asp.net 2.0. Inside this FormView I have some TextBox's and other
elements. One of these elements is a DropDownList which needs to be
populated from fields in a database.

So far I have the DropDownList bound to a function and the code is
simply:

<asp:DropDownList ID="ixFilm" runat="server"
DataSourceID="ObjectDataSource1" DataTextField="strTitle"
DataValueField="ixFilmID" >
</asp:DropDownList>

ObjectDataSource1 is linked to a .vb page which has the code for
selecting the data.

Firstly, how can I Bind the selected option from the DropDownList when
I want to insert data into a database?

Secondly, how can I put in an extra option into this DropDownList which
says "Please Select" ?

code in the .vb file is:

Public Overloads Function GetActiveFilmList() As Generic.List(Of
ActiveFilms)

Using connFilmList As New
SqlConnection(ConfigurationManager.ConnectionStrin gs("VUE_DMS_SQLConnectionString").ConnectionString )
Using cmdFilmList As New
SqlCommand("spCinemas_ListAllActiveFilms", connFilmList)
cmdFilmList.CommandType = CommandType.StoredProcedure
connFilmList.Open()
Dim list As New Generic.List(Of ActiveFilms)
Using drFilmList As SqlDataReader =
cmdFilmList.ExecuteReader()
Do While (drFilmList.Read())
Dim temp As New
ActiveFilms(CInt(drFilmList("ixFilmID")), CStr(drFilmList("strTitle")))
list.Add(temp)
Loop
End Using
Return list
End Using
End Using

End Function

Thanks..

Dec 18 '06 #1
1 1759
'Please Select' is easy - add the item to the DDL's Items collection - then,
change the AppendDataBoundItems property to 'true'
you might check out the following code sample at ASPNet101.com:
http://aspnet101.com/aspnet101/aspne...x?code=dvddlmd

This sample uses a DetailsView, but the process is the pretty much the same

--
David Wier
MVP/ASPInsider
http://aspnet101.com
http://aspexpress.com
"TheDude5B" <ti*******@gmail.comwrote in message
news:11**********************@l12g2000cwl.googlegr oups.com...
Hi,

I have created the Insert Template for my FormView on an aspx page
using asp.net 2.0. Inside this FormView I have some TextBox's and other
elements. One of these elements is a DropDownList which needs to be
populated from fields in a database.

So far I have the DropDownList bound to a function and the code is
simply:

<asp:DropDownList ID="ixFilm" runat="server"
DataSourceID="ObjectDataSource1" DataTextField="strTitle"
DataValueField="ixFilmID" >
</asp:DropDownList>

ObjectDataSource1 is linked to a .vb page which has the code for
selecting the data.

Firstly, how can I Bind the selected option from the DropDownList when
I want to insert data into a database?

Secondly, how can I put in an extra option into this DropDownList which
says "Please Select" ?

code in the .vb file is:

Public Overloads Function GetActiveFilmList() As Generic.List(Of
ActiveFilms)

Using connFilmList As New
SqlConnection(ConfigurationManager.ConnectionStrin gs("VUE_DMS_SQLConnectionS
tring").ConnectionString)
Using cmdFilmList As New
SqlCommand("spCinemas_ListAllActiveFilms", connFilmList)
cmdFilmList.CommandType = CommandType.StoredProcedure
connFilmList.Open()
Dim list As New Generic.List(Of ActiveFilms)
Using drFilmList As SqlDataReader =
cmdFilmList.ExecuteReader()
Do While (drFilmList.Read())
Dim temp As New
ActiveFilms(CInt(drFilmList("ixFilmID")), CStr(drFilmList("strTitle")))
list.Add(temp)
Loop
End Using
Return list
End Using
End Using

End Function

Thanks..

Dec 18 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Miguel Dias Moura | last post: by
1 post views Thread by mimo | last post: by
1 post views Thread by Jamie Oglethorpe | last post: by
27 posts views Thread by didacticone | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.