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.


Question:
How can I format numbers and date/times using ASP.NET? For example, I want to format a number as a currency.

Views:
964,702

Question:
I am using Access and getting a 80004005 error (or a [Microsoft][ODBC Microsoft Access Driver] The Microsoft Jet database engine cannot open the file '(unknown)' error) when trying to open a connection! How can I fix this problem?

Views:
233,530

Question:
How do I display data on a web page using arrays instead of Do...While...MoveNext...???...

Views:
186,006

Question:
When I get a list of all files in a directory via the FileSystemObject, they aren't ordered in any reasonable way. How can I sort the files by name? Or by size? Or by date created? Or...

Views:
168,750

Question:
Can I send emails without using CDONTS?

Views:
130,322

Question:
How can I convert a Recordset into an array? Also, how can I convert an array into a Recordset?

Views:
238,089

Question:
How can I quickly sort a VBScript array?

Views:
230,033

Question:
How can I find out if a record already exists in a database? If it doesn't, I want to add it.

Views:
183,511

Question:
For session variables to work, must the Web visitor have cookies enabled?

Views:
133,635

Question:
How can I remove multiple spaces between words in a string? That is, if I have: Hi    there how can I get: Hi there?

Views:
129,557


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()
    dlPopularFAQs.DataSource = myCommand.ExecuteReader(CommandBehavior.CloseConnection)
    dlPopularFAQs.DataBind()	
  End Sub
</script>

<asp:DataList runat="server" id="dlPopularFAQs" 
                Width="85%" Border="1"
                HorizontalAlign="Center"
                Font-Name="Verdana" CellPadding="4"
                Font-Size="10pt"
                RepeatColumns="5" >
   <ItemTemplate>
     <b>Question:</b><br />
     <%# DataBinder.Eval(Container.DataItem, "Description") %>
     <p>
     <b>Views:</b><br />
     <%# DataBinder.Eval(Container.DataItem, "ViewCount", "{0:#,###}") %>
   </ItemTemplate>
</asp:DataList>	


[Return to the article]