|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| ||||||||||||||||||||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
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! |
|
#2
|
|||
|
|||
|
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 |
|
#3
|
|||
|
|||
|
Thanks very much! I'll try that out. BTW, would this be the same for multiple selects or is an additional loop required?
|
|
#4
|
|||
|
|||
|
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. |
![]() |
| Viewing: Dev Articles Community Forums > Programming > ASP Development > Editing a Drop Down List |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|