0

Hi guys,

I am stuck on my code. I am creating Repeater control dynamically. For some reason i cant really get it to work, Maybe someone can tell where i am going wrong. I have one class name "MultipleSelectCategoryRepeaterTemplate" this class will create the repeater Header, Item and Footer dynamic. In its item template it has another dynamic repeater. This inner repeater i cant bind its values.

Public Class MultipleSelectCategoryRepeaterTemplate
    Implements ITemplate

    Private _type As ListItemType
    Private _level As Integer
    Private _headerName As String
    Private Shared _lstMultipleSelectCategories As List(Of MultipleSelectCategory)

    Public Sub New(ByVal type As ListItemType, ByVal intLevel As Integer, ByVal strHeaderName As String, ByVal lstCategory As List(Of MultipleSelectCategory))
        _type = type
        _level = intLevel
        _headerName = strHeaderName
        _lstMultipleSelectCategories = lstCategory
    End Sub

    Public Sub InstantiateIn(container As Control) Implements ITemplate.InstantiateIn
        Dim ph As New PlaceHolder

        Select Case _type
            Case ListItemType.Header
                Dim strHtml As StringBuilder = New StringBuilder()

                strHtml.AppendFormat("<ul>")
                strHtml.AppendFormat("<li class='list-item-all'>")
                strHtml.AppendFormat("    <div class='checkbox'>")
                strHtml.AppendFormat("        <label>")
                strHtml.AppendFormat("            <asp:CheckBox runat='server' ID='cbxOption' data-toggle='CheckBoxAll'/>{0}", _headerName)
                strHtml.AppendFormat("        </label>")
                strHtml.AppendFormat("    </div>")
                strHtml.AppendFormat("</li>")

                ph.Controls.Add(New LiteralControl(strHtml.ToString()))
            Case ListItemType.Item

                Dim li As New HtmlGenericControl With {.ID = "liItem", .TagName = "li"}
                Dim dvCheckBoxWrapper As New HtmlGenericControl With {.TagName = "div"}
                Dim lbl As New HtmlGenericControl With {.TagName = "Label"}

                dvCheckBoxWrapper.Attributes.Add("class", "checkbox")

                lbl.Controls.Add(New CheckBox() With {.ID = "cbxOption"})
                lbl.Controls.Add(New Label() With {.ID = "lblOptionText"})
                dvCheckBoxWrapper.Controls.Add(lbl)
                li.Controls.Add(dvCheckBoxWrapper)

                ph.Controls.Add(li)

                Dim rptList As New Repeater() With {.ID = "rptList"}

                rptList.HeaderTemplate = New MultipleSelectCategoryListRepeaterTemplate(ListItemType.Header, _level + 1)
                rptList.ItemTemplate = New MultipleSelectCategoryListRepeaterTemplate(ListItemType.Item, _level + 1)
                rptList.FooterTemplate = New MultipleSelectCategoryListRepeaterTemplate(ListItemType.Footer, _level + 1)

                ph.Controls.Add(rptList)

                AddHandler ph.DataBinding, New EventHandler(AddressOf MultipleSelectCategory_ItemDataBound)
            Case ListItemType.Footer
                Dim strHtml As StringBuilder = New StringBuilder()

                strHtml.AppendFormat("</ul>")

                ph.Controls.Add(New LiteralControl(strHtml.ToString()))
        End Select

        container.Controls.Add(ph)
    End Sub

    Public Sub MultipleSelectCategory_ItemDataBound(ByVal sender As Object, ByVal e As EventArgs)
        Dim ph As PlaceHolder = CType(sender, PlaceHolder)
        Dim ri As RepeaterItem = CType(ph.NamingContainer, RepeaterItem)
        Dim rptList As Repeater = Nothing
        Dim mscItem As MultipleSelectCategory = ri.DataItem

        Dim strHtml As StringBuilder = New StringBuilder()

        If mscItem.ChildCategory Is Nothing Then
            Dim lbl As Label = TryCast(ri.FindControl("lblOptionText"), Label)
            rptList = TryCast(ri.FindControl("rptList"), Repeater)

            If Not lbl Is Nothing Then
                lbl.Text = mscItem.CategoryName
            End If

            If Not rptList Is Nothing Then
                rptList.DataSource = mscItem.List
                rptList.DataBind()
            End If
        Else

        End If

    End Sub
