views:

19

answers:

1

I need to create a repeater section that will show 4 columns - First Name, Last Name, a link based off of stored column data that says.

All the data plus some extra not being used is in a players profile. How do I link the data on the code-behind to the repeater control with the databinders?

I am using visual studio 2008, VB.NET for the code behind.

A: 

Have you considered using a DataGrid instead of a repeater? Here's a bit of a breakdown on when to use each.

http://msdn.microsoft.com/en-us/library/aa479015.aspx

To more directly answer your question you'll need to set the Repeater's DataSource property to a DataView or an ArrayList. As such:

 Sub Page_Load(Sender As Object, e As EventArgs)
        If Not IsPostBack Then
            Dim values As New ArrayList()

            values.Add(New PositionData("Microsoft", "Msft"))
            values.Add(New PositionData("Intel", "Intc"))
            values.Add(New PositionData("Dell", "Dell"))

            Repeater1.DataSource = values
            Repeater1.DataBind()

            Repeater2.DataSource = values
            Repeater2.DataBind()
        End If
    End Sub

    Public Class PositionData

        Private myName As String
        Private myTicker As String        

        Public Sub New(newName As String, newTicker As String)
            Me.myName = newName
            Me.myTicker = newTicker
        End Sub        

        Public ReadOnly Property Name() As String
            Get
                Return myName
            End Get
        End Property        

        Public ReadOnly Property Ticker() As String
            Get
                Return myTicker
            End Get
        End Property
    End Class
cazlab
The PositionData is not reconized. Do I need to import something or call that another way?I am using VB.Net
JPJedi
Terribly sorry, @JPJedi, I left a bit out, but I've edited my post and added it. The entire example is here: http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.repeater.aspx#data_binding
cazlab