Repeater not repeating :0) (asp.net)(vb)
- by Phil
Morning stackoverflow,
I have a repeater, with the following code in my aspx page;
<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>
Then I have this code in my aspx.vb to get the data;
If did = 0 Then
s = "sql works on db server"
x = New SqlCommand(s, c)
x.Parameters.Add("@contentid", Data.SqlDbType.Int)
x.Parameters("@contentid").Value = contentid
c.Open()
r = x.ExecuteReader
r.Read()
Contactinforepeater.DataSource = r
Contactinforepeater.DataBind()
End If
c.Close()
r.Close()
If Not did = 0 Then
s = "sql works on db 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
r.Read()
Contactinforepeater.DataSource = r
Contactinforepeater.DataBind()
End If
r.Close()
c.Close()
If 'did' is or is not '0' I still get no data outputted to the page. I just get the 'contact information' h1 header from the header template.
I've tested the value of s in sqlsms and it works fine. Position, surname, telephone, fax, email all exist in the db. The particular page I am checking exists and has 1 set of contact information attached.
Where am I going wrong?
Thanks!
ps. Does my syntax appear correct?
pps. I am also open to different ways of achieving the same result. I tried via an sqldatasource but ran into problems when using variables as params (there is no option to select them, only controls, querystring etc)