End Class

Dynamic Inner Repeater

Public Class MultipleSelectCategoryListRepeaterTemplate
    Implements ITemplate

    Private _type As ListItemType
    Private _level As Integer

    Public Sub New(ByVal type As ListItemType, ByVal intLevel As Integer)
        _type = type
        _level = intLevel
    End Sub

    Public Sub InstantiateIn(container As Control) Implements ITemplate.InstantiateIn
        Dim ph As New PlaceHolder

        Select Case _type
            Case ListItemType.Header
                Dim strHtml As StringBuilder = New StringBuilder()

                strHtml.AppendFormat("<ul>")

                ph.Controls.Add(New LiteralControl(strHtml.ToString()))
            Case ListItemType.Item
                ph.Controls.Add(New LiteralControl("<li>"))
                ph.Controls.Add(New LiteralControl("<div class='checkbox'>"))
                ph.Controls.Add(New LiteralControl("<label>"))
                ph.Controls.Add(New CheckBox() With {.ID = "cbxOption"})
                ph.Controls.Add(New Label() With {.ID = "lblOptionText"})
                ph.Controls.Add(New LiteralControl("</label>"))
                ph.Controls.Add(New LiteralControl("</div>"))
                ph.Controls.Add(New LiteralControl("</li>"))

                AddHandler ph.DataBinding, New EventHandler(AddressOf MultipleSelectItem_ItemDataBound)
            Case ListItemType.Footer
                Dim strHtml As StringBuilder = New StringBuilder()

                strHtml.AppendFormat("</ul>")

                ph.Controls.Add(New LiteralControl(strHtml.ToString()))
        End Select
    End Sub

    Public Sub MultipleSelectItem_ItemDataBound(ByVal sender As Object, ByVal e As EventArgs)
        Dim ph As PlaceHolder = CType(sender, PlaceHolder)
        Dim ri As RepeaterItem = CType(ph.NamingContainer, RepeaterItem)
        Dim lbl As Label = TryCast(ri.FindControl("lblOptionText"), Label)
        Dim item As ListItem = ri.DataItem

        If Not lbl Is Nothing Then
            lbl.Text = item.Text
        End If
    End Sub
End Class

Populating Outer Repeater

rptMultipleSelectCategory.HeaderTemplate = New MultipleSelectCategoryRepeaterTemplate(ListItemType.Header, 1, "All", lstMultipleSelectCategories)
        rptMultipleSelectCategory.ItemTemplate = New MultipleSelectCategoryRepeaterTemplate(ListItemType.Item, 1, "All", lstMultipleSelectCategories)
        rptMultipleSelectCategory.FooterTemplate = New MultipleSelectCategoryRepeaterTemplate(ListItemType.Footer, 1, "All", lstMultipleSelectCategories)

        rptMultipleSelectCategory.DataSource = lstMultipleSelectCategories
        rptMultipleSelectCategory.DataBind()

        upnlMultipleSelectCategory.Update()
2
Contributors
1
Reply
28
Views
1 Month
Discussion Span
Last Post by Michael_9
0

The Data( I see you need to draw controls for clear to work...)

Namespace Core
    Friend Module Func

        Public OkButton As Button
        Public CancelButton As Button
        Public ProgBar As ProgressBar

        Private Sub ProgressLoop()

            Do
                Func.ProgBar.PerformStep()
                Threading.Thread.Sleep(1)
            Loop

        End Sub
