Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Basics
|
ASP.NET 2.0 Basics If you are new to ASP or ASP.NET programming with version 2.0, this is the forum to begin asking questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 2nd, 2006, 06:48 PM
Authorized User
 
Join Date: Jan 2006
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default Multiple Databound controls for one database field

I would like to know how to insert data from multiple data controls into one column in a database.

An example of the data to be inserted would be a project number as such: SP-2006-01

I would like to use 2 DropDownList controls for the possible values such as SP and 2006. In addition, I would like to allow the user to type the last bit of information 01 into a textbox control.

Currently I am using a single text box for this data. I want more control over what possible values the user is allowed to input.

In essence:
DropDownList1 + "-" + DropDownList2 + "-" + TextBox1 = P_NUM (SP-2006-01)

Thanks!

 
Old March 3rd, 2006, 04:03 PM
Friend of Wrox
 
Join Date: Nov 2003
Posts: 1,348
Thanks: 0
Thanked 5 Times in 5 Posts
Default

You have the idea.

DropDownList1.SelectedValue + "-" + DropDownList2.SelectedValue + "-" + TextBox1.Text

Jim

 
Old March 6th, 2006, 03:23 PM
Authorized User
 
Join Date: Jan 2006
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default

That looks like is should work; however when I type the DropDownList1.Selected, the Intellisense tells me 'DropDownList1 is not defined.' I don't understand? I went to the Properties box for the control, and copy/pasted the name from the ID column.

This control is embedded in the 'Insert' template of a 'FormView' web contol. Do I need to reference the control in a particular fashion since it is in the template?

 
Old March 6th, 2006, 03:44 PM
Friend of Wrox
 
Join Date: Nov 2003
Posts: 1,348
Thanks: 0
Thanked 5 Times in 5 Posts
Default

Yes you need to refernce it differently, EX:
dim ddl1 as new dropdownlist
ddl1 = FormView1.FindControl("DropDownList1")

Then use ddl1 in your string.

ddl1.SelectedValue + .....

 
Old March 9th, 2006, 05:20 PM
Authorized User
 
Join Date: Jan 2006
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks, that works great!

 
Old March 10th, 2006, 12:47 AM
Friend of Wrox
 
Join Date: Nov 2003
Posts: 1,348
Thanks: 0
Thanked 5 Times in 5 Posts
Default

Glad to help.. :) glad you got it working

Jim

 
Old March 29th, 2006, 06:33 PM
Authorized User
 
Join Date: Jan 2006
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I have noticed that this code creates two entries in the database. I believe it is because there are actually two Inserts taking place.

The first occurs when this code is run:

    Sub InsertPROJECTNUMBER()

        Dim ProjectNumber_Param As String
        Dim TYPEPROJECTNUMBERDropDownList As New DropDownList
        Dim YEARPROJECTNUMBERDropDownList As New DropDownList
        Dim NUMPROJECTUMBERTextBox As New TextBox

        TYPEPROJECTNUMBERDropDownList = FormView1.FindControl("TYPEPROJECTNUMBERDropDownLi st")
        YEARPROJECTNUMBERDropDownList = FormView1.FindControl("YEARPROJECTNUMBERDropDownLi st")
        NUMPROJECTUMBERTextBox = FormView1.FindControl("NUMPROJECTUMBERTextBox")

        ProjectNumber_Param = TYPEPROJECTNUMBERDropDownList.SelectedValue + "-" + YEARPROJECTNUMBERDropDownList.SelectedValue + "-" + NUMPROJECTUMBERTextBox.Text

        SqlDataSource1.InsertParameters("PROJECTNUMBER").D efaultValue = ProjectNumber_Param
        SqlDataSource1.Insert()

    End Sub

The second is when the 'Insert' LinkButton's click event is fired on the FormView control. This is used to insert the remaining information from the other databound controls of the FormView into the database.

This creates a double entry into the database. How would I go about setting the InsertParameter("ProjectName") equal to the same value that it would have had if I had kept the original databind for the original PROJECTNUMBERTextbox on the FormView?






Similar Threads
Thread Thread Starter Forum Replies Last Post
Field References in User Controls Ron Howerton ASP.NET 2.0 Basics 2 April 19th, 2007 10:04 AM
multiple constructors for custom controls three BOOK: Professional Web Parts and Custom Controls ASP.NET ISBN: 0-7645-7860-X 0 May 1st, 2006 03:24 PM
databound grids with html controls inside badgolfer ASP.NET 1.0 and 1.1 Basics 1 September 25th, 2004 12:14 PM
Adding multiple form field values to database cdenequolo Classic ASP Basics 1 August 17th, 2004 05:38 PM
Multiple controls - grouped william.murray Access 2 August 4th, 2004 04:07 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.