views:

94

answers:

1

I have my repeater item template:

<asp:Repeater ID="Linksrepeater" runat="server">
<HeaderTemplate><h2>Links</h2><ul>
</HeaderTemplate>
<ItemTemplate>
<li><%#Container.DataItem("Category")%></li>
</ItemTemplate>
<FooterTemplate>
</ul>
</FooterTemplate>
</asp:Repeater>

Hooked up to:

s = "sql"
        x = New SqlCommand(s, c)
        x.Parameters.Add("@contentid", SqlDbType.Int)
        x.Parameters("@contentid").Value = contentid
        c.Open()
        r = x.ExecuteReader
        If r.HasRows Then
            Linksrepeater.DataSource = r
            Linksrepeater.DataBind()
        End If

        c.Close()
        r.Close()

When I run the code I get: Invalid Cast Exception was not handled by user code (Conversion from string "category" to type 'Integer' is not valid.)

I'm not sure how / why it is trying to convert "Category" to integer as in the db it is a string.

Can you please tell me how to avoid this error? thanks.

EDIT:

The same error occurs if I try <%#Container.DataItem("URL")%>

A: 

Are you sure this snippet is correct?

<%# Container.DataItem("Category") %>

Try this instead:

<%# Eval("Category") %>

or (changing MyObject to your class name)

<%# (Container.DataItem as MyObject).Category %>
Artiom Chilaru