Welcome to WindowsClient.net | Sign in | Join

Ken Tucker

Visual Basic MVP

Sponsors





  • advertise here

How to Dynamically add bound controls to a Data repeater

In the datarepeater's ItemCloning event you have the option to add bound controls to the datarepeater item.  For this example I have a datarepeater named datarepeater1.  I am using Linq to Sql to get data from the northwind database employee table

 

Public Class Form1

    Dim bs As New BindingSource

 

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

 

        Dim db As New NorthwindDataContext

 

        Dim q = From emp In db.Employees Select emp

 

        bs.DataSource = q

 

        DataRepeater1.DataSource = bs

    End Sub

 

    Private Sub DataRepeater1_ItemCloning(ByVal sender As Object, ByVal e As Microsoft.VisualBasic.PowerPacks.DataRepeaterItemCloneEventArgs) Handles DataRepeater1.ItemCloning

        Dim lbl As New Label

        Dim b As New Binding("Text", bs, "LastName")

        lbl.DataBindings.Add(b)

 

        e.Source.Controls.Add(lbl)

    End Sub

End Class

 

Comments

No Comments

Leave a Comment

(required) 

(required) 

(optional)

(required) 

Page view counter