Simple DataList Demo

This demo illustrates how the DataList's RepeatColumns property can be used to display multiple DataSource records per HTML <table> row. Specifically, in this demo 5 records are shown per table row.



Source Code
<% @Import Namespace="System.Data" %>
<% @Import Namespace="System.Data.SqlClient" %>
<script language="vb" runat="server">
  Sub Page_Load(sender as Object, e as EventArgs)
    BindData()
  End Sub
	
	
  Sub BindData()
    '1. Create a connection
    Dim myConnection as New SqlConnection(ConfigurationSettings.AppSettings("connectionString"))

    '2. Create the command object, passing in the SQL string
    Const strSQL as String = "sp_Popularity"
    Dim myCommand as New SqlCommand(strSQL, myConnection)

    'Set the datagrid's datasource to the datareader and databind
    myConnection.Open()
    rptULforFAQs.DataSource = myCommand.ExecuteReader(CommandBehavior.CloseConnection)
    rptULforFAQs.DataBind()	
  End Sub
</script>

<asp:Repeater runat="server" id="rptULforFAQs">
   <HeaderTemplate>
     <ul>
   </HeaderTemplate>
   <ItemTemplate>
     <li><%# DataBinder.Eval(Container.DataItem, "Description")%></li>
   </ItemTemplate>
   <FooterTemplate>
     </ul>
   </FooterTemplate>
</asp:Repeater>	


[Return to the article]