2

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

1 Answer 1

0

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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