PDA

View Full Version : Dropdown Box with data fom the selected column


Cuttie0506
02-15-2006, 02:35 PM
Hi..
I have a dropdown list with a number of classes.. Those classes refers to the columns names in the db...
When i selected i class, i will search that column in m db...
"listCol" is the column name i request.form("class")

After i have selected the information out, i want to display the data in a dropdown box...

But how do i specify is from which column?

Code for getting the data from the selected column:

dim sqlString
Dim rs_vList

Set rs_vList = Server.CreateObject("ADODB.Recordset")
rs_vList.ActiveConnection = MM_dsprms_STRING

dim listCol
listCol = request.form("class")

sqlString = "SELECT DISTINCT " & listCol & " From Sys_Config_Table"

rs_vList.Source = sqlString
rs_vList.CursorType = 0
rs_vList.CursorLocation = 2
rs_vList.LockType = 1
rs_vList.Open()



Code for the dropdown list

<tr> <td>List: </td>
<td><select name=list id=select>
<%While (NOT rs_vListSearch.EOF)%>
<option value="<%=(rs_vListSearch.Fields.Item(" ").Value)%>"<%If (Not isNull((Session("list")))) Then If (CStr(rs_vListSearch.Fields.Item(" ").Value) = CStr((Session(" ")))) Then Response.Write("SELECTED")%>><%=(rs_vListSearch.Fields.Item(" ").Value)%></option>
<%
rs_vListSearch.MoveNext()
Wend

If (rs_vListSearch.CursorType > 0) Then
rs_vListSearch.MoveFirst

Else
rs_vListSearch.Requery
End If
%>
</select></td>


What should i put for my "rs_vListSearch.Fields.Item("list").Value", the value inside the bracket? Coz normally i will put my colName, but this time the col name i get using another dropdown list.

Thanx

Roelf
02-15-2006, 09:29 PM
try this:
<option value="<%=(rs_vListSearch.Fields.Item(Request.Form("yourdropdownlistname")).Value)%>"<%If (Not isNull((Session("list")))) Then If (CStr(rs_vListSearch.Fields.Item(" ").Value) = CStr((Session(" ")))) Then Response.Write("SELECTED")%>><%=(rs_vListSearch.Fields.Item(" ").Value)%></option>

and the part in red in those other places too

But it might be better to get the Request.Form("yourdropdownlistname") somewhat earlier in a var, that way you can do some checking on the value (is a value present fe) then you wont screw up your new dropdown

Cuttie0506
02-16-2006, 01:16 AM
Hi, i have tried, but i got an error..

Code for getting the data in the 2nd ddl


If request.form("submit") = "Get List" OR request.form("submit") = "Get Rating" OR request.form("submit") = "Save" OR request.form("submit") = "Save & Email" Then

dim sqlString
Dim rs_vList

Set rs_vList = Server.CreateObject("ADODB.Recordset")
rs_vList.ActiveConnection = MM_dsprms_STRING

'dim listCol
'listCol = request.form("class")

sqlString = "SELECT DISTINCT " & request.form("class") & " From Sys_Config_Table"

rs_vList.Source = sqlString
rs_vList.CursorType = 0
rs_vList.CursorLocation = 2
rs_vList.LockType = 1
rs_vList.Open()
End If


Code for the 1st ddl(which i will select and display the data for 2nd ddl)


<tr>
<td>Class: </td>
<td><select name=class id=select>
<%While (NOT rs_vClass.EOF)%>
<option value="<%=(rs_vClass.Fields.Item("Class").Value)%>"<%If (Not isNull((Session("class")))) Then If (CStr(rs_vClass.Fields.Item("Class").Value) = CStr((Session("class")))) Then Response.Write("SELECTED")%>><%=(rs_vClass.Fields.Item("Class").Value)%></option>
<%
rs_vClass.MoveNext()
Wend

If (rs_vClass.CursorType > 0) Then
rs_vClass.MoveFirst

Else
rs_vClass.Requery
End If
%>
</select> <input type=submit name=submit value='Get List'></td>
<td>&nbsp;</td>
<td width="40%" colspan="3"><font size="2">Class that Vulnerability belongs to</font></td>
</tr>



Code for the 2nd ddl

<% If request.form("submit") = "Get List" OR request.form("submit") = "Get Rating" OR request.form("submit") = "Save" OR request.form("submit") = "Save & Email" Then %>
<tr> <td>List: </td>
<td><select name=list id=select>
<%While (NOT rs_vList.EOF)%>
<option value="<%=(rs_vList.Fields.Item(request.form("class")).Value)%>"<%If (Not isNull((Session("list")))) Then If (CStr(rs_vList.Fields.Item(request.form("class")).Value) = CStr((Session("list")))) Then Response.Write("SELECTED")%>><%=(rs_vList.Fields.Item(request.form("class")).Value)%></option>
<%
rs_vList.MoveNext()
Wend

If (rs_vList.CursorType > 0) Then
rs_vList.MoveFirst

Else
rs_vList.Requery
End If
%>
</select></td>
<td>&nbsp;</td>
<td width="40%" colspan="3"><font size="2">List related to Class selected</font></td></tr>
<% End If %>

Bullschmidt
03-07-2006, 02:37 AM
Some related links:

Classic ASP Design Tips - Fill a Listbox Possibly With Multiple Columns
http://www.bullschmidt.com/devtip-filllistbox.asp

Classic ASP Design Tips - Dependent Listboxes
http://www.bullschmidt.com/devtip-dependentlistboxes.asp

degsy
03-07-2006, 02:33 PM
i have tried, but i got an error..
?????

Cuttie0506
03-09-2006, 06:26 AM
erm, nvm, its okay already.. because i'm not working on this already.. thanx anyway

Bullschmidt
03-09-2006, 10:16 AM
And just for future reference I think what degsy was pointing out is that whenever you're posting about an error, it's nice to have the exact error message which often refers to a specific line of code and along the same lines to know exactly what line of code that actually was.

And here's something about what to do if you're NOT getting a nice, specific error message.

It would be nice to get some more diagnostic information on the error message page. So in Internet Explorer you can do this: Tools | Internet Options | Advanced | Uncheck Show friendly HTTP error messages. And it doesn't hurt anything to just keep your browser set like this.

And then when you get an error you can see more on the error page especially the code at the bottom which could be something like "Error on line 339 GetValue()) extra parenthesis"?

And here's a resource about that:

Why do I get a 500 Internal Server error for all ASP errors?
http://www.aspfaq.com/show.asp?id=2109

Cuttie0506
03-10-2006, 03:31 AM
okay, i will take note. Thanx