raghup Posted July 2, 2007 Share Posted July 2, 2007 How do I populate a drop down list?I have a table named tblChecklist in my database. One of the fields is named txtStatusOfJob and has a dropdown list. This list is populated by another table called tblDDLStatus. The field name in this table is txtStatus.I am using asp with vbscript. I tried using the following code in an edit record page. It is not working. The pages is not loading. Any help would be appreciated.Cheers Raghu <%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%><%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%><!--#include file="Connections/cnDbase2.asp" --><%Dim rsCheckListsSet rsCheckLists = Server.CreateObject("ADODB.Recordset")rsCheckLists.ActiveConnection = MM_cnDbase_STRINGrsCheckLists.Source = "SELECT * FROM ChecklistaipabChad WHERE anID=" & Request.QueryString("id")rsCheckLists.CursorType = 0rsCheckLists.CursorLocation = 2rsCheckLists.LockType = 1rsCheckLists.Open()%><% Dim DataConnDim cmdPopulateStatusDim SQL Set DataConn = Server.CreateObject("ADODB.Connection")Set cmdPopulateStatus = Server.CreateObject("ADODB.Recordset")DataConn.Open "dsn=webdbase"SQL = "SELECT STATUS, DESCRIPTION FROM ddlStatus ORDER BY STATUS ASC"cmdPopulateStatus.Open SQL, DataConn%><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html><body><form><Select Name="statusOfJob" id = "statusOfJob"><option value="" selected="<%=(rsCheckLists.Fields.Item("statusOfJob").Value)%>"><%=(rsCheckLists.Fields.Item("statusOfJob").Value)%></option> <%While Not cmdPopulateStatus.EOF%><option value="<%= cmdPopulateStatus("STATUS") %>"><%= cmdPopulateStatus("DESCRIPTION") %></option><%cmdPopulateStatus.MoveNextWendcmdPopulateStatus.CloseSet cmdPopulateStatus = NothingDataConn.CloseSet DataConn = Nothing%></Select></form></body></html>[code] Link to comment Share on other sites More sharing options...
justsomeguy Posted July 2, 2007 Share Posted July 2, 2007 rsStatus.Source = "SELECT STATUS FROM tblDDLStatus ORDER BY txtStatus ASC"You are only getting a field called "STATUS" from the table, but you try to order by txtStatus (which you are not getting). You're also trying to use another field later called DESCRIPTION that you are also not getting. Link to comment Share on other sites More sharing options...
raghup Posted July 3, 2007 Author Share Posted July 3, 2007 rsStatus.Source = "SELECT STATUS FROM tblDDLStatus ORDER BY txtStatus ASC"You are only getting a field called "STATUS" from the table, but you try to order by txtStatus (which you are not getting). You're also trying to use another field later called DESCRIPTION that you are also not getting.I have changed to the followingrsStatus.Source = "SELECT STATUS, DESCRIPTION FROM ddlStatus ORDER BY STATUS ASC" still not working.cheersraghu Link to comment Share on other sites More sharing options...
justsomeguy Posted July 3, 2007 Share Posted July 3, 2007 The field name in this table is txtStatus.What is the field called, txtStatus or STATUS? Make sure you are using the correct names. Link to comment Share on other sites More sharing options...
raghup Posted July 5, 2007 Author Share Posted July 5, 2007 I have changed the code above. The out put is as followsIN PROGRESS <<APPROVEDARCHIVEDCOMPLETEDIN PROGRESS <<PUBLISHEDREJECTEDThe above code is giving me the dropdown list as shown "IN PROGRESS" is visible two times! How do I fix this?CheersRaghu Link to comment Share on other sites More sharing options...
justsomeguy Posted July 5, 2007 Share Posted July 5, 2007 It's in the database twice. Link to comment Share on other sites More sharing options...
raghup Posted July 6, 2007 Author Share Posted July 6, 2007 It's in the database twice.It is not in the database two times. cheersraghu Link to comment Share on other sites More sharing options...
justsomeguy Posted July 6, 2007 Share Posted July 6, 2007 There is a static option here:<option value="" selected="<%=(rsCheckLists.Fields.Item("statusOfJob").Value)%>"><%=(rsCheckLists.Fields.Item("statusOfJob").Value)%></option>So one option will be printed there, and the rest in the loop. If you want then you can check in the loop to skip the one printed first, or also just leave out the first one being printed and instead check in the loop if the current item is the selected item, and if so to write the selected attribute for it. Link to comment Share on other sites More sharing options...
raghup Posted July 10, 2007 Author Share Posted July 10, 2007 There is a static option here:<option value="" selected="<%=(rsCheckLists.Fields.Item("statusOfJob").Value)%>"><%=(rsCheckLists.Fields.Item("statusOfJob").Value)%></option>So one option will be printed there, and the rest in the loop. If you want then you can check in the loop to skip the one printed first, or also just leave out the first one being printed and instead check in the loop if the current item is the selected item, and if so to write the selected attribute for it.Thanks a lot for the tip. I used the following. It is working fine now!cheersRaghu<Select Name="statusOfJob" id = "statusOfJob"><%While Not cmdPopulateStatus.EOF%><option value="<%= cmdPopulateStatus("STATUS") %>" <%If rsCheckLists.Fields.Item("statusOfJob") = cmdPopulateStatus("STATUS") Then Response.Write("selected=""selected""") : Response.Write("")%>><%= cmdPopulateStatus("DESCRIPTION") %></option><%cmdPopulateStatus.MoveNextWendcmdPopulateStatus.CloseSet cmdPopulateStatus = NothingDataConn.CloseSet DataConn = Nothing%></Select> Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.