Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Condition the elements of a Drop downbox

Status
Not open for further replies.

cfcProgrammer

Programmer
Mar 1, 2006
88
CA
Hi,

I am still fairly new to ASP so I need a little help.

I need to start off by first saying that I do not agree with what I am about to ask you about. I have argued and am sure there are a million other ways for this to be coded but I have been told that this is the way it is to be done... so here I am asking for your help in doing it.

A field is added to a table in the sql server database that will hold up to 12 numbers all separated by a comma. These numbers will represent the report number.(this is the part that I strongly disagree on)

I have to build the drop down box depending on what is in this field. So if I have 1,5,8,9,10,11 then those are the reports I must display in the drop down box.

Here is how I currently have the drop down box created.

Code:
<tr><td colspan="5" align="center">
    <h3 align="center">
    <span style="font-size: 10pt; font-family: Arial">Report Name:&nbsp; </span>
<select name="ReportName" id="ReportName">
<option value="-1" selected="selected">--- Please Select a Report ---</option>
<option value="1">Report One</option>
<option value="2">Report Two</option>
<option value="3">Report Three</option>
<option value="4">Report Four</option>
<option value="5">Report Five</option>
<option value="6">Report Six</option>
<option value="7">Report Seven</option>
<option value="8">Report Eight</option>
<option value="9">Report Nine</option>
<option value="10">Report Ten</option>
<option value="11">Report Eleven</option>
<option value="12">Report Twelve</option>
</select></h3> 
<hr align="center" width="825">
</td>
</tr>

How can I search that field for the values and then apply it to the dropdown box creation? Do I separate the field and store each of the elements somewhere or is there a cleaner way of doing this. My boss is convinced all of this can be done in one simple line of code. I am not seeing that but PLEASE if it can be done I will greatly accept the fact that I was wrong.

I have also been given the option of either removing the display of the report name all together or simply graying it out and making it inactive.

Can someone please give me a hand with this? He would like it "yesterday" if you know what I mean. Things are a little tense here with this and the last thing I want to do is spend hours trying to figure this out and have something else for us to butt heads over.

I am going to work on this too.. I'm not asking someone to do my work for me... I just need some help and guidance.

Any help at all would be greatly appreciated.

Thanks so much


cfcProgrammer
 
So what is this form doing?

If a thing, whatever it is, is in the database it will have up to 12 reports associated with it?

The form would allow users to grab whatever reports are associated with the thing?

I think your boss is wrong and one simple line of code it isn't.
 
[tt]<%
dim nword
nword=array("Zero","One","Two","Three","Four","Five","Six", _
"Seven","Eight","Nine","Ten","Eleven","Twelve")
'etc etc
dim s, a, i
s=rs("[blue]thatfield[/blue]").value
a=split(s,",") 'suppose .value is already in sorted order and within the range [1,12]
%>
<tr><td colspan="5" align="center">
<h3 align="center">
<span style="font-size: 10pt; font-family: Arial">Report Name:&nbsp; </span>
<select name="ReportName" id="ReportName">
<option value="-1" selected="selected">--- Please Select a Report ---</option>
<%
for i=0 to ubound(a)
%>
<option value="<%= trim(a(i))%>">Report <%= nword(cint(a(i))%></option>
<%
next
%>
</select></h3>
<hr align="center" width="825">
</td>
</tr>
[/tt]
 
Thank you for your response. What this form is simply doing is building an application, so that when users log into it a page is displayed that contains a drop down box with only the reports that they have permissions to and a series of parameters that they can enter.

I think I managed to resolve it.. here is what I came up with...
Code:
dim MyResults,MyConn, MySql

    set MyConn = Server.CreateObject("ADODB.Connection")
    MyConn.ConnectionTimeout = 0
   ' The following line must be changed to reflect your data source info

    MyConn.open "Driver={SQL Server};Server=SNAME;Database=DNAME;Uid=ID;Pwd=PASS;"
    MyConn.CommandTimeout = 0

    MySql="Select STATEMENT FROM TABLE WHERE UID = UID
    set rstemp=MyConn.execute(MySql)

    'check the return value to see if there are any records returned
        if NOT (rstemp.EOF) then
    'Retreive the data from the SQL results'
            repArrRS = rstemp.getrows()
            totrecs = ubound(repArrRS,2)
        dim repRow 'Row Counter
            repRow = 0
            AreRecs = true 'there are records
        else
            totrecs = 0
            AreRecs = false 'there are no records
        end if
         rstemp.close() 'close the recordset
         set rstemp = Nothing
 %>

'Create an Array to hold the report id in each element

MyResults = repArrRS(0,repRow)
Dim RptArray
RptArray = split(MyResults,",")

'Function to get all the report names 

Function GetrepName(int i){
 case 1: 
    return "Report Name One";
 case 2: 
    return "Report Name Two";
 case 3: 
    return "Report Name Three";
 case 4: 
    return "Report Name Four";
 case 5: 
    return "Report Name Five";
 case 6: 
    return "Report Name Six";
 case 7: 
    return "Report Name Seven";
 case 8: 
    return "Report Name Eight";
 case 9: 
    return "Report Name Nine;
case 10: 
    return "Report Name Ten";
 case 11: 
    return "Report Name Eleven";
 case 12: 
    return "Report Name Twelve";
}
%>
<tr><td colspan="5" align="center">
    <h3 align="center">
    <span style="font-size: 10pt; font-family: Arial">Report Name:&nbsp; </span>
<select name="ReportName" id="ReportName">
<option value="-1" selected="selected">--- Please Select a Report ---</option>
<% for (i=0; i<RptArray.length;i++)
 <option value =<% RptArray [i]%>> <%Getrepname(RptArray [i])%>
</select></h3>

<hr align="center" width="825">
    </td>
</tr>

Does this seem like a good solution? If you see any code that you deem unnecessary or a more efficient way of doing it.. please your feedback and any suggestions are very appreciated and welcomed.

Thanks





cfcProgrammer
 
A rough look over it seems to suggest to me a sort of almagame of vbs and cf/js syntax. But since you said you have already managed to resolve it with what you show, I sure pass with no comment.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top