vb.net Datarepeater, Dataadapter, Dataset, SQL How to break up line by line and insert into repeater

StackOverflow https://stackoverflow.com/questions/16304003

Question

Edited Code : the code from before works great but cannot change the textbox.text properties or display them fro each of the controlls added by this loop

any help is appreciated

some sub

    Dim EqLst As String = ""

    Try

        Dim con As New SqlConnection
        Dim myConString As String = getSQLString()
        Dim objcommand As SqlCommand = New SqlCommand

        With objcommand
            .Connection = con
            Dim cmdText As String = "SELECT EquipList from SiteAuditor where client='" & GLClient & "' and market='" & GLMarket & "' and project='" & GLProject & "'"
            .CommandText = cmdText
        End With
        con.ConnectionString = myConString
        con.Open()

        Using readerObj As SqlClient.SqlDataReader = objcommand.ExecuteReader
            'This will loop through all returned records 
            While readerObj.Read

                EqLst = readerObj("EquipList").ToString

                Exit While
            End While
        End Using

        con.Close()

        Dim li As String() = EqLst.Split(",")
        Dim data As New List(Of dataitem)
        For Each name As String In li
            'Form1.DataRepeater1.AddNew()
            data.Add(New dataitem(name))
            Form1.DataRepeater1.CurrentItem.Controls("txtName").Text = name
        Next

        Form1.DataRepeater1.DataSource = data

I guess here is where i need be find out how to add / change my textox names within the datarpeater control anyone have any solutions for me ?

        'For Each name As String In li
        '    Form1.DataRepeater1.CurrentItemIndex(i).text = name
        'Next


    Catch ex As Exception

        Dim thiserror As String = "Error grabDataRepeaterData, " & vbCrLf _
                    & "Email Notifying CLS-Software Developemnt about this error was sent."
        Dim additionalinfo As String = UserLogin & vbCrLf & UserLogin.Replace("CLSGROUP\", "") & vbCrLf & vbCrLf & vbCrLf & vbCrLf & vbCrLf & ex.ToString
        MessageBox.Show(thiserror)
        ErrorEmails(thiserror, additionalinfo)

    End Try


    Return Nothing

end sub

Public Class dataitem
    Public Sub New(text As String)
        Me.text = text
    End Sub
    Public Property text As String
End Class
Was it helpful?

Solution

The DataRepeater has to have its DataSource property set for AddNew to work. It's designed to be data bound.

You can set the dataSource to a list of objects. Then whenever you add to the list, the dataRepeater will automatically show the new items.

Example:

Public Class dataitem
 Public Sub New(text As String)
  Me.text = text
 End Sub
 Public Property text As String
End Class

Public Class Form1
 Public Sub New()
  InitializeComponent()
  Dim data As New List(Of dataitem)
  data.Add(New dataitem("test1"))
  data.Add(New dataitem("test2"))
  DataRepeater1.DataSource = data
 End Sub
End Class

OTHER TIPS

Your not declaring the datatype in your for each loop. You need 'as string' after 'name'

For Each name As String In li
        Form1.DataRepeater1.AddNew()
        Form1.DataRepeater1.CurrentItem.Controls("txtName").Text = name
Next
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top