简体   繁体   中英

loop throw gridview1 rows to add contents in other gridview2

I have this code and I already try debugging, there are no other problem but only one thing I dont know is how to read through the next row from the Gridview "aT" which I got from a Sql query result

  For Each aR As DataRow In aT.Rows
        Dim AltRow As DataRow = AltTbl.NewRow
        AltRow.Item(0) = aR.Item("OXLINC")
        AltRow.Item(1) = aR.Item("OXPART")
        AltRow.Item(2) = FormatCurrency(aR.Item("OXLSTP"))
        AltRow.Item(3) = FormatCurrency(aR.Item("OXCOST"))
        AltRow.Item("QtyRA") = QtyR
        AltRow.Item(5) = aR.Item("OXQTYA")
        AltRow.Item(8) = r.RowIndex
        AltRow.Item(9) = MFG
        AltTbl.Rows.Add(AltRow)
    Next

    If AltTbl.Rows.Count > 0 Then
        GridView10.DataSource = AltTbl
        GridView10.DataBind()
        GridView10.Visible = True
        GridView7.Visible = False
    End If

    For Each gR As GridViewRow In GridView10.Rows
        Dim sR As DataRow = aT.Rows(0)  //Dont know what to do here
        Dim WhseTbl As New DataTable
        WhseTbl.Columns.Add("WhseID")
        WhseTbl.Columns.Add("Qty")
        For i = 1 To 10
            If RTrim(sR.Item("OXBR" & i)) <> "" Then
                Dim wR As DataRow = WhseTbl.NewRow
                wR.Item(0) = sR.Item("OXBR" & i)
                wR.Item(1) = sR.Item("OXAV" & i)
                WhseTbl.Rows.Add(wR)
                gR.BackColor = Drawing.Color.Yellow
            End If
        Next
        If WhseTbl.Rows.Count > 0 Then
            Dim whseG As GridView = gR.FindControl("WhGrid")
            whseG.DataSource = WhseTbl
            whseG.DataBind()
        Else
            gR.Cells(6).Text = "Not Available"
        End If
        If sR.Item("OXQTYA") >= 1 Then
            gR.BorderColor = Drawing.Color.GreenYellow
        End If
    Next

It only read first Row I know its obvious but I need help. I want to know what I can replace that with

Thanks

Why not use the same DataSource for each of the GridView controls and then handle the RowDataBound event for the second GridView control to do whatever formatting (color, custom text, etc.) you need for each column, based upon business rules (ie QXQTYA is greater than 1)?

You can handle the RowDataBound event by doing the following:

Markup:

<asp:gridview id="GridViewB" 
    onrowdatabound="GridViewB_RowDataBound" 
    runat="server">
</asp:gridview>

Code-behind:

Sub CustomersGridView_RowDataBound(ByVal sender As Object, ByVal e As GridViewRowEventArgs)
    If e.Row.RowType = DataControlRowType.DataRow Then
        ' Do custom logic here per column
    End If
End Sub

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM