如何在中继器部分创建列表?

发布于 2024-08-31 12:13:09 字数 155 浏览 2 评论 0原文

我需要创建一个转发器部分,它将显示 4 列 - 名字、姓氏、基于存储的列数据的链接。

所有数据加上一些未使用的额外数据都在玩家档案中。如何使用数据绑定器将代码隐藏上的数据链接到转发器控件?

我使用 Visual Studio 2008,VB.NET 作为后台代码。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

自此以后,行同陌路 2024-09-07 12:13:09

您是否考虑过使用 DataGrid 而不是中继器?
以下是关于何时使用每种方法的一些详细说明。

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

要更直接地回答您的问题,您需要将 Repeater 的 DataSource 属性设置为 DataView 或 ArrayList。像这样:

 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

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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文