473,320 Members | 1,814 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

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 1869
'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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Paul Eastabrook | last post by:
Hi, FormView & DetailsView are great controls in the new version of ASP.Net, but I am finding it tricky to display more than the record that either control is bound to at the time. For these...
3
by: Miguel Dias Moura | last post by:
Hello, i have an ASP.NET / VB page where i have a few 4 groups of Drop Down Lists. Each group of Drop Down Lists include 3 Drop Down Lists for date such as: DAY, MONTH, and YEAR. I don't want...
15
by: Swetha | last post by:
Hello I have a DropDownList that I am populating using the following SqlDataSource: <asp:DropDownList ID="parentIDDropDownList" runat="server" DataSourceID="SqlDataSource3"...
3
by: sck10 | last post by:
Hello, I am creating a form for users to enter information about a lab and the members of the lab. I have one form (FormView) that they use to enter information about that lab. The keyvalue is...
1
by: mimo | last post by:
Hi, I'm trying to use Stored Procedures with a Grid View and everytime I try the update and the delete stored procedures fail. By the way I am doing this through the wizard. Is there a...
1
by: Jamie Oglethorpe | last post by:
I have a simple prototype ASP application with a business object wrapping a data set. It contains a single data table. On my UI I have two object data sources; the first has a bound drop down...
7
by: Lorenzino | last post by:
Hi, I have a problem with bindings in a formview. I have a formview; in the insert template i've created a wizard control and inside it i have an HTML table with some textboxes bound to the...
4
by: Larry Bud | last post by:
Main page has a FormView, and within that, is a drop down. A user control is on the page to it like this Dim cc As FormView, dd As DropDownList cc = Parent.FindControl("FormView1") dd =...
3
by: penny111 | last post by:
Hi there, For my application, i need to have 3 drop down lists 1. drop down list of folder names 2. drop down list of documents in the folder selected 3. drop down list of instances of the...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.