 |
| ASP.NET 1.1 As of 10/6/2005, this forum is locked as part of the reorganization described here: http://p2p.wrox.com/topic.asp?TOPIC_ID=35394. No posts have been deleted. Open ongoing discussions from the last week have been moved to either ASP.NET 1.0 and 1.1 Beginners http://p2p.wrox.com/asp-net-1-0-1-1-basics-60/ or ASP.NET 1.0 and 1.1 Professional. http://p2p.wrox.com/forum.asp?FORUM_ID=50. See my sticky post inside for more. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the ASP.NET 1.1 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
|
|
|
|

February 18th, 2004, 06:44 PM
|
|
Authorized User
|
|
Join Date: Jan 2004
Posts: 66
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Database driven drop down list box
Hi,
I am trying to populate a dropdown list box with values from a database. The code which searches the database appears to work, but i cant get it bound to list box on the aspx.page
here is the code for searching the database and attempting to bind it to the dropdown list box:
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim sql_comp_str As String
sql_comp_str = "SELECT CODES.CDE_BUS_VALUE_TXT FROM CODES WHERE (((CODES.CDE_CD_ATTRIB_ID)=8)) ORDER BY CODES.CDE_CMN_CLCTN_CD;"
'open the database
Dim ConnStr As String = "Provider=Microsoft.Jet.OLEDB.4.0;" & "User ID=Admin;" & "Data Source=C:\Inetpub\wwwroot\CompModel\Database\Dev\C ompModel.mdb"
Dim DbConn As System.Data.OleDb.OleDbConnection = New System.Data.OleDb.OleDbConnection(ConnStr)
Dim DDSearch As System.Data.OleDb.OleDbCommand
DbConn.Open()
DDSearch = New System.Data.OleDb.OleDbCommand(sql_comp_str, DbConn)
ddCompType.DataSource = DDSearch.ExecuteReader()
ddCompType.DataBind()
DbConn.Close()
End Sub
Here is the code for the dropdown ox on the aspx page:
<asp:DropDownList ID="ddCompType" Runat="server" Width="134px"></asp:DropDownList>
Imaginative, eh?!
I am probably missing something really simple at the moment, but I am new to .Net development and cant see where the problem is.
Thanks
|
|

February 18th, 2004, 10:13 PM
|
 |
Friend of Wrox
|
|
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
|
|
It looks like you are doing everything that you need except for setting the value and text fields:
ddCompType.DataValueField = "CDE_BUS_VALUE_TXT"
ddCompType.DataTextField = "CDE_BUS_VALUE_TXT"
Peter
------------------------------------------------------
Work smarter, not harder.
|
|

February 19th, 2004, 08:03 AM
|
|
Authorized User
|
|
Join Date: Jan 2004
Posts: 66
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Thanks, that worked!
Cheers
Morris
|
|

February 27th, 2004, 02:13 PM
|
|
Authorized User
|
|
Join Date: Jan 2004
Posts: 66
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
hello all - got another problem with this topic!
Taking the code and corrections suggested above (which worked perfectly) I got that drop down menu working. With my new found confidence of using dropdown menus :D, I wanted to implement another list.
However, instead of getting multiple values I am only getting one returned and placed into the list box. Below is the code which i am using for this:
'get the dates
Dim sql_comp_dt As String
Dim emp_id As String
'create the sql string
sql_comp_dt = "SELECT DISTINCT EMP_EVALUATION.EEV_EVALUATION_DT FROM EMP_EVALUATION WHERE (((EMP_EVALUATION.EEV_EMPLOYEE_ID)=" & emp_id & "));"
'opening the database, running the query and passing it to the database
Dim ConnStr As String = "Provider=Microsoft.Jet.OLEDB.4.0;" & "User ID=Admin;" & "Data Source=C:\Inetpub\wwwroot\CompModel\Database\Dev\C ompModel.mdb"
Dim DbConn As System.Data.OleDb.OleDbConnection = New System.Data.OleDb.OleDbConnection(ConnStr)
Dim DDdateSearch As System.Data.OleDb.OleDbCommand
DbConn.Open()
DDdateSearch = New System.Data.OleDb.OleDbCommand(sql_comp_dt, DbConn)
ddDates.DataSource = DDdateSearch.ExecuteReader()
'bind the data to the database
ddDates.DataValueField = "EEV_EVALUATION_DT"
ddDates.DataTextField = "EEV_EVALUATION_DT"
ddDates.DataBind()
DbConn.Close()
When I run this against the database directly, the get 5 indivdual dates, but when I run through the web interface, I am only getting one. Cant figure this one out, esp considering I am using the code and improvements in the suggestions above.
If anyone could shed some light on this and point a frustrated newbie in the right direction, it would be much appreciated!!
Morris
|
|

April 1st, 2004, 03:23 PM
|
|
Authorized User
|
|
Join Date: Jan 2004
Posts: 66
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
hi, how are you all?
I hate to revive an old topic, but i was wondering if anyone could answer either of these questions?
1: i have two separate fields in my database for first name and last name. Is it possible to display both first name and last name in a drop down list so the choices look like this: "An Other"?
2: How can I make SelectedIndexChanged functions work in a a list which gets the information in the list fromthe database? I have tried to using selectedIndex = "" but that only results in an error. Any ideas?
thanks in advance,
Morris
|
|

April 3rd, 2004, 05:44 PM
|
 |
Friend of Wrox
|
|
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
|
|
Usually when I need to merge fields I do it in the query:
SELECT FirstName+' '+LastName FROM table...
or
SELECT LastName+', '+FirstName FROM table...
Not sure what you mean with the second question.
Peter
------------------------------------------------------
Work smarter, not harder.
|
|

April 3rd, 2004, 07:56 PM
|
|
Authorized User
|
|
Join Date: Jan 2004
Posts: 66
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
hi there,
thanks for your help on the first problem, ill give that a go and see if I can make it work.
As for the second problem, maybe i have a made a simple error in my code. I have, as you know, a series of drop down lists which get info from the database. However, to activate these, I have had to place a button beside these for the click on to take them to the next stage of te process.
I cant, at the moment, get the function SelectedIndexChanged() to work when the user has selected an item from the list. I would like the user to be able to select something from the list and then for the system to take them onto the next without having to click a button.
Is this possible to do with drop down list which is set up the way i have it? When i put in a selectedindex attribute such as selectedIndex="" vs.net returns an error. Is there another way of setting the selectedindex to a default value so when the user selects an option from it, execute a function?
Hope that makes more sense,
Morris
P.S: Once again, thanks for all yor help
|
|

April 3rd, 2004, 08:09 PM
|
 |
Friend of Wrox
|
|
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
|
|
I see what you mean now... this is easy. You have to turn on the AutoPostBack feature of the dropdown list. This results in ASP.net writing out a page post action in the HTML "select" element's onChange client-side event. You don't need to do anything special aside from putting AutoPostback="true" in the markup for the dropdownlist.
|
|

April 3rd, 2004, 08:16 PM
|
|
Authorized User
|
|
Join Date: Jan 2004
Posts: 66
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Hi,
thanks for all of your help, it is really appreciated!
Morris
|
|
 |