Snitz Forums 2000
Snitz Forums 2000
Home | Profile | Register | Active Topics | Members | Search | FAQ
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 Community Forums
 Code Support: ASP (Non-Forum Related)
 Build a dynamic select box
 New Topic  Topic Locked
 Printer Friendly
Author Previous Topic Topic Next Topic  

redbrad0
Advanced Member

USA
3725 Posts

Posted - 25 December 2004 :  14:19:01  Show Profile  Visit redbrad0's Homepage  Send redbrad0 an AOL message
For some reason I can't seem to figure this out. I am trying to build a dynamic select box but cant seem to get it right. In the sample database layout below you can see that I have it setup to have a unlimited number of sub category's.


ID      CatID       Name
1       0           Brads Pictures
2       0           Stephs Pictures
3       1           Christmas
4       1           Halloween
5       3           2003
6       3           2004


Now this is what the select box would look like

<select name="CategoryID">
  <option value="1">Brads Pictures</option>
  <option value="3">- Christmas</option>
  <option value="4">- Halloween</option>
  <option value="5">-- 2003</option>
  <option value="6">-- 2004</option>
  <option value="2">Stephs Pictures</option>
</select>


So far this is the code I have which just display the base category's. Can someone help me figure out how to get this correct?

function DisplayPictureCats(fCatID)
	fDisplaySelect = ""
	fDisplaySelect = "<select size=""1"" name=""CategoryID"">" & vbCrLf
	strSql = "SELECT Cat_ID"
	strSql = strSql & ", Cat_CatID"
	strSql = strSql & ", Cat_Name"
	strSql = strSql & " FROM Category"
	strSql = strSql & " WHERE Cat_CatID=0"
	Set rsf = my_Conn.Execute(strSql)

	If rsf.eof or rsf.bof Then
		fDisplaySelect = fDisplaySelect & "<option value="""">No Categorys Available</option>" & vbCrLf
	Else
		fDisplaySelect = fDisplaySelect & "<option value="""">Select Your Category</option>" & vbCrLf
		do until rsf.eof or rsf.bof
			fDBCatID = rsf("Cat_ID")
			fDBCatCatID = rsf("Cat_CatID")
			fDBCatName = rsf("Cat_Name")

			fDisplaySelect = fDisplaySelect & "<option value=""" & fDBCatID & """"
			If cint(fCatID)=cint(fDBCatID) Then
				fDisplaySelect = fDisplaySelect & " selected"
			End If
			fDisplaySelect = fDisplaySelect & ">" & fDBCatName & "</option>" & vbCrLf
			rsf.movenext
		loop
	End If
	fDisplaySelect = fDisplaySelect & "</select>" & vbCrLf
	DisplayPictureCats = fDisplaySelect
end function

Brad
Oklahoma City Online Entertainment Guide
Oklahoma Event Tickets

Gremlin
General Help Moderator

New Zealand
7528 Posts

Posted - 25 December 2004 :  23:15:28  Show Profile  Visit Gremlin's Homepage
You might want to consider using GetString, it's fairly efficient building listboxes or selects etc

http://www.4guysfromrolla.com/webtech/102600-1.shtml
http://www.aspfree.com/c/a/ASP-Code/Using-GetString-Method-to-Populate-a-dropdown-box-by-Michael-Ryan/

Kiwihosting.Net - The Forum Hosting Specialists
Go to Top of Page

redbrad0
Advanced Member

USA
3725 Posts

Posted - 25 December 2004 :  23:59:14  Show Profile  Visit redbrad0's Homepage  Send redbrad0 an AOL message
Thanks for the links but I am still lost on how to get this to display correctly. With trying to post the sub categorys in different levels is what is getting me in only using 1 or 2 select statments.

Brad
Oklahoma City Online Entertainment Guide
Oklahoma Event Tickets
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Topic Locked
 Printer Friendly
Jump To:
Snitz Forums 2000 © 2000-2021 Snitz™ Communications Go To Top Of Page
This page was generated in 0.38 seconds. Powered By: Snitz Forums 2000 Version 3.4.07