zoukankan      html  css  js  c++  java
  • 关于gridview 合并行列

    Protected Sub MainGrdvDataBinding()
      Dim ds_MainBills As DataSet, i As Integer
      Dim j As Integer = 0 '數量的總計
      Dim k As Integer = 0 '總重量的總計
      Dim l As Integer = 0 '木架數總計
      Dim m As Integer = 0 '木架費總計
      Dim n As Decimal = 0 '金額總計
      Dim dt As DataTable
      Dim DetailRow As DataRow

      Try
        con_brmis = Css2DataAccess.GetConnection(Nothing, "css2") 
        ds_MainBills = Css2DataAccess.ExecuteDataset(con_brmis, CommandType.Text, Session("Sql_Main"))
        dt = ds_MainBills.Tables(0).Columns.Add.Table
        For i = 0 To dt.Rows.Count - 2
        If dt.Rows(i)("box_num") Then
          j += dt.Rows(i)("box_num")
          k += dt.Rows(i)("total_weight")
          l += dt.Rows(i)("shelft_num")
          m += dt.Rows(i)("shelft_fee")
          n += dt.Rows(i)("total_fee")
        End If
        Next
        DetailRow = dt.NewRow

        DetailRow("traffic_comp_name") = "总计"
        DetailRow("box_num") = j
        DetailRow("total_weight") = k
        DetailRow("shelft_num") = l
        DetailRow("shelft_fee") = m
        DetailRow("total_fee") = n
        dt.Rows.Add(DetailRow)
        Main_grdv.DataSource = dt
        Main_grdv.DataBind()
        With Main_grdv
          For i = 0 To .Rows.Count - 2
          If .Rows(i).Cells(16).Text = "1" Then

            .Rows(i).Cells(16).Text = "正常发货"

          ElseIf .Rows(i).Cells(16).Text = "2" Then
            .Rows(i).Cells(16).Text = "补货"
          End If

          Next
          .Rows(i).Cells(2).Visible = False
          .Rows(i).Cells(4).Visible = False
          .Rows(i).Cells(5).Visible = False
          .Rows(i).Cells(3).ColumnSpan = 4
        End With

        If ds_MainBills.Tables(0).Rows.Count = 0 Then
          ErrorMsg.Text = Resources.CommonLan.Msg_NotFound
        Else
          MainBills_pnl.Visible = True
        End If
        '合并相同取货单的行
        Call gvRender()

        ds_MainBills = Nothing
      Catch ex As Exception
        ErrorMsg.Text = ex.Message
      Finally
        con_brmis.Close()
      End Try
    End Sub

    '合并相同取货单的行
    Private Sub gvRender()
      Dim i As Integer, j As Integer

      If Main_grdv.Rows.Count <= 1 Then
      Return
      End If

      '由行开始循环
      For i = Main_grdv.Rows.Count - 2 To 0 Step -1

        Dim oldTr As TableRow = Main_grdv.Rows(i)
        Dim newTr As TableRow = Main_grdv.Rows(i + 1)

        If oldTr.Cells(2).Text = newTr.Cells(2).Text And oldTr.Cells(4).Text = newTr.Cells(4).Text And oldTr.Cells(7).Text = newTr.Cells(7).Text     Then

          '由列开始循环  Main_grdv.Columns.Count - 3 到 Main_grdv.Columns.Count - 1 列则为不合并的列
          For j = 0 To Main_grdv.Columns.Count - 4
            'Main_grdv.Rows(r).Cells(j).RowSpan = rowspan
            If newTr.Cells(j).RowSpan < 2 Then
              oldTr.Cells(j).RowSpan = 2
            Else
              oldTr.Cells(j).RowSpan = newTr.Cells(j).RowSpan + 1
              oldTr.Cells(j).VerticalAlign = VerticalAlign.Middle
            End If
            newTr.Cells(j).Visible = False
          Next
        Else
        End If
      Next
    End Sub

  • 相关阅读:
    零基础学python-16.7 nonlocal介绍
    零基础学python-16.6 嵌套作用域
    零基础学python-16.5 模块间全局变量的修改以及其他访问全局变量的方法
    零基础学python-16.4 global作用域
    零基础学python-16.3 变量名解析:LEGB原则
    如何格式化日期和时间
    如何创建指定的日期和时间
    如何遍历Set对象
    如何遍历Map对象
    如何遍历List对象
  • 原文地址:https://www.cnblogs.com/withoutaword/p/2842659.html
Copyright © 2011-2022 走看看