繁体   English   中英

循环抛出gridview1行以在其他gridview2中添加内容

[英]loop throw gridview1 rows to add contents in other gridview2

我有这段代码,我已经尝试调试,没有其他问题,但是我不知道的唯一一件事是如何从我从Sql查询结果中获取的Gridview“ aT”读取下一行

  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

它只读第一行,我知道它很明显,但是我需要帮助。 我想知道我可以用什么代替

谢谢

为什么不为每个GridView控件使用相同的DataSource ,然后为第二个GridView控件处理RowDataBound事件,以根据业务规则( QXQTYA为大于1)?

您可以通过执行以下操作来处理RowDataBound事件:

标记:

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

后台代码:

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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