"Ram Raju" <ra*****@lycos.com> wrote in message
news:uu*************@tk2msftngp13.phx.gbl...
Hi All,
I am displaying few values in a List box. I would like to put first
item as selected by default.
i.e <option value="some value" selected>Name</option>
Here is my code.
<SELECT size=15 id=select1 name=select1>
<% do while not Rs.EOF %>
<Option value=<%=Rs("value")%>><%= Rs("Name") %></Option>
<%
Rs.MoveNext
loop
%>
</SELECT>
You could use some sort of flag to indicate that it's the first item. Also,
you should surround your attribute values in quotes.
<select size="15" id="select1" name="select1">
<%
Dim firstOption
firstOption = True
Do While Not Rs.EOF
Response.Write "<option value=""" & Rs("value") & """"
If firstOption = True Then
Response.Write " selected"
firstOption = False
End If
Response.Write ">" & Rs("Name") & "</option>"
Rs.MoveNext
Loop
%>
</select>
Hope this helps.
Regards,
Peter Foti