ASP.net Repeater Control Problem (nothing outputted from datasource(sqldatareader))
Posted
by Phil
on Stack Overflow
See other posts from Stack Overflow
or by Phil
Published on 2010-04-13T08:31:39Z
Indexed on
2010/04/13
8:43 UTC
Read the original article
Hit count: 309
I have the following code to get the repeaters' data in my usercontrol (content.ascx.vb):
If did = 0 Then
s = "select etc (statement works on server)"
x = New SqlCommand(s, c)
x.Parameters.Add("@contentid", Data.SqlDbType.Int)
x.Parameters("@contentid").Value = contentid
c.Open()
r = x.ExecuteReader
If r.HasRows Then
Contactinforepeater.DataSource = r
End If
c.Close()
r.Close()
Else
s = "select etc (statement works on server)"
x = New SqlCommand(s, c)
x.Parameters.Add("@contentid", SqlDbType.Int)
x.Parameters("@contentid").Value = contentid
x.Parameters.Add("@did", SqlDbType.Int)
x.Parameters("@did").Value = did
c.Open()
r = x.ExecuteReader
If r.HasRows Then
Contactinforepeater.DataSource = r
c.Close()
r.Close()
End If
End If
Then I have the following repeater control markup in my usercontrol (content.ascx):
<asp:Repeater ID="Contactinforepeater" runat="server">
<HeaderTemplate>
<h1>Contact Information</h1>
</HeaderTemplate>
<ItemTemplate>
<table width="50%">
<tr>
<td colspan="2"><%#Container.DataItem("position")%></td>
</tr>
<tr>
<td>Name:</td>
<td><%#Container.DataItem("surname")%></td>
</tr>
<tr>
<td>Telephone:</td>
<td><%#Container.DataItem("telephone")%></td>
</tr>
<tr>
<td>Fax:</td>
<td><%#Container.DataItem("fax")%></td>
</tr>
<tr>
<td>Email:</td>
<td><%#Container.DataItem("email")%></td>
</tr>
</table>
</ItemTemplate>
<SeparatorTemplate><br /><hr /><br /></SeparatorTemplate>
</asp:Repeater>
When I insert this usercontrol into default.aspx with this code:
<%@ Register src="Modules/Content.ascx" tagname="Content" tagprefix="uc1" %>
and
<form id="form1" runat="server">
<div>
<uc1:Content ID="Content" runat="server" />
</div>
</form>
I do not get any error messages but the expected content from the database is not displayed. Can someone please show me the syntax to get this working or point out where I am going wrong?
Thanks in advance!
© Stack Overflow or respective owner