If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > ASP > qns abt selected value in ddl

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 01-15-06, 03:34
Cuttie0506 Cuttie0506 is offline
Registered User
 
Join Date: Jan 2006
Posts: 44
qns abt selected value in ddl

Hi all, i'm new to asp.. and i have sum qns too ask from u guys...

i have search for tis ans for quite sum times.. it may sounds abit easy for u guys but really hope sum1 cld help mi...

I have 2 tables, 1 table is to contain de data tt can be used to display de options in ddl.. For example, in tis ddl, i ave Cat and Dog.

I have selected dog and info is stored in another table..
I want to retrieve tis dog info out and display in a ddl.
For de ddl, as usual, i used de 1st table to display all de data and use another table to display de selected value..

But at tis pt of time, i only noe how to display de items in ddl, but nt de selected value... i have did tis in asp.net, and it seems abit diff from tt...
Appreciate alot if sum1 cld help mi solve tis.. thanx!!!

Code:
<%
Catgeory refers to the info tt was saved previously(1 of de option in de catagory. For example, in Catgeory ddl, there's 2 options, Cat and Dog. Catgeory here refers to mayb, dog.

Set rs_vEmail = Server.CreateObject("ADODB.Recordset")
rs_vEmail.ActiveConnection = MM_dsprms_STRING
rs_vEmail.Source = "SELECT ID, Name, Email_Add, Category FROM Email_Address"
rs_vEmail.CursorType = 0
rs_vEmail.CursorLocation = 2
rs_vEmail.LockType = 1
rs_vEmail.Open()

TheArray = rs_vEmail.GetRows

'This is to get the data from the db to display de items in the ddl. E.G, Dog and Cat 

Dim rs_vCategory 'recordset to capture category from category table

Set rs_vCategory = Server.CreateObject("ADODB.Recordset")
rs_vCategory.ActiveConnection = MM_dsprms_STRING
rs_vCategory.Source = "SELECT category FROM Category"
rs_vCategory.CursorType = 0
rs_vCategory.CursorLocation = 2
rs_vCategory.LockType = 1
rs_vCategory.Open()
%>

' This is to display de items in de ddl. But how do i select (display) de items tt i retrieve from the db?

<html>

<td><select name="category" id="select">

<%
While (NOT rs_vCategory.EOF)
%>
					

<option value="<%=(rs_vCategory.Fields.Item("category").Value)%>"><%=(rs_vCategory.Fields.Item("category").Value)%></option>

<%
rs_vCategory.MoveNext()

Wend

If (rs_vCategory.CursorType > 0) Then
	rs_vCategory.MoveFirst

Else
	rs_vCategory.Requery
End If

</html>

Last edited by Cuttie0506; 01-15-06 at 03:38.
Reply With Quote
  #2 (permalink)  
Old 01-15-06, 20:25
Bullschmidt Bullschmidt is offline
Guru
 
Join Date: Jun 2003
Location: USA
Posts: 1,032
Don't know but perhaps this may hopefully give you some ideas:

Classic ASP Design Tips - QueryString
http://www.bullschmidt.com/devtip-querystring.asp
__________________
J. Paul Schmidt, Freelance Web and Database Developer
www.Bullschmidt.com
Access Database Sample, Web Database Sample, ASP Design Tips
Reply With Quote
  #3 (permalink)  
Old 01-15-06, 23:08
fredservillon fredservillon is offline
Registered User
 
Join Date: Oct 2005
Posts: 178
Wink

Quote:
Originally Posted by Cuttie0506
Hi all, i'm new to asp.. and i have sum qns too ask from u guys...

i have search for tis ans for quite sum times.. it may sounds abit easy for u guys but really hope sum1 cld help mi...

I have 2 tables, 1 table is to contain de data tt can be used to display de options in ddl.. For example, in tis ddl, i ave Cat and Dog.

I have selected dog and info is stored in another table..
I want to retrieve tis dog info out and display in a ddl.
For de ddl, as usual, i used de 1st table to display all de data and use another table to display de selected value..

But at tis pt of time, i only noe how to display de items in ddl, but nt de selected value... i have did tis in asp.net, and it seems abit diff from tt...
Appreciate alot if sum1 cld help mi solve tis.. thanx!!!

Code:
<%
Catgeory refers to the info tt was saved previously(1 of de option in de catagory. For example, in Catgeory ddl, there's 2 options, Cat and Dog. Catgeory here refers to mayb, dog.

Set rs_vEmail = Server.CreateObject("ADODB.Recordset")
rs_vEmail.ActiveConnection = MM_dsprms_STRING
rs_vEmail.Source = "SELECT ID, Name, Email_Add, Category FROM Email_Address"
rs_vEmail.CursorType = 0
rs_vEmail.CursorLocation = 2
rs_vEmail.LockType = 1
rs_vEmail.Open()

TheArray = rs_vEmail.GetRows

'This is to get the data from the db to display de items in the ddl. E.G, Dog and Cat 

Dim rs_vCategory 'recordset to capture category from category table

Set rs_vCategory = Server.CreateObject("ADODB.Recordset")
rs_vCategory.ActiveConnection = MM_dsprms_STRING
rs_vCategory.Source = "SELECT category FROM Category"
rs_vCategory.CursorType = 0
rs_vCategory.CursorLocation = 2
rs_vCategory.LockType = 1
rs_vCategory.Open()
%>

' This is to display de items in de ddl. But how do i select (display) de items tt i retrieve from the db?

<html>

<td><select name="category" id="select">

<%
While (NOT rs_vCategory.EOF)
%>
					

<option value="<%=(rs_vCategory.Fields.Item("category").Value)%>"><%=(rs_vCategory.Fields.Item("category").Value)%></option>

<%
rs_vCategory.MoveNext()

Wend

If (rs_vCategory.CursorType > 0) Then
	rs_vCategory.MoveFirst

Else
	rs_vCategory.Requery
End If

</html>

Use the SELECTED method for Select statement. SInce your option selection is dynamic use a function that insert the word SELECTED when the correct record is retireve for listing and blank out if the record is not to be selected.
There are ways to expand the use of properties that are not mentioned in any tutorial book, you'll just have to experiement with it by using your programming skill logics.

YOu need a condition Text function here..(inserted StrSELECTED() )

<option value="<%=(rs_vCategory.Fields.Item("category").Va lue)%>" <%= StrSELECTED() %> ><%=(rs_vCategory.Fields.Item("category").Value)%> </option>


Where StrSELECTED is a string function to call and you have to create the condition
for example

<Script language="VBScript">
Function StrSELECTED
IF
'Place your condition here like if this record is matching the other table record selected ' then
StrSELECTED = "SELECTED"
else
StrSELECTED = ""
End if
End Function

</Script>

I dont know how you actually use the application, but if you can just use one table and add another boolean field for yes/No if selected or not, would make it easier to use this function.

Last edited by fredservillon; 01-16-06 at 10:28.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On