ASP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingASP Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old August 27th, 2002, 03:40 PM
aspnewbie aspnewbie is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2002
Location: The Great White North
Posts: 361 aspnewbie User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 58 m 50 sec
Reputation Power: 8
Send a message via MSN to aspnewbie
Editing a Drop Down List

Does anyone know how to display (for an edit page) a drop down list, which highlights the items the user selected when they added the record to the database.

Like the list of authors from the WYSIWIG example in Article 116. The add page gives you a drop down list of Authors.

dropdown list code:

Code:
<select name="author" style="width:335px"> 
<option value="NULL" checked>-- Select an Author --</option> 
<% 

objRS.Open "select * from newsAuthors order by name asc" 

while not objRS.EOF 
Response.Write "<option value='" & objRS("authorId") & "'>" 
Response.Write objRS("name") & "</option>" 
objRS.MoveNext 
wend 

%> 

</select> 


here's where it is added to the database for the first time:

Code:
objConn.Execute "insert into 
newsPosts(title,topics,newsPost,authorId) 
values('" & title & "', '" & topics & "','" & 
newsPost & "'," & author & ")" 


But if the user accidentally selected the wrong person and you wanted to enable the user to edit that record via an edit record asp, how would recreate the dropdown list with the previously selected items highlighted?

Thanks!

Reply With Quote
  #2  
Old September 7th, 2002, 07:38 PM
rdoekes rdoekes is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2002
Location: Strasbourg, France
Posts: 181 rdoekes User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 m 20 sec
Reputation Power: 8
Send a message via AIM to rdoekes Send a message via Yahoo to rdoekes
Do this by select the author id from the NewsPost u r looking for.
Then make the matching authorID option selected:


<select name="author" style="width:335px">
<option value="NULL">-- Select an Author --</option>
<%

Dim iAuthorID
objRs.Open "select authorID From newPost Where NewsID = [yourNewsId]"
If Not objRs.EOF Then

iAuthorID = objRs.Fields(0).value
Else
iAuthodID = 0
End If

objRs.Close

'now select the list of authors


objRS.Open "select * from newsAuthors order by name asc"

while not objRS.EOF

Response.Write "<option value='" & objRS("authorId") & _
"'"
'here is the trick
If Cint(objRs("authorID")) = Cint(iAuthorID) Then
Response.Write " selected"
End If

Response.Write ">" & objRS("name") & "</option>"

objRS.MoveNext
wend

End If

%>
</select>
__________________
- Rogier Doekes

Reply With Quote
  #3  
Old September 9th, 2002, 10:57 AM
aspnewbie aspnewbie is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2002
Location: The Great White North
Posts: 361 aspnewbie User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 58 m 50 sec
Reputation Power: 8
Send a message via MSN to aspnewbie
Thanks very much! I'll try that out. BTW, would this be the same for multiple selects or is an additional loop required?

Reply With Quote
  #4  
Old September 9th, 2002, 11:07 AM
rdoekes rdoekes is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2002
Location: Strasbourg, France
Posts: 181 rdoekes User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 m 20 sec
Reputation Power: 8
Send a message via AIM to rdoekes Send a message via Yahoo to rdoekes
multiple selects

If u have multiple selects first you need to define a multiple property in your HTML select tag
<select name="authorID" multiple>

Then your test is not a simple test anymore but a For loop which you test.

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingASP Development > Editing a Drop Down List


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump




 Free IT White Papers!
 
How to Present Effectively Online
This white paper offers practical and actionable advice on the key steps that any presenter should consider as they plan and execute a Webinar or online meeting.

Request Your Free Technology Downloads!
 
Open Source Security Myths
Open Source Software (OSS) is computer software whose source code is available to the general public with relaxed or non-existent intellectual property restrictions (or arrangement such as the public domain), and is usually developed with the input of many contributors.

Request Your Free Technology Downloads!
 
Power and Cooling Capacity Management for Data Centers
This paper describes the principles for achieving power and cooling capacity management.

Request Your Free Technology Downloads!
 
Scalable, Fault-Tolerant NAS for Oracle - The Next Generation
For several years NAS has been evolving as a storage alternative for Oracle databases, and for good reason: NAS is quite often the simplest, most cost-effective storage approach for Oracle. Learn about the benefits that HP's approach to scalable NAS brings to Oracle environments in this comprehensive white paper.

Request Your Free Technology Downloads!
 
Understanding Web Application Security Challenges
This white paper discusses many common threats and preventive measures for Web application security, and explains what you can do to help protect your organization.

Request Your Free Technology Downloads!
 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 




© 2003-2009 by Developer Shed. All rights reserved. DS Cluster 5 Hosted by Hostway
For more Enterprise Application Development news, visit eWeek