APNSoft - Web Controls, components for ASP.NET Home Help Center Contact Us
About UsProductsDownloadsPurchase
Support

DataGrid
Version 3.1



What's New
Overview
Features
Reference Book
Licensing
Support



Populating with Data
Columns   (general)
Columns   (templates)
Rows
Bottom Bar
Layout and Behavior
Exporting
Skins




Various parts of the DataGrid can be configured by using templates. Templates are easy to use powerful tools, which allow changing component’s appearance and behaviour flexibly on developer’s demand.


Templates applied to columns.

  • HTML Template

    HTML Template is a regular text file with HTML tags and special Active Blocks, instead of which data is inserted. Active Blocks examples:

    $GridID$ displays a unique Grid's identifier.
    $RowID$ displays a unique row's identifier.
    $CellValue$ displays the current Cell value.
    $CustomerID$ displays data from the column "CustomerID".
    $ColumnName$ displays the current column name.

    This example demonstrates how to merge data from various columns by using the HTML Template with Active Blocks.

  • XSL Template

    XSL Template is a file similar to HTML template, which can include XSL tags for major flexibility. XSL template, as well as HTML template can include special Active Blocks for data display.

    XSL Templates allow comparing/modifying data without a loss in performance. For example, under conditional formatting you must first analyze values of fields and then apply the formatting.

    XSL Template must include a section "xsl:template" with name "Main". A template example provided below analyzes column's "Quantity" values and fills it with red colour if there are more than 20.

    <xsl:template name="Main">
        <xsl:choose>
            <xsl:when test="$Quantity$ &gt; 20">
                <font color="red">$Quantity$</font>
            </xsl:when>
            <xsl:otherwise>$Quantity$</xsl:otherwise>
        </xsl:choose>
    </xsl:template>
    

    This example demonstrates how to use the XSL Template.

  • ASCX Template (User Control)

    ASCX Template is most flexible because it allows developer to organize and format column data by using the preferred programming language (C# or VB.NET). ASCX Template must include the field GridRow which is declared as public:
    
    [C#]
    
    public APNSoft.WebControls.GridColumn GridColumn = null;
    public APNSoft.WebControls.GridRow GridRow = null;
    
    [VB.NET]
    
    Public GridColumn As APNSoft.WebControls.GridColumn = Nothing
    Public GridRow As APNSoft.WebControls.GridRow = Nothing
    
    
    The component automatically sets this field value for each row.
    Please see this example.

Template is applied to a column by using of the Template property. The DataGrid component automatically identifies the type of applicable template (HTML or XSL).



Template applied to Bottom Bar.

This template is an XML file, which defines the structure and the layout of elements on Bottom Bar. Template is applied to a Bottom Bar by using the Template property. A template example can be found here.

Template's items:

Spacer sets the space in pixels. Example:

<Spacer Width="5" />

Button places the button for a certain action. Supports the click and double-click actions. There are several predefined buttons:

<Button Action="PageFirst" Title="First Page" EventType="Click" />
<Button Action="PagePrev" Title="Previous Page" EventType="Click" />
<Button Action="PageNext" Title="Next Page" EventType="Click" />
<Button Action="PageLast" Title="Last Page" EventType="Click" />
<Button Action="RowNew" Title="New Row" EventType="Click" />
<Button Action="ExportToExcel" Title="Export to Excel" EventType="DoubleClick" />
<Button Action="ExportToHTML" Title="Export to HTML" EventType="DoubleClick" />

Also you can extend Bottom Bar with custom buttons, which make DataGrid more relevant to users. Each custom button is defined by a single XML node in the XML template applied to Bottom Bar and one or two icon files, which are all stored in the Grid's Skin Folder. Example:

<Button Action="Custom" Title="Refresh" Function="dg.Refresh('dg1');" Icon="Refresh.gif" />

This example above displays the single icon for button: the Refresh.gif file. If you want to use additional icon for hovered button you should place the file RefreshOver.gif in the Skin Folder. Filename for hovered button is the name of inactive icon concatenated with the Over word.

Info is an information panel for display, for example, page number. Examples:

<Info Data="Pages" Title="Pages">$PageNumber$ / $PagesInTotal$</Info>
<Info Data="Rows" Title="Rows">Rows $ItemFirst$ to $ItemLast$ of $ItemsInTotal$.</Info>

Separator displays a vertical line. Example:

<Separator />

StatusBar displays the status bar. Example:

<StatusBar Title="Status Bar" 
	MsgReady="Ready" 
	MsgLoading="Loading..." 
	MsgInserting="Inserting..." 
	MsgUpdating="Updating..." 
	MsgDeleting="Deleting..." 
	MsgProcessing="Processing..." 
	MsgNoRecords="No records to display." 
/>



Templates applied to Context Menu.

Template for Context Menu is an XML file with items and separators. It is applied by using the properties GridContextMenuHeader.Template and GridContextMenuRow.Template. Context Menu style can be customized by editing CSS classes included in the CSS Style (CSSStyle.CSS) which is located in the Skin Folder. Template examples you can found here.

<ContextMenu>
  <item id="ir1" title="Edit row '$RowID$'" onclick="dg.OpenFormForUpdate('$RowID$');" 
    icon="CntMnuEdit.gif" iconWidth="16" iconHeight="16" />
  <item id="ir2" title="Delete row '$RowID$'" onclick="dg.DeleteRow('$RowID$');" 
    icon="CntMnuDelete.gif" />
  <separator id="sr1" />
  <item id="ir3" title="Add new row" onclick="dg.OpenFormForInsert();" 
    icon="CntMnuNew.gif" />
</ContextMenu>


Template elements and attributes:
  • <ContextMenu/> - the root element for entire template.
  • <item/> - one menu item element.
  • <separator/> - element for separator.
  • id - is used in order to ensure uniqueness.
  • title - specifies the text (caption) displayed for the menu item.
  • onclick - specifies the client side procedure which is fired when the user clicks the left mouse button on the item.
  • icon - specifies the name of the one item's icon image. The icon image displayed at the left side of the menu item. The icon images must be located in the Skin Folder as specified by the SkinFolder property.
  • iconWidth, iconHeight - one item's icon image width and height. This attributes can be specified only once if the menu uses icons with identical width and height.
Attention! Element names and attributes are case-sensitive. Be careful when you're typing in your data.

Template for Context Menu can include special Active Blocks, instead of which data is inserted. Available Active Blocks:

$GridID$ displays a unique Grid's identifier.
$RowID$ displays a unique row's identifier.
$ColumnIndex$ displays the current column index.
$ColumnName$ displays the current column name.
$CellValue$ displays the content of the current cell.
$CellValueText$ displays the text of the current cell.
$CellValueTextShort$ displays the short text of the current cell.
$CellValueEncoded$ displays the encoded text of the current cell.
    This value can be used as a parameter for JavaScript function.
    To decode this value, use the dg.DecodeCellValue(CellValue) client-side procedure.






  © 2003-2010 APNSoft. All rights reserved. Table of Contents   Terms of use   Contact Us   Help Center