ASP.net repeater control with SQLDataReader as data source

Posted by PhilSando on Geeks with Blogs See other posts from Geeks with Blogs or by PhilSando
Published on Thu, 22 Apr 2010 06:56:36 GMT Indexed on 2010/04/22 8:14 UTC
Read the original article Hit count: 218

Filed under:

Here is the markup for the repeater control and its templates:

<asp:Repeater ID="Repeater" runat="server">
<HeaderTemplate>
<table>
<tr>
<td colspan="3"><h2>Header information:</h2></td>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td><%#Container.DataItem%></td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>

 Here is the code to populate it with data:

  SQLString = "select something from foo where something"
            SQLCommand = New SqlCommand(SQLString, SQLConnection)
            SQLConnection.Open()
            SQLDReader = SQLCommand.ExecuteReader
            If SQLDReader.HasRows Then
                Contactinforepeater.DataSource = SQLDReader
                Contactinforepeater.DataBind()
            End If
        End If
        SQLConnection.Close()
        SQLDReader.Close()

© Geeks with Blogs or respective owner