Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I am creating a sandboxed webpart which display a list from my SP. I have the following code

ASCX page...

<asp:Repeater ID="rptCarousel" runat="server" >
        <ItemTemplate>
            <div>
                <div class="sliderstuff">
                    <asp:Image ID="imgCarousel" runat="server" />
                    <h2><asp:Literal ID="litTitle" runat="server" /></h2>
                    <h3><asp:Literal ID="litDescription" runat="server" /></h3>
                    <div class="btnSlider">
                        <a href="#" ><asp:Literal ID="litLinktext" runat="server" /></a>
                    </div>
                </div>
            </div>
        </ItemTemplate>
    </asp:Repeater>

Then my code behind

 Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    Using site As New SPSite("http://cn-lap-hp-dev/")
        Using web As SPWeb = site.OpenWeb()
            Dim Imagelist As SPList = web.Lists("Home Page Carousel")

            rptCarousel.DataSource = Imagelist.Items.GetDataTable()
            rptCarousel.DataBind()


        End Using
    End Using
End Sub

and

 Protected Sub rptCarousel_ItemDataBound(ByVal sender As Object, ByVal e As RepeaterItemEventArgs) Handles rptCarousel.ItemDataBound
    Dim litTitle As Literal
    Dim item As SPListItem = DirectCast(e.Item.DataItem, SPListItem)


    'Find and initialise our elements
    litTitle = DirectCast(e.Item.FindControl("hypCompetitionID"), Literal)

    'Now add this record to the datarow
    litTitle.Text = "Test"

End Sub

Pretty simple i think but I cannot get the webpart to work when deployed...if i remove the "Handles rptCarousel.ItemDataBound" the webpart renders but with no data?? Anyone any ideas?

S

share|improve this question
add comment

1 Answer

up vote 0 down vote accepted

Almost there, I would use the following.

Protected Sub rptCarousel_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.RepeaterItemEventArgs) Handles rptCarousel.ItemDataBound
    Dim litTitle As Literal

    Dim drv As DataRowView
    'Now add this record to the datarow
    drv = DirectCast(e.Item.DataItem, DataRowView)

    'Find and initialise our elements
    litTitle = DirectCast(e.Item.FindControl("litTitle"), Literal)

    'Now set our values
    litTitle.Text = drv("Title").ToString()


End Sub
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.