Print Page | Close Window

filling combobox

Printed From: Web Wiz Forums
Category: General Discussion
Forum Name: Classic ASP Discussion
Forum Description: Discussion on Active Server Pages (Classic ASP).
URL: https://forums.webwiz.net/forum_posts.asp?TID=14560
Printed Date: 30 March 2026 at 6:55am
Software Version: Web Wiz Forums 12.08 - https://www.webwizforums.com


Topic: filling combobox
Posted By: t.vdplaats
Subject: filling combobox
Date Posted: 05 April 2005 at 7:00am
Can someone help me to modify the default.asp that the list will be shown in a combobox (news_id and news_title) instead of a list???
 
here's the content of the default.asp (standard webwizNews default.asp):
 
<% Option Explicit %>
<!--#include file="common.asp" -->
<%
Dim rsNews   'Database recordset holding the news items
Dim intRecordPositionPageNum 'Holds the number of the page the user is on
Dim intRecordLoopCounter 'Loop counter to loop through each record in the recordset
Dim intTotalNumNewsEntries 'Holds the number of News Items there are in the database
Dim intTotalNumNewsPages 'Holds the number of pages the News Items cover
Dim intLinkPageNum  'Holds the number of the other pages of news itmes to link to

'If this is the first time the page is displayed then set the record position is set to page 1
If Request.QueryString("PagePosition") = "" Then
 intRecordPositionPageNum = 1
'Else the page has been displayed before so the news item record postion is set to the Record Position number
Else
 intRecordPositionPageNum = CInt(Request.QueryString("PagePosition"))
End If 
%>
<html>
<head>
<title></title>
<link rel="stylesheet" href="../stylesheet.CSS" type="text/css">
</head>
<body class="backvlak">
</body>
 

 <%
'Create recorset object
Set rsNews = Server.CreateObject("ADODB.Recordset")
 
'Initalise the strSQL variable with an SQL statement to query the database by selecting all tables ordered by the decending date
strSQL = "SELECT tblNews.* FROM tblNews ORDER BY News_Date DESC;"
'Set the cursor type property of the record set to dynamic so we can naviagate through the record set
rsNews.CursorType = 3
 
'Query the database
rsNews.Open strSQL, adoCon
'Set the number of records to display on each page by the constant set in the common.asp file
rsNews.PageSize = intRecordsPerPage
 
'Get the record poistion to display from
If NOT rsNews.EOF Then rsNews.AbsolutePage = intRecordPositionPageNum

'If there are no rcords in the database display an error message
If rsNews.EOF Then
 'Tell the user there are no records to show
 Response.Write "<span class=""text""><br>There are no News Items to read"
 Response.Write "<br>Please check back later</span>"
 Response.End
 

'Display the News Items
Else 
 
 'Count the number of News Items database
 intTotalNumNewsEntries = rsNews.RecordCount 
 
 'Count the number of pages of News Items there are in the database calculated by the PageSize attribute set above
 intTotalNumNewsPages = rsNews.PageCount

 'Display the HTML number number the total number of pages and total number of records
 %>
 
<br>
<table width="100%" border="0" cellspacing="0" cellpadding="0" align="center" class="normal">
 <tr>
    <td align="center" class="text"></td>
 </tr>
</table>
<br>
<%
 'For....Next Loop to display the News Items in the database
 For intRecordLoopCounter = 1 to intRecordsPerPage
  'If there are no records then exit for loop
  If rsNews.EOF Then Exit For 
 %>
<table width="95%" border="0" align="center" cellpadding="1" cellspacing="0">
 <tr>
    <td class="link"><strong><a href="news_item.asp?NewsID=<% = rsNews("News_ID") %>" target="_self">
      <% = rsNews("News_title") %>
      </a></strong> <span class="normal"></span> </td>
 </tr>
</table>
<br><%
  'Move to the next record in the recordset
  rsNews.MoveNext
 Next
End If
'Display an HTML table with links to the other News Items
%>
<table width="100%" border="0" cellspacing="0" cellpadding="0" align="center">
 <tr>
  <td> <table width="100%" border="0" cellpadding="0" cellspacing="0">
    <tr>
          <td width="50%" align="center" class="normal">
            <%
'If there are more pages to display then add a title to the other pages
If intRecordPositionPageNum > 1 or NOT rsNews.EOF Then
 Response.Write vbCrLf & "  Page:&nbsp;"
End If
'If the News Items page number is higher than page 1 then display a back link     
If intRecordPositionPageNum > 1 Then
 Response.Write vbCrLf & "   <a href=""default.asp?PagePosition=" &  intRecordPositionPageNum - 1  & """ target=""_self"">&lt;&lt;&nbsp;Prev</a>&nbsp;"          
End If      

'If there are more pages to display then display links to all the pages
If intRecordPositionPageNum > 1 or NOT rsNews.EOF Then
 
 'Display a link for each page in the News Items      
 For intLinkPageNum = 1 to intTotalNumNewsPages  
  
  'If the page to be linked to is the page displayed then don't make it a hyper-link
  If intLinkPageNum = intRecordPositionPageNum Then
   Response.Write vbCrLf & "       " & intLinkPageNum
  Else
  
   Response.Write vbCrLf & "       <a href=""default.asp?PagePosition=" &  intLinkPageNum  & """ target=""_self"">" & intLinkPageNum & "</a>&nbsp;"   
  End If
 Next
End If

'If it is Not the End of the News Items entries then display a next link for the next News Items page       
If NOT rsNews.EOF then    
 Response.Write vbCrLf & "  <a href=""default.asp?PagePosition=" &  intRecordPositionPageNum + 1  & """ target=""_self"">Next&nbsp;&gt;&gt;</a>"     
End If       

'Finsh HTML the table
%>
          </td>
    </tr>
   </table>
   </td>
 </tr>
</table>
<%
'Reset server objects
rsNews.Close
Set rsNews = Nothing
Set strCon = Nothing
Set adoCon = Nothing
%>
<br>
<div align="center"> </div>



Replies:
Posted By: snooper
Date Posted: 05 April 2005 at 6:33pm
%>
<select name="NameHERE">
<% For intRecordLoopCounter = 1 to intRecordsPerPage
  'If there are no records then exit for loop
  If rsNews.EOF Then Exit For 
 %>
 <option value="<% = rsNews("News_ID") %>"><% = rsNews("News_title") %></option>
<%
  'Move to the next record in the recordset
  rsNews.MoveNext
 Next
%>
</select>
<%


Posted By: t.vdplaats
Date Posted: 06 April 2005 at 2:53am
Thanx snooper.. that did the job!



Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.08 - https://www.webwizforums.com
Copyright ©2001-2026 Web Wiz Ltd. - https://www.webwiz.net