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

This is driving me insane! Done this many times as a .Net developer but can't seem to get it working in a SharePoint webpart.

Page load code...

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 the repeater code

Protected Sub rptCarousel_ItemDataBound(source As Object, 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

Once i have deployed the webpart is running ok, its finding the SP list and it knows I have 3 items in my list (from the DIV's that are displaying by viewing source) but it will not display the data...is there any other way to debug this?

UPDATE:

WOW! Please ignore my stupidness! would help i had some content in my title eh?! The above works if anyone wants to use it.

However I need to display image but cant convert the Object to an image?

share|improve this question
    
When you say you can't convert the object to an image what do you mean? Do you have a field in the list which holds an image URL? –  PlanetWilson Jul 16 '12 at 10:34
    
Just sorted this, just forgot to convert to string...imgCarousel.ImageUrl = "Home%20Page%20Carousel/" & drv("LinkFilename").ToString() –  Stephen Jul 16 '12 at 11:40
add comment

1 Answer 1

The above code works... But you need to make sure you have content in the list you're referencing! I had records but no Title for litTitle.Text = drv("Title").ToString(). Once I added some content to the Title it worked.

Also need to remember to ToString() everything that comes out.

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.