The template tag is the primary workhorse of XModPro. It contains the data commands and layout instructions for your display. Additionally, it enables you to specify who is allowed to add, edit, and delete records as well as who is allowed to view the details of records. You can use multiple Template tags, enabling you to have side-by-side (or however you want to lay them out using HTML) displays within the same module instance, each being fed by different datasources.
<xmod:template
AddRoles="DNNRoleName1,DNNRoleName2"
Ajax="True|False"
ConnectionString="string"
DeleteRoles="DNNRoleName1;DNNRoleName2"
DetailRoles="DNNRoleName1;DNNRoleName2"
EditRoles="DNNRoleName1;DNNRoleName2"
ID="string"
UsePaging="True|False">
<ListDataSource CommandText="string"
ConnectionString="string"/>
<DetailDataSource CommandText="string"
ConnectionString="string"/>
<DeleteCommand CommandText="string" />
<CustomCommands>
<DataCommand CommandName="string" CommandText="string" ConnectionString="string">
<Parameter Name="string" Value="string" />
</DataCommand>
</CustomCommands>
<Pager> ... </Pager>
<SearchSort>...</SearchSort>
<HeaderTemplate>...</HeaderTemplate>
<ItemTemplate>...</ItemTemplate>
<AlternatingItemTemplate>...</AlternatingItemTemplate>
<SeparatorTemplate>...</SeparatorTemplate>
<FooterTemplate>...</FooterTemplate>
<DetailTemplate>...</DetailTemplate>
<NoItemsTemplate>...</NoItemsTemplate>
</xmod:template>
Ajax: New to version 2.6, when this attribute is true, actions within the template tag will be performed without a full page refresh. This value is false by default. NOTE: buttons that postback such as the DetailButton (or DetailImage or DetailLink) or AddButton or DeleteButton or CommandButton, etc. must have their ID property set to function correctly. If you have to click twice on a button, for instance, make sure it's ID has been set.
ConnectionString: If you need to specify a SQL Server database other than the current DotNetNuke database, you can supply a connection string here. When specified, it serves as the default connection string for the ListDataSource and DetailDataSource. You can also use a connection string defined in the web.config file. To do so, use the ConnectionString token like so:
<xmod:template ... ConnectionString='[[ConnectionString:connectionName]]' ...>
<Pager>
tag.SELECT
command or a stored procedure. Supply the SQL command as the commandtext attribute. For stored procedures, use EXEC sprocName
. In the initial release, data sources can only point to the current DotNetNuke database. Also note that Bit columns are returned as True/False - not 1/0. The data source for list views is defined in the <ListDataSource>
tag while the data source for the detail view is defined in the DetailDataSource tag.ListDataSource: Provides the data for the template when it is displaying in list view. It accepts <parameter> tags to pass parameters as part of the command. The "alias" attribute is optional and is used to avoid conflicts or to accept a parameter with a specific name (the "name" attribute) but use a different parameter name in the command (the "alias" attribute). If no "alias" is specified, the "name" will be used.
Output Parameters: New to version 1.3, you can retrieve and use the value of SQL Output parameters. To do so, add the Direction="Output" to the <parameter> tag and specify a DataType and Size (required for Strings). See Example #4 and the Data Parameter Tokens Topic.
Examples:
#1 <ListDataSource CommandText="SELECT FirstName, LastName FROM Users" />
#2 <ListDataSource CommandText="SELECT FirstName, LastName FROM Users WHERE ZipCode = @zip"> <parameter name="zip" alias="zip" value="12345" /> </ListDataSource>
#3 <ListDataSource CommandText="EXEC GetUsers @zip"> <parameter name="zip" alias="zip" value="12345" /> </ListDataSource>
#4 <ListDataSource CommandText="GetEmploeesByDepartment" CommandType="StoredProcedure"> <parameter name="DepartmentId" value="32"/> <parameter name="DepartmentName" direction="Output" datatype="string" size="100" /> </ListDataSource>
You can optionally specify a ConnectionString for this data source. If none is specified, the default connection will be used - either the connection specified by the ConnectionString property of the parent <xmod:template>
tag or the current DotNetNuke database if the template doesn't define a connection. As with the template tag, you can use the [[ConnectionString:connectionName]]
token to use a connection defined in the web.config file.
<parameter>
tags like the <ListDataSource>
. You can optionally specify a ConnectionString for this data source. If none is specified, the default connection will be used - either the connection specified by the ConnectionString property of the parent <xmod:template>
tag or the current DotNetNuke database if the template doesn't define a connection. As with the template tag, you can use the [[ConnectionString:connectionName]]
token to use a connection defined in the web.config file.<parameter>
tags like the <ListDataSource
>CustomCommands: New to version 3. Custom commands allow you to execute commands on your data source beyond the standard list/detail/delete commands. For instance, you may use them to create an Approve Record button which would set the approval status on a record. Custom Commands are triggered using <xmod:CommandButton>, <xmod:CommandLink> and <xmod:CommandImage> controls. For the <Command> tag, specify the Name of the command and set the Type to Custom. When a custom command is executed, the page will postback to the server and XMod Pro will attempt to reload the resultset on the same page the user was on when the command button was clicked. In most cases this should update any values on that page that have been changed. An example is below:
<xmod:Template>
...
<CustomCommands>
<DataCommand CommandName="ChangeLastNameToSmith" CommandText="UPDATE Authors SET LastName='Smith' WHERE AuthorId=@AuthorId">
<Parameter Name="AuthorId" />
</DataCommand>
</CustomCommands>
...
<ItemTemplate>
<xmod:CommandButton Text="CustomCommand">
<Command Name="ChangeLastNameToSmith" Type="Custom">
<Parameter Name="AuthorId" Value='[[AuthorId]]' />
</Command>
</xmod:CommandButton>
...
</ItemTemplate>
...
</xmod:Template>
<Pager>
topic for more details.<SearchSort>
topic.[[FieldName]]
"FieldName" is the name of the field or column in your data source. This name is case sensitive and must match the field/column's name exactly. It must be surrounded by [[ and ]]. You can use the Field Token in many places. However, when you use it as the attribute value for an XMod Pro tag or other third party control, you must delimit the attribute value with single quotes, rather than double quotes. See the <xmod:detailbutton>
code in the example. When used in the <parameter>
tag, the attribute is written as: value='[[UserID]'
rather than: value="[[UserID]]"
. When using a Field Token with HTML tag attributes, this is not necessary.<xmod:template addroles="SampleRole1;SampleRole2">
<ListDataSource commandtext="SELECT * FROM Users" />
<DetailDataSource commandtext="SELECT * FROM Users WHERE
UserID=@UserID" />
<HeaderTemplate>
<ul>
</HeaderTemplate>
<ItemTemplate>
<li>
User's Name: [[FirstName]]
[[LastName]] <br />
<xmod:detaillink text="More...">
<parameter name="UserID" value='[[UserID]]' />
</xmod:detaillink>
</li>
</ItemTemplate>
<AlternatingItemTemplate>
<li class="AltItem">
User's Name:
[[FirstName]] [[LastName]] <br />
<xmod:detaillink text="More...">
<parameter name="UserID" value='[[UserID]]' />
</xmod:detaillink>
</li>
</AlternatingItemTemplate>
<FooterTemplate>
</ul>
</FooterTemplate>
<DetailTemplate>
<h1>This is the detail view</h1>
User's Name: [[FirstName]] [[LastName]]
</DetailTemplate>
</xmod:template>