ASP.net repeater control with SQLDataReader as data source
- by PhilSando
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()