#Region "Constants"
        Public Const DataRoot As String = "C:\AFormData\"
        Public Const IMG_PATH As String = "C:\AFormData\img"
        Public Const LoadImage As String = "C:\AFormData\img\codemap_zps4115ff7e.jpg"
        Public Const LINE_TERMINATOR As String = ">>"
        Public Const LoadImageX As Integer = 0
        Public Const LoadImageY As Integer = 0
        Public Const LoadBarFailedMessage As String = "Loading Bar Denied"
        Public Const ResizeMessage As String = "Current Form Resizing"
        Public Const NoCommandMsg As String = "Not a command."

#End Region

#Region "Form Vars"
        Public Const CURRENT_FORM As Integer = 1
        Public Const PREVIOUS_FORM As Integer = 2
        Public IsInitialized As Boolean
        Public OkButtonLocationX As Integer
        Public OkButtonLocationY As Integer

        Public LoadingThread As Threading.Thread
#End Region

        Function ProgBarTime(ByVal form As Form1) As Integer
            Return form.ProgressTime
        End Function
        Function TboxLocCalc(ByVal form As Form1) As Point
            Return New Point(form.Width / 2 + 100, form.Height / 2 + 100)
        End Function
        Function TboxLocCalc2(ByVal form As Form1) As Point

            Return New Point(form.Width / 2 + 100, form.Height / 2)

        End Function
        Function ButtonLocCalc(ByVal form As Form1) As Point
            Return New Point(form.Width / 2 - 100, form.Height / 2 - 100)
        End Function
        Function Button2LocCalc(ByVal form As Form1) As Point
            Return New Point(Func.ButtonLocCalc(form).X - 100, Func.ButtonLocCalc(form).Y)
        End Function

        Function InitializeFunc(ByVal form As Form1) As Boolean
            Dim Ok, Cancel As Button

            Ok = New Button
            Cancel = New Button

            OkButton = Ok
            CancelButton = Cancel

            If IsNothing(form) Then
                Return IsInitialized = False
            Else
                Debug.Write("Something else?")
            End If

            If form.InitializeOk = True Then
                form.Width = 640
                form.Height = 480
                form.CurrentString = String.Empty
                form.PreviousString = String.Empty

                FormBoundsWidth(form)
                FormBoundsHeight(form)
                Func.ProgBar = Func.CreateProgBar(form)
                form.Controls.Add(Func.ProgBar)

                'LoadingThread = New Threading.Thread(AddressOf Func.ProgressLoop)
                form.Update()
            End If
            If form.InitializeOk = False Then
                Return Func.IsInitialized = False
            End If
            Return Func.IsInitialized = True
        End Function

        Function FormBoundsWidth(ByVal form As Object) As Integer
            Return form.Bounds.Width
        End Function

        Function FormBoundsHeight(ByVal form As Object) As Integer
            Return form.Bounds.Height
        End Function

        Function CreateForm() As Form1
            Dim f As New Form1
            f.FormNum = PREVIOUS_FORM

            f.Controls.Add(OkButton)
            f.Controls.Add(CancelButton)
            f.Show()
            f.SendToBack()
            Return f
        End Function

        Function GetTbox(ByVal Form1 As Form1) As TextBox

            Return Form1.TextBox1

        End Function

        Function CreateProgBar(ByVal aform As Form1) As ProgressBar
            Dim pb As New ProgressBar
            pb.Location = New Point(aform.Width / 400, aform.Height / 300)
            pb.Size = New Size(aform.Bounds.Width, aform.Bounds.Height / 4)
            Return pb

        End Function

        Function CreateLoadScreen(ByVal aform As Form1) As Form1
            Dim CurrentTime As Integer = 0
            Dim gfx As Graphics = aform.CreateGraphics
            Dim TotalLoadTime As Integer

            Dim LoadTimeResult As Integer = 0
            If IsInitialized = False Then
                Func.IsInitialized = False
                aform.DW_WRITELINE(Func.LoadBarFailedMessage)
                aform.SendToBack()
                Return Nothing
            End If

            OkButton.PerformClick()
            CurrentTime = CurrentTime + 1

            'Change initializeOK boolean to line above
              aform.InitializeOk = False
            If aform.InitializeOk = True Then
                gfx.Clear(Color.Black)
               'Change initializeOK boolean to three lines up
            End If
            CurrentTime = CurrentTime + 1

            Dim ld As Image = Image.FromFile(Func.LoadImage)

            'gfx.DrawImage(ld, New Point(LoadImageX, LoadImageY))

            CurrentTime = CurrentTime + 1

            LoadTimeResult = LoadTimeResult + CurrentTime

            'Threading.Thread.Sleep(LoadTimeResult)

            'Threading.Thread.SpinWait(100)

            'Func.ProgBar.Value = 0

            'LoadingThread = Nothing

            'Do Until aform.ProgressTime >= 0 And aform.ProgressTime >= 8
            'Func.ProgBar.PerformStep()

            'Loop
            Func.LoadTime(aform, gfx)
            Return aform

        End Function

        Function LoadTime(ByVal form As Form1, ByVal gfx As Graphics) As String
            Dim x As Integer = 0
            Dim LoadingMessage = "Loading"
            Dim Counter As String = "."
            For x = 0 To 1 * 2
                gfx.DrawString(LoadingMessage, New Font("Tahoma", 20), Brushes.Azure, 0, 0)
                form.Invalidate()
                LoadingMessage += Counter
                Threading.Thread.Sleep(1000 * 2)
            Next
            Return LoadingMessage
        End Function

    End Module

End Namespace

Implementation(Not really do it...With maybe?)

Imports WindowsApplication4.Core

Public Class Form1
    Inherits System.Windows.Forms.Form

    Friend Shared FormNum As Integer
    Friend Shared PreviousForm As Form1
    Friend Shared Current_Form As Form1
    Friend Shared PreviousString, CurrentString As String
    Friend Shared ProgressTime As Integer
    Friend Shared InitializeOk As Boolean
    Event Commands()

#Region " Windows Form Designer generated code "

    'Public Sub New()
    'MyBase.New()

        'This call is required by the Windows Form Designer.
    'InitializeComponent()

        'Add any initialization after the InitializeComponent() call

    'End Sub

    'Form overrides dispose to clean up the component list.
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub

    'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer

    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.  
    'Do not modify it using the code editor.
    Friend WithEvents Button1 As System.Windows.Forms.Button
    Friend WithEvents Button2 As System.Windows.Forms.Button
    Friend WithEvents TextBox1 As System.Windows.Forms.TextBox
    Friend WithEvents TextBox2 As System.Windows.Forms.TextBox
    Friend WithEvents Label1 As System.Windows.Forms.Label
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.Button1 = New System.Windows.Forms.Button
        Me.Button2 = New System.Windows.Forms.Button
        Me.TextBox1 = New System.Windows.Forms.TextBox
        Me.TextBox2 = New System.Windows.Forms.TextBox
        Me.Label1 = New System.Windows.Forms.Label
        Me.SuspendLayout()
        '
        'Button1
        '
        Me.Button1.Location = New System.Drawing.Point(8, 208)
        Me.Button1.Name = "Button1"
        Me.Button1.TabIndex = 0
        Me.Button1.Text = "Button1"
        '
        'Button2
        '
        Me.Button2.Location = New System.Drawing.Point(200, 208)
        Me.Button2.Name = "Button2"
        Me.Button2.TabIndex = 1
        Me.Button2.Text = "Button2"
        '
        'TextBox1
        '
        Me.TextBox1.Location = New System.Drawing.Point(8, 56)
        Me.TextBox1.Multiline = True
        Me.TextBox1.Name = "TextBox1"
        Me.TextBox1.Size = New System.Drawing.Size(272, 120)
        Me.TextBox1.TabIndex = 2
        Me.TextBox1.Text = "TextBox1"
        '
        'TextBox2
        '
        Me.TextBox2.Location = New System.Drawing.Point(8, 184)
        Me.TextBox2.Name = "TextBox2"
        Me.TextBox2.Size = New System.Drawing.Size(272, 20)
        Me.TextBox2.TabIndex = 3
        Me.TextBox2.Text = "TextBox2"
        '
        'Label1
        '
        Me.Label1.BackColor = System.Drawing.Color.Transparent
        Me.Label1.Font = New System.Drawing.Font("Microsoft Sans Serif", 14.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.Label1.Location = New System.Drawing.Point(80, 8)
        Me.Label1.Name = "Label1"
        Me.Label1.Size = New System.Drawing.Size(100, 24)
        Me.Label1.TabIndex = 4
        Me.Label1.Text = "IonVision"
        '
        'Form1
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
        Me.ClientSize = New System.Drawing.Size(284, 262)
        Me.Controls.Add(Me.Label1)
        Me.Controls.Add(Me.TextBox2)
        Me.Controls.Add(Me.TextBox1)
        Me.Controls.Add(Me.Button2)
        Me.Controls.Add(Me.Button1)
        Me.Name = "Form1"
        Me.Text = "Form1"
        Me.ResumeLayout(False)

    End Sub

#End Region
    Sub New()
        InitializeComponent()
        Func.OkButton = Me.Button1
        Func.CancelButton = Me.Button2

        Func.IsInitialized = False
        Current_Form = Me
        InitializeOk = True

        AddHandler Commands, AddressOf Command

        ProgressTime = 0

        Func.InitializeFunc(Me)
        Func.IsInitialized = True

        'Func.CreateLoadScreen(Me)
    End Sub

    Private Sub OkButton_Click(ByVal s As Object, ByVal e As EventArgs) Handles Button1.Click

        If s.InitializeOk = True Then
            Dim CreatedForm = Func.CreateForm
            Form1.PreviousForm = CreatedForm
            If Func.InitializeFunc(CreatedForm) = False Then
                Throw New Exception("Failed to Create Form")
            ElseIf True Then

                Func.IsInitialized = True
            End If
        End If
    End Sub

    Public Shared Sub DW_WRITELINE(ByVal input As String)
        If Func.IsInitialized = True Then
            GetTbox(Current_Form).AppendText(Func.LINE_TERMINATOR & input & Environment.NewLine)
        End If

    End Sub
    Dim resized As Boolean = False
    Private Sub Form1_Resize(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Resize

    End Sub

    Private Sub Command()

        If IsNothing(CurrentString) Then
            DW_WRITELINE(Func.NoCommandMsg)
            Exit Sub
        End If
        If CurrentString = "Min" Then
            Me.Width = 300
            Me.Height = 300
            Me.Button1.Location = Func.ButtonLocCalc(Me)
            Me.Button1.Location = Func.Button2LocCalc(Me)
            Me.TextBox1.Location = Func.TboxLocCalc(Me)
            Me.TextBox2.Location = Func.TboxLocCalc2(Me)

        End If
        If CurrentString = "Max" Then
            Me.Width = 1024
            Me.Height = 768
            Me.Button1.Location = Func.ButtonLocCalc(Me)
            Me.Button2.Location = Func.Button2LocCalc(Me)
            Me.TextBox1.Location = Func.TboxLocCalc(Me)
            Me.TextBox2.Location = Func.TboxLocCalc2(Me)

        End If
        If CurrentString = "Load" Then
            For Each Control As Control In Me.Controls
                Control.Visible = False
            Next

            'Func.InitializeFunc(Me)
            Func.CreateLoadScreen(Me) 'Load Screen Function
            Func.InitializeFunc(Me) 'Reload GUI
            For Each Control As Control In Me.Controls
                Control.Visible = True
            Next

        End If
        If CurrentString = "Go" Then
            Me.InitializeOk = True
            Func.InitializeFunc(Me)
            'RaiseEvent Commands()
        End If

    End Sub
    Private Sub TextBox2_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TextBox2.KeyDown
        Select Case e.KeyCode
            Case Keys.Enter
                CurrentString = CStr(TextBox2.Text)
                PreviousString = CStr(TextBox2.Text)
                RaiseEvent Commands()
        End Select
    End Sub
End Class

Edited by Michael_9: change line of initialize ok boolean

Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.