0

データリスト内の各データをループするにはどうすればよいですか?現在、「Label8」から1つの値を取得しているため、「Label7」にすべての「いいえ」が表示されます。

 Protected Sub DataList2_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataListItemEventArgs) Handles DataList2.ItemDataBound
    For Each li As DataListItem In DataList2.Items
        Dim labelasd As Label = DirectCast(e.Item.FindControl("**Label8**"), Label)
        Dim reviewid As Integer = labelasd.Text
        Dim connectionString As String = _
        ConfigurationManager.ConnectionStrings("ConnectionString").ConnectionString
        Dim connection As SqlConnection = New SqlConnection(connectionString)
        connection.Open()
        Dim sql As String = "Select Count(reviewYes) AS Expr1 From ProductReviewHelp Where ProductReviewID = " & reviewid & ""
        Dim command As SqlCommand = New SqlCommand(sql, connection)
        Dim reader As SqlDataReader = command.ExecuteReader()
        Dim countofreview As Integer = 0
        Dim reviewcountboolean As Boolean
        If (reader.Read()) Then
            If (IsDBNull(reader.GetValue(0)) = False) Then


                countofreview = reader.GetValue(0)


            End If
        End If
        If countofreview = 0 Then
            reviewcountboolean = False
        Else
            reviewcountboolean = True
        End If

        If (reviewcountboolean = True) Then

            Dim label1 As Label = DirectCast(e.Item.FindControl(**"Label7"**), Label)
            label1.Text = "Hello"

        ElseIf (reviewcountboolean = False) Then

            Dim label1 As Label = DirectCast(e.Item.FindControl(**"Label7"**), Label)
            label1.Text = "No"

        End If
    Next
End Sub

データリスト内の各データをループするにはどうすればよいですか?現在、「Label8」から1つの値を取得しているため、「Label7」にすべての「いいえ」が表示されます。

4

2 に答える 2

0

ループを使用して反復することができます ここに例があります

Try
        readFromDL1 = DirectCast(SqlDataSource1.Select(DataSourceSelectArguments.Empty), DataView)
        readFromQ = DirectCast(SqlDataSource7.Select(DataSourceSelectArguments.Empty), DataView)

    Catch ex As Exception

    End Try
    'End 
    'datalist1
    i = 0
    _rowCount = DataList1.Items.Count
    If _rowCount > 0 Then
        _getCall = DataList1.Items.Item(i).FindControl("lnkEdit")
    End If

    For Each readr As DataRowView In readFromQ
        findQNumber = readr(1).ToString()
        For Each readfdlr1 As DataRowView In readFromDL1
            findQNumber1 = readfdlr1(1).ToString

            Try
                indexofitems = DataList1.Items.Item(i1).ItemIndex
                If findQNumber.ToString = findQNumber1.ToString Then
                    _getCall = DataList1.Items.Item(indexofitems).FindControl("lnkEdit")
                    _getCall.Text = "Called"
                    _getCall.Enabled = False
                    _getCall.ForeColor = Drawing.Color.Red
                    _getCall.BackColor = Drawing.Color.Yellow

                End If
                i1 = i1 + 1
            Catch e As Exception

            End Try

        Next
        i1 = 0
        i = i + 1
于 2015-02-04T20:45:04.297 に答える