DataGrid

A grid is a standard way to display DB records in an X-Y manner. Let's see a basic way of displaying a grid of records using the DataGrid control of VS.Net -

<!--T_grid_1.aspx-->

<%@ Import Namespace="System.Data.OLEDB" %>
<script language="VB" runat="server">
Sub Page_Load(Src As Object, E As EventArgs)
Dim strConn as string ="PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA SOURCE=" & server.mappath("/Tornado/DB/NWIND.mdb")
Dim strSQL as string ="select employeeid,lastname,firstname,reportsto from employees"
Dim Conn as New OLEDBConnection(strConn)
Dim Cmd as New OLEDBCommand(strSQL,Conn)
   Conn.Open()
   myDataGrid.DataSource = Cmd.ExecuteReader()
   myDataGrid.DataBind()
   Conn.close
End Sub
</script>
<html>
<body>
<ASP:DataGrid id="MyDataGrid" runat="server">
   <HeaderStyle HorizontalAlign="Center" ForeColor="White" BackColor="Black"></HeaderStyle>
</asp:DataGrid>
</body>
</html>
 

Now, let's see the way to do it in Tornado.

<!--T_grid_2.aspx-->

<script language='vb' runat='server'>
Sub Page_Load(Source as Object, E as EventArgs)
Dim MyGrid As New Tornado.Z()
   MyGrid.dbSKin = "medical"
   Mygrid.dbDSN= "Nwind.Mdb"
   Mygrid.dbSQL= "SELECT employeeid,lastname,firstname,reportsto From Employees"
   MyGrid.dbTextHolder = "Title=Basic Grid Display"
   MyGrid.ASPdbNET()
End Sub
</script>
 

You might notice that this Tornado display page has some built-in nice colors, title and record navigation without any programming. To produce the equivalent of this using the standard controls in VS will take considerable effort. But the more important point is that many of the programming chores are hidden and that would allow you to concentrate on the business logic which in this case is the datasource and the query.

Does Tornado work with VS controls? See it for yourself -

<!--T_grid_5.aspx-->

<%@ Import Namespace="System.Data" %>
<script language="vb" runat="server">

Sub grid_Page(Sender As Object, E As DataGridPageChangedEventArgs)
grid.CurrentPageIndex = e.NewPageIndex
grid.DataBind()
End Sub

Sub Page_Load(Source as Object, E as EventArgs)
dim ds as new dataset()
Dim TT As New Tornado.Z()
With TT
.dbQP="S=2|Ps=-1"
.dbTextHolder="Title=ASPdb DataGrid Demo|Sub=Tornado works with Datagrid"
.dbDSN = "nwind.mdb"
.dbSQL = "Select ProductID, ProductName, UnitPrice From products"
grid.DataSource = .ASPdbDS()
grid.DataBind()
End With'...Use DataGrid with Tornado.
End Sub
</script>

<body>
<form runat="server">
   <asp:DataGrid id="grid" runat="server"
   CssClass="R1"
   PageSize="5"
   OnPageIndexChanged="grid_Page"
   AllowPaging="True"
   AutoGenerateColumns="True">
   <HeaderStyle HorizontalAlign="Center" CssClass="GH"></HeaderStyle>
   <AlternatingItemStyle CssClass="R2"></AlternatingItemStyle>
   <PagerStyle mode="NumericPages" horizontalalign="Left" CssClass="CC1"></PagerStyle>
   </asp:datagrid>
</form>
</body>
 

If you are still thinking about how to reproduce the equivalent of a Tornado output using VS.Net, I hope the following example will put the issue to rest. This advanced example consists of 2 files - Master and Slave displaying embedded grid, aggregates and a spinning pie chart of the drill down details! This 38 lines of code can produce a very fancy application that is beyond the reach of many web programmers.

Master and Slave in one file - Display a master grid with an embedded slave grid

<!--T_grid_3.aspx-->

<body onLoad="self.focus()">
<script language="vb" runat="server">
Sub Page_Load(Source as Object, E as EventArgs)
Dim myself = Request.ServerVariables("SCRIPT_NAME")
   If Request.QueryString("details") = "" Then
   Dim pop As String = "<A HREF='" & myself & "?Details=#0#' Target='Details' onClick=""window.open('','Details', 'width=500, height=500, left=400, top=400, directories=no, menubar=no, toolbar=no, status=no, resizable=yes')"">#0#</A>"
   Dim E63 As New tornado.z()
   With E63
      .dbQP = "U=60| S=8| M=G| D=Nwind| GDF=CustomerID,CompanyName,ContactName"
      .dbEmbeddedGridMagicCell = "(;![]#|~/+{})fi=OrderID|mac=" & pop
      .dbGridMagicCell = "(;![]#|~/+{})field=CompanyName|macro=#1#<br>#4#<br>#5#, #7#<p>#2#<br>#4#<br>#9#! field=ContactName|Macro=SQL:SELECT OrderID,OrderDate,RequiredDate,ShippedDate from orders where customerID= '#0#'"
      .dbNameMap = "field=CustomerID|alias=ID,field=CompanyName|alias=Customer,field=ContactName|alias=Orders"
      .dbEmbeddedGridNameMap = "field=OrderID|alias=ID,field=OrderDate|alias=Ordered,field=RequiredDate|alias=Required,field=ShippedDate|alias=Shipped"
      .dbSQL = "SELECT CustomerID,CompanyName,ContactName,ContactTitle,Address,City,Region,PostalCode, Country,Phone,Fax FROM Customers"
      .dbTextHolder = "Title=Tornado Demo - Advanced Master with embedded Charting Details|subtitle=Can you image you can do this with 30 lines of code without knowing too much about ASP or ASP.NET?"
      .ASPdbNET()
   End With
Else '..... here split master and slave
   Dim ID As String = Request.QueryString("Details")
   Dim E61 As New tornado.z()
   With E61
      .dbQP = "U=61| S=8| M=GC| PS=-1| Ni=None| D=Nwind.mdb"
      .dbGridMagicCell = "field=0|tag=align=middle,field=2|tag=align=right,field=4|tag=align=right,field=SubTotal|tag=align=right|macro=#SubTotal:currency#,field=Quantity|tag=align=right|macro=#quantity#"
      .dbCommonTables = "index=PID,PDesc|sql=Select ProductID,ProductName from Products"
      .dbLookUpFlds = "field=1|keyindex=PID|Lookupindex=PDesc"
      .dbSQL = "SELECT ProductId,ProductId as Description,UnitPrice,Quantity,Discount,UnitPrice*Quantity*(1 -Discount) as SubTotal from [order details] where OrderID=" & ID
      .dbAggregate = "(~^:)Fields=3^5|AggType=SUM|BottomTemp=<tr bgcolor=yellow align=right><td ColSPAN=3><b>Total </b></td><td>[[3:###,###]]<td><td Colspan=2 align=right>[[5:Currency]]</td>|CellFormat=Val"
      .dbTextHolder = "Title=Order Details for Order " & ID
      .dbChartData = "dataset0yValues=#(5)#| dataset0Labels=#1#"
      .dbChartParams = "Type=26| TitleString='Description vs SubTotal Spinning Plot'| titleFont='Arial,14,1'| Archieve=/tornado/Jars/|Width=350| Height=350| 3D=True| textLabelsOn=True| pieWidth=.40| pieHeight=.40| valueLabelsOn=True"
      .dbGridTemplate = "<center>[[Grid]]<P>[[Chart]]</center>"
      .ASPdbNET()
   End With
End If
End Sub