Tornado Class Library

Special Features - Dynalist (Dynamic List)

What kind of applications should use Dynalist?

Imagine querying a used car database. You can ask the following -

You can make a lot of queries before you reach the target vehicle. Instead we use Dynalist to query 'what is in stock' and not 'is there any in stock'.

If any of the level of choices are not available, then the Dynalist will terminate.

The following is the example code of the main file -
We use some simple memory HTML codes as Input -

    Employee[[Level0]]<p>Customer ID[[Level1]]<p>Order Id[[Level2]]

We use an external aspx file to process the Output values -

    File=/Tnew/Doc/Manual/DynalistOutput.aspx

We specify short cut as table + field in each level. Remember that the field type wrapper must be correct as - Customerid is a string and Employeeid and Orderid is a number.

<script language="vb" runat="server">
Sub Page_Load(Source as Object, E as EventArgs)
  Dim InputHTML As String = "Employee[[Level0]]<p>Customer ID[[Level1]]<p>Order Id[[Level2]]"
  Dim TriggerAspx As String = "File=/Tnew/Doc/Manual/DynalistOutput.aspx"
  Dim Mydlist As New Tornado.Z
  With Mydlist
    .dbQP = "U=1|S=1|M=grid|Th=Dynamic List|D=Nwind"
    Dim s As String = "InputHtml=" & InputHTML & "|OutputAspx=" & TriggerAspx
    s &= ";Level=0|Label=[Select an Employee]|Table=employees|Field=Employeeid"
    s &= ";Level=1|Label=[Select a Customer Id]|Table=Orders|Field='Customerid'"
    s &= ";Level=2|Label=[Select an Order Id]|Table=Orders|Field=OrderId"
    .dbDynalist = s
    .ASPdbDynaList()
  End With
End Sub
</Script>


The following is the code of the Output file (DynalistOutput.aspx) which displays all the selected values of the Dynalist -

The Dynalist selected values in string array format can be retrieved from Get_DListLevelSelectedItem

<script language="VB" runat="server">
Sub Page_Load(Src As Object, E As EventArgs)
  Dim i as integer
  Dim GD As New Tornado.GetData
  Dim Sel() As String = GD.Get_DListLevelSelectedItem
  Response.write("<H1>Dynalist OutPut File</H1>")
  Response.Write("Your trigger value is - " & Request.Form("ASPdbDlistSubmit") & "<P>")
  For i = 0 To UBound(Sel)
    Response.Write("Your selected value for level " & i & " value is - " & Sel(i) & "<P>")
  Next
End Sub
</script>

 

The above example specifies only the table and field names and the system builds a simple SELECT... FROM ... SQL to perform the queries. When  you want to have full control and specify the exact SQL for the queries, you can use the SQL keyword to accomplish that.

Look at SQL0 for the first level. There are two fields selected - employeeid, FirstName & ' ' & Lastname
This is a case where the first field is the selected value and the second is the Lookup field. Instead of the employeeid (1,2,3...), now the Names of the employees will show up. This is very unique feature! So the rule is -

Define the SQL of the levels. If SQL fields > 1 then they will be used as Lookup Value/Text in select box.
 

<script language="VB" runat="server">
Sub Page_Load(Src As Object, E As EventArgs)
  Dim InputHTML As String = "Employee[[Level0]]<p>Customer ID[[Level1]]<P>Order Id[[Level2]]"
  Dim TriggerAspx As String = "File=/Tnew/Doc/Manual/DynalistOutput.aspx"
  Dim SQL0 As String = "Select employeeid, FirstName & ' ' & Lastname from employees"
  Dim SQL1 As String = "Select Customerid from Orders where employeeid = {{0}}"
  Dim SQL2 As String = "Select OrderId from Orders where Customerid='{{1}}' and Employeeid={{0}}"
  Dim Mydlist As New Tornado.Z
  With Mydlist
    .dbQP = "U=1|S=1|M=grid|Th=Dynamic List|D=Nwind.mdb"
    Dim s As String = "InputHtml=" & InputHTML & "|OutputAspx=" & TriggerAspx
        s &= ";Level=0|Label=[Select an Employee]|DropValueIndex=0|DropTextIndex=1|SQL=" & SQL0
        s &= ";Level=1|Label=[Select a Customer Id]|SQL=" & SQL1
        s &= ";Level=2|Label=[Select an Order Id]|SQL=" & SQL2
    .dbDynalist = s
    .ASPdbDynaList()
  End With
End Sub
</script>
 

In actual applications, it is more practical to include the Input and Output in the same main file. The following repeats the above example with In/Out source combined.

 

[vb]
<script language="VB" runat="server">
Sub Page_Load(Src As Object, E As EventArgs)
  Dim GD As New Tornado.GetData
'...We use input/output/program in the same file by scanning the request form and querystring
'...Myself is the url of this file
  Dim Myself As String = Request.ServerVariables("SCRIPT_NAME")
'...we use a simple memory template as an input file
  Dim InputHTML As String = "Employee[[Level0]]<p>Customer ID[[Level1]]<P>Order Id[[Level2]]"
'...We use the existing file as output file
  Dim TriggerAspx As String = Myself
'...test for trigger
  Dim QS As String = Request.QueryString("ASPdbDList_Trigger")
  Dim Trigger As Boolean = Not IsNothing(QS) AndAlso CBool(QS)
'...If not a trigger click then it must be normal
  If not Trigger Then
    Dim Mydlist As New Tornado.Z
    With Mydlist
      .dbQP = "U=1|S=1|M=grid|Th=Dynamic List|D=Nwind"
      Dim s As String = "InputHtml=" & InputHTML & "|OutputAspx=" & TriggerAspx
      s &= ";Level=0|Label=[Select an Employee]|Table=employees|Field=Employeeid"
      s &= ";Level=1|Label=[Select a Customer Id]|Table=Orders|Field='Customerid'"
      s &= ";Level=2|Label=[Select an Order Id]|Table=Orders|Field=OrderId"
      .dbDynalist = s
      .ASPdbDynaList()
    End With
  Else 'Detect Trigger click execute the following
    Dim i As Integer
'...Get the levels selections as well as the trigger value here. You can then process them your way.
    Dim Sel() As String = GD.Get_DListLevelSelectedItem
    Response.Write("Your trigger value is - " & Request.Form("ASPdbDlistSubmit") & "<br>")
    For i = 0 To UBound(Sel)
      Response.Write("Your selected value for level " & i & " value is - " & Sel(i) & "<br>")
    Next
  End If
End Sub
</script>

 

Remarks

 


Send comments on this topic.


Copyright 1998-2006 ASP-db