ASP.Net - DataList

The Datalist control, is pretty cool.

I think it’s weaker then the grid view, it serves as a simple list mechanism.

Here’s a basic example

1
2
3
4
5
<asp:DataList ID="dlResultList" runat="server">
<ItemTemplate>
<%#DataBinder.Eval(Container.DataItem, "Title")%>
</ItemTemplate>
</asp:DataList>

You can populate the control using a datasource. But I perfer binding it manaully. That code looks something like the following.

1
2
3
4
5
6
7
8
9
10
11
Dim sql As String _
= "select Title " _
& "from tblResultSet " _
& "where ntUserName='" & SI.sys.ntUserName & "' " _
& "and ObjectName='" & lblAssetType.Text.ToString & "'"

Dim ds As DataSet _
= SI.db.ds_Get(sql, "aspxConnectionSTring")

dlResultList.DataSource = ds.Tables(0)
dlResultList.DataBind()