1

编辑的代码:之前的代码效果很好,但无法更改 textbox.text 属性或显示它们来自此循环添加的每个控件

任何帮助表示赞赏

一些子

    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

我想这是我需要了解如何在 datarpeater 控件中添加/更改我的 textox 名称的地方,有人对我有任何解决方案吗?

        '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

结束子

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

2 回答 2

2

DataRepeater 必须设置其 DataSource 属性才能使 AddNew 工作。它被设计为数据绑定。

您可以将 dataSource 设置为对象列表。然后,无论何时添加到列表中,dataRepeater 都会自动显示新项目。

例子:

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
于 2013-04-30T16:33:20.247 回答
0

您没有在每个循环中声明数据类型。你需要在'name'之后'as string'

For Each name As String In li
        Form1.DataRepeater1.AddNew()
        Form1.DataRepeater1.CurrentItem.Controls("txtName").Text = name
Next
于 2013-04-30T16:09:20.567 回答