The DataList tag, like the Template tag, is a View control that is used for displaying and interacting with records from your datasource. It is used in essentially the same manner as the Template tag and can be used together with the Template tag within your templates. Like the Template tag, it contains the data commands and layout instructions for your display and 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. The primary difference between the DataList and Template is that the DataList allows you to layout your records in a grid pattern.
Record1 Record2 Record3
Record4 Record5 Record6
Record7 Record8 ----- OR ---- Record1 Record4 Record7 Record2 Record5 Record8 Record3 Record6
This type of layout is handy for scenarios like displaying a list of images or products where you want to control the specific number of columns and the order in which they're displayed.
You can use multiple DataList 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:DataList
AddRoles="DNNRoleName1,DNNRoleName2"
Ajax="True|False"
ConnectionString="string"
DeleteRoles="DNNRoleName1;DNNRoleName2"
DetailRoles="DNNRoleName1;DNNRoleName2"
EditRoles="DNNRoleName1;DNNRoleName2"
ID="string"
RepeatColumns="integer"
RepeatDirection="Horizontal|Vertical"
RepeatLayout="Table|Flow"
UsePaging="True|False">
<ListDataSource CommandText="string"
ConnectionString="string"/>
<DetailDataSource CommandText="string"
ConnectionString="string"/>
<DeleteCommand CommandText="string" />
<Pager> ... </Pager>
<SearchSort>...</SearchSort>
<HeaderTemplate>...</HeaderTemplate>
<ItemTemplate>...</ItemTemplate>
<AlternatingItemTemplate>...</AlternatingItemTemplate>
<SeparatorTemplate>...</SeparatorTemplate>
<FooterTemplate>...</FooterTemplate>
<DetailTemplate>...</DetailTemplate>
<NoItemsTemplate>...</NoItemsTemplate>
</xmod:DataList>
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:DataList... 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 DataList 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:DataList>
tag or the current DotNetNuke database if the DataList tag doesn't define a connection. As with the DataList 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:DataList>
tag or the current DotNetNuke database if the DataList doesn't define a connection. As with the DataList tag, you can use the [[ConnectionString:connectionName]]
token to use a connection defined in the web.config file.<parameter>
tags like the <ListDataSource
><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:DataList AddRoles="SampleRole1;SampleRole2">
<ListDataSource commandtext="SELECT * FROM Users" />
<DetailDataSource commandtext="SELECT * FROM Users WHERE
UserID=@UserID" />
<HeaderTemplate>
<h1>Users List</h1>
</HeaderTemplate>
<ItemTemplate>
User's Name: [[FirstName]]
[[LastName]] <br />
<xmod:detaillink text="More...">
<parameter name="UserID" value='[[UserID]]' />
</xmod:detaillink>
</ItemTemplate>
<AlternatingItemTemplate>
User's Name:
[[FirstName]] [[LastName]] <br />
<xmod:detaillink text="More...">
<parameter name="UserID" value='[[UserID]]' />
</xmod:detaillink>
</AlternatingItemTemplate>
<FooterTemplate>
</FooterTemplate>
<DetailTemplate>
<h1>This is the detail view</h1>
User's Name: [[FirstName]] [[LastName]]
</DetailTemplate>
<NoItemsTemplate>
<span class="NormalRed">Sorry. No Records Were Found</span>
</NoItemsTemplate>
</xmod:DataList>