Link to home
Start Free TrialLog in
Avatar of potwingn
potwingn

asked on

checkbox's in a treeview.

When the checkbox's are selected and I click on submit, I need it to query the database for the names listed next to that checkbox.  For eample...
I have a list of a company's breakdown.

ANY COMPANY USA
   STORE NUMBER
       DEPT 1
       DEPT 2
       DEPT 3   ETC...
Each of the store number's and dept's have a check box next to it, and I want to have on another page post the information from that database.  With the check boxes checked in any number of combinations, then clicking on submit it will go to the next page and show the data from my database for those selected.  I am thinking an if then statement, but I am new to this and would appreciate any help you can offer me.

   
ASKER CERTIFIED SOLUTION
Avatar of fritz_the_blank
fritz_the_blank
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hi
For Each nd In TreeView1.Nodes
   If nd.Checked Then
      If Len(sQuery)<>0 Then sQuery = sQuery + "," ' or other delimiter
      sQuery = sQuery + nd.Text
'or
'      sQuery = sQuery + nd.Path
'      sQuery = sQuery + nd.Tag '(tag can store some ID)
   End If
Next

set sQuery value to hidden input element and
strIDs = Split( request.form("HiddenElement")
For i=0 to ubound(strIDs)
   'your staff with every id
Next i
Avatar of potwingn
potwingn

ASKER

Below is the code that I have so far.  I am new to this, could you post to me in a way that I can see how it works with what I have.  Your help is very much appreciated.




<html>
<head>
<title>ASP TreeView Exemple</title>
<meta name="author" content="Simon La Rochelle">
<meta name="description" content="This is an easy way to make a vb-like TreeView in ASP">

<script language='javascript'>

function ToggleDisplay(oButton, oItems) {

      if ((oItems.style.display == "") || (oItems.style.display == "none")) {
            oItems.style.display = "block";
            oButton.src = "minus.gif";
      }      else {
            oItems.style.display = "none";
            oButton.src = "plus.gif";
      }

      return false;

}

function HideDisplay(oItems) {

      oItems.style.display = "none";

}

function ShowDisplay(oItems) {

      oItems.style.display = "block";

}

</script>

</head>

<body bgcolor='#FFFFFF'>
<form action=subs3.asp method='post'>

<%
dim eunit, childno1, CHILDNO2, grecordset, childno3, fsql, erecordset, esql, gsql, FRECORDSET, childno, oconnection, urecordset, drecordset, dsql, orecordset, csql, cevent, cunit, ccount, topn, intpage, intpgcnt, intrecnt, intfn, intstart, callev, callun, csubs, usql, cuic, tree, tcount
cunit=request.form("Unit")
cevent=request.querystring("EVENT")
callev=request.querystring("ALLEV")
callun=request.querystring("ALLUN")
set oConnection = Server.CreateObject( "adodb.connection" )
oConnection.Provider = "vfpoledb.1"
oConnection.ConnectionString = "data source=e:\inetpub\wwwroot\ito\vamft\data\vamft.dbc"
oConnection.Open            

'Get our recordset
set uRecordSet = Server.CreateObject( "adodb.recordset" )
urecordset.cursorlocation=3
urecordset.cursortype=3
urecordset.activeconnection=oconnection
usql="select * from units where unit = '" & cunit & "'"
uRecordSet.Open usql
csubs=0
if not urecordset.EOF then
cuic=urecordset.fields(0).value
usql="select * from units where bduic = '" & cuic & "' and unit <> '" & cunit & "'"
uRecordSet.Close
uRecordSet.Open usql
csubs=urecordset.recordcount
end if
tcount = 2
tree = 1
'HERE'S THE FIRST EXEMPLE (without checkboxes and links)
if csubs > 0 then%>
<h3>All Subordinate Units For <%=cunit%></h3>
<%    WriteHead "My2TreeView",1,cunit,0,True,False,"",false
for ccount = 1 to csubs
     if urecordset.fields(7).value = "BN    " then
      WriteHead "My2TreeView",tcount,urecordset.fields(1).value,tree,True,False,"",true
        tcount=tcount+1
      end if
     if urecordset.fields(7).value = "CO    " and urecordset.fields(5).value > "      " then
      WriteHead "My2TreeView",tcount,urecordset.fields(1).value,tree+1,false,true,"",true
        writefoot
        tcount=tcount+1
     else
        if urecordset.fields(7).value = "CO    " and urecordset.fields(5).value = "      " then
           writefoot
           WriteHead "My2TreeView",tcount,urecordset.fields(1).value,tree,false,true,"",true
           tcount=tcount+1
        end if
     end if
urecordset.movenext
next
end if
writefoot


%>
  </select>&nbsp;&nbsp;&nbsp; <input type="submit" value="Submit" name="Submit"></form>


</form>
</body>
</html>

<%

'*********************************
'TREEVIEW SUBS
'*********************************

Sub WriteHead(TreeName,ItemID,ItemName,Level,IsParent,UseCheckBox,MyLink,IsOpn)

      Dim IsIE 'as boolean
      
      IsIE = (InStr(request.servervariables("HTTP_USER_AGENT"), "MSIE") > 0)

      'Spacing depends on what level you're at
      Select Case Level
            Case 1 : Response.Write "<IMG SRC='dot1.gif' BORDER=0 ALT=''>"
            Case 2 : Response.Write "<IMG SRC='t_dot.gif' WIDTH=36 HEIGHT=18 BORDER=0 ALT=''><IMG SRC='dot1.gif' BORDER=0 ALT=''>"
            Case 3 : Response.Write "<IMG SRC='t_dot.gif' WIDTH=72 HEIGHT=18 BORDER=0 ALT=''><IMG SRC='dot1.gif' BORDER=0 ALT=''>"
            Case 4 : Response.Write "<IMG SRC='t_dot.gif' WIDTH=108 HEIGHT=18 BORDER=0 ALT=''><IMG SRC='dot1.gif' BORDER=0 ALT=''>"
            Case 5 : Response.Write "<IMG SRC='t_dot.gif' WIDTH=144 HEIGHT=18 BORDER=0 ALT=''><IMG SRC='dot1.gif' BORDER=0 ALT=''>"
            Case 6 : Response.Write "<IMG SRC='t_dot.gif' WIDTH=180 HEIGHT=18 BORDER=0 ALT=''><IMG SRC='dot1.gif' BORDER=0 ALT=''>"
            Case 7 : Response.Write "<IMG SRC='t_dot.gif' WIDTH=216 HEIGHT=18 BORDER=0 ALT=''><IMG SRC='dot1.gif' BORDER=0 ALT=''>"
            Case 8 : Response.Write "<IMG SRC='t_dot.gif' WIDTH=252 HEIGHT=18 BORDER=0 ALT=''><IMG SRC='dot1.gif' BORDER=0 ALT=''>"
            Case 9 : Response.Write "<IMG SRC='t_dot.gif' WIDTH=288 HEIGHT=18 BORDER=0 ALT=''><IMG SRC='dot1.gif' BORDER=0 ALT=''>"
            Case 10 : Response.Write "<IMG SRC='t_dot.gif' WIDTH=324 HEIGHT=18 BORDER=0 ALT=''><IMG SRC='dot1.gif' BORDER=0 ALT=''>"
      End Select

      'If IsParent then put a plus sign else put a blank space
      If IsParent then
            'JsCode only if isIE
            If isIE then
                  If IsOpn then
                        Response.Write "<IMG SRC='minus.gif' WIDTH=12 HEIGHT=10 ID='" & TreeName & ItemID & "Btn' ONCLICK='javascript:ToggleDisplay(" & TreeName & ItemID & "Btn, " & TreeName & ItemID & "chlds);' ALT BORDER='0'>"
                  Else
                        Response.Write "<IMG SRC='plus.gif' WIDTH=12 HEIGHT=10 ID='" & TreeName & ItemID & "Btn' ONCLICK='javascript:ToggleDisplay(" & TreeName & ItemID & "Btn, " & TreeName & ItemID & "chlds);' ALT BORDER='0'>"
                  End If
            Else
                  If IsOpn then
                        Response.Write "<IMG SRC='minus.gif' WIDTH=12 HEIGHT=10 ID='" & TreeName & ItemID & "Btn' ALT BORDER='0'>"
                  Else
                        Response.Write "<IMG SRC='plus.gif' WIDTH=12 HEIGHT=10 ID='" & TreeName & ItemID & "Btn' ALT BORDER='0'>"
                  End if
            End If      
      Else
            If Level = 0 then
                  Response.Write "<IMG SRC='nosign2.gif' WIDTH=12 HEIGHT=10 ALT BORDER='0'>"
            Else
                  Response.Write "<IMG SRC='nosign.gif' WIDTH=12 HEIGHT=10 ALT BORDER='0'>"
            End If
      End if
      
      'If UseCheckBox then show a checkbox else add space
      If UseCheckBox then
            Response.Write "<INPUT TYPE='checkbox' NAME='" & TreeName &"chk' VALUE='" & ItemID & "'>"
      Else
            Response.Write "<img src='t_dot.gif' WIDTH=4 HEIGHT=18 BORDER=0 ALT=''>"
      End If
            
      Response.Write "<font face='Verdana,Arial,Helvetica' size='2' color='#333399'>"
      
      'If MyLink = "" then do not use link
      If MyLink = "" then
            'If first Level, use bold
            If Level = 0 then Response.Write "<b>" & ItemName & "</b>" else Response.Write ItemName
      Else
            'If first Level, use bold
            If Level = 0 then Response.Write "<b><a href='" & MyLink & "'><font color='#333399'>" & ItemName & "</a></b>" else Response.Write "<a href='" & MyLink & "'><font color='#333399'>" & ItemName & "</a>"
      End If

      Response.Write "</font>"
      Response.Write "<br>"
      
      'Always add DIV because WriteFoot() will close it
      Response.Write "<div ID='" & TreeName & ItemID & "chlds'>"
      
      'JsCode only if IsIE and if the section is not open
      If IsIE then
            If IsOpn then
                  Response.Write "<script language='javascript'>ShowDisplay(" & TreeName & ItemID & "chlds);</script>"
            Else
                  Response.Write "<script language='javascript'>HideDisplay(" & TreeName & ItemID & "chlds);</script>"
            End If
      End If

End Sub

Sub WriteFoot()

      Response.Write "</div>"

End Sub

%>
I am not sure that I deserve points here--apart from pointing you to the IN part of the sql statement, I haven't really helped much (and for this I apologize--I have been swamped with work and haven't had much time to volunteer here lately).

FtB