Example
Source
Run as client-side object
With
DbNetGrid
you can create pivot tables to show summary information with ease
Register the component libraries
<%@ Register TagPrefix="DNL" Namespace="DbNetLink.Web.UI" Assembly="DbNetLink.DbNetGrid" %>
Server Control
<form id="Form1" name="Form1" method="post" runat="server"> <table> <tr> <td> <DNL:DbNetGrid id="dbnetgrid1" runat="server" ConnectionString = "sqlserver" PrimaryKeyColumn = "EmployeeID" SelectPart = "year(orderdate) year" Headings = " " EditRow = false Chart = "true" FromPart = "sales.salesorderheader join sales.salesorderdetail on sales.salesorderheader.salesorderid = sales.salesorderdetail.salesorderid" GroupBy = "year(orderdate)" OrderColumn = "year(orderdate)" > <GridColumnProperties> <DNL:ColumnProperty ColumnName="year" Property="backgroundColor" Value="gainsboro" ></DNL:ColumnProperty> <DNL:ColumnProperty ColumnName="year" Property="fontWeight" Value="bold" ></DNL:ColumnProperty> </GridColumnProperties> </DNL:DbNetGrid> </td> </tr> </table> </form>
Server-side script
/////////////////////////////////////////////////////////////// protected override void OnPreRender( EventArgs e ) /////////////////////////////////////////////////////////////// { string[] Months = {"January","February","March","April","May","June","July","August","September","October","November","December"}; string[] SelectPart = new string[12]; string[] Headings = new string[12]; DbNetGrid Grid = ((DbNetGrid) FindControl("dbnetgrid1")); for ( int i = 0; i < Months.Length; i++ ) { SelectPart[i] = "SUM(CASE WHEN MONTH(OrderDate) = " + (i+1).ToString() + " THEN LineTotal END) AS '" + Months[i] + "'"; Headings[i] = Months[i]; ColumnProperty CP = new ColumnProperty(); CP.ColumnName = Months[i]; CP.Property = "format"; CP.Value = "n"; Grid.GridColumnProperties.Add( CP ); } Grid.SelectPart = Grid.SelectPart + "," + String.Join(",", SelectPart); Grid.Headings = Grid.Headings + "," + String.Join(",", Headings); }