472,789 Members | 1,054 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,789 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 1854
'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
by: Rina0 | last post by:
Cybersecurity engineering is a specialized field that focuses on the design, development, and implementation of systems, processes, and technologies that protect against cyber threats and...
0
by: kcodez | last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
14
DJRhino1175
by: DJRhino1175 | last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this - If...
0
by: Rina0 | last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
5
by: DJRhino | last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer) If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _ 310030356 Or 310030359 Or 310030362 Or...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
by: lllomh | last post by:
How does React native implement an English player?
0
by: Mushico | last post by:
How to calculate date of retirement from date of birth
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...

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.