Imports System Imports System.Data Imports System.Configuration Imports System.Web Imports System.Web.Security Imports System.Web.UI Imports System.Web.UI.WebControls Imports System.Web.UI.HtmlControls Imports System.Collections Imports System.Data.SqlClient Imports System.Data.OleDb Imports System.DrawingPublic Class _Default Inherits System.Web.UI.Page Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) End Sub Protected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Dim myconn As New SqlConnection("server=.\SQLEXPRESS;database=PROGRESSDATA;uid=sa;pwd=179113") Dim mysqldata As New SqlDataAdapter("select PJNM , PHNM, WorkID,Date,Pprogress,Rprogress from WorkDetail,Project,Phase where WorkDetail.PJID=Project.PJID and Phase.PHID=WorkDetail.PHID", myconn) Dim ds As New DataSet mysqldata.Fill(ds, "WorkDetail") Dim aDataView As DataView = ds.Tables("WorkDetail").DefaultView jb_tab.GridLines = GridLines.Both jb_tab.BorderStyle = BorderStyle.Solid jb_tab.BorderWidth = 1 jb_tab.CellPadding = 3 jb_tab.CellSpacing = 0 jb_tab.Width = 300 jb_tab.BorderColor = Color.FromArgb(20, 120, 235) For Each aRow As DataRowView In aDataView Dim aTableRow As New TableRow Dim Cell_zzzh As New TableCell Dim Cell_xb As New TableCell Dim Cell_sl As New TableCell Dim Cell_date As New TableCell Dim Cell_Pp As New TableCell Dim Cell_Rp As New TableCell Cell_zzzh.Text = aRow("PJNM").ToString() Cell_xb.Text = aRow("PHNM").ToString() Cell_sl.Text = aRow("WorkID").ToString() Cell_date.Text = aRow("Date").ToString() Cell_Pp.Text = aRow("Pprogress").ToString() Cell_Rp.Text = aRow("Rprogress").ToString() aTableRow.Cells.Add(Cell_zzzh) aTableRow.Cells.Add(Cell_xb) aTableRow.Cells.Add(Cell_sl) aTableRow.Cells.Add(Cell_date) aTableRow.Cells.Add(Cell_Pp) aTableRow.Cells.Add(Cell_Rp) jb_tab.Rows.Add(aTableRow) Next '**开始合并单元格** Dim iRows As Integer 'DataTable的行数 Dim iColumns As Integer 'DataTable的列数 iRows = jb_tab.Rows.Count iColumns = 2 Dim strTmp As String = Nothing '临时变量保存单元格值 Dim iRowSpan As Integer = 1 '拉伸到几个行高 Dim iRowNo As Integer = 0 '正在拉伸的行号 Dim iColNo As Integer = 0 For i As Integer = 0 To iColumns - 1 '正在拉伸的列号 '历遍绑定到表的所有列 strTmp = "" For j As Integer = 0 To iRows - 1 '历遍绑定到表的所有行(单元格) If strTmp = jb_tab.Rows(j).Cells(i).Text.ToString().Trim() Then '将临时变量与指定单元格的制进行比较 iRowSpan = iRowSpan + 1 jb_tab.Rows(j).Cells(i).Visible = False '隐藏当前单元格 '上面的单元格在纵向改变为n个单元格的高度 jb_tab.Rows(iRowNo).Cells(iColNo).RowSpan = iRowSpan Else iRowNo = j iColNo = i iRowSpan = 1 '将当前单元格的值赋给临时变量 strTmp = jb_tab.Rows(j).Cells(i).Text.ToString().Trim() End If Next Next '**合并完毕** End SubEnd Class
Imports System.Data
Imports System.Configuration
Imports System.Web
Imports System.Web.Security
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Web.UI.HtmlControls
Imports System.Collections
Imports System.Data.SqlClient
Imports System.Data.OleDb
Imports System.DrawingPublic Class _Default
Inherits System.Web.UI.Page Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) End Sub Protected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Dim myconn As New SqlConnection("server=.\SQLEXPRESS;database=PROGRESSDATA;uid=sa;pwd=179113")
Dim mysqldata As New SqlDataAdapter("select PJNM , PHNM, WorkID,Date,Pprogress,Rprogress from WorkDetail,Project,Phase where WorkDetail.PJID=Project.PJID and Phase.PHID=WorkDetail.PHID", myconn) Dim ds As New DataSet
mysqldata.Fill(ds, "WorkDetail")
Dim aDataView As DataView = ds.Tables("WorkDetail").DefaultView
jb_tab.GridLines = GridLines.Both
jb_tab.BorderStyle = BorderStyle.Solid
jb_tab.BorderWidth = 1
jb_tab.CellPadding = 3
jb_tab.CellSpacing = 0
jb_tab.Width = 300
jb_tab.BorderColor = Color.FromArgb(20, 120, 235)
For Each aRow As DataRowView In aDataView
Dim aTableRow As New TableRow
Dim Cell_zzzh As New TableCell
Dim Cell_xb As New TableCell
Dim Cell_sl As New TableCell
Dim Cell_date As New TableCell
Dim Cell_Pp As New TableCell
Dim Cell_Rp As New TableCell Cell_zzzh.Text = aRow("PJNM").ToString()
Cell_xb.Text = aRow("PHNM").ToString()
Cell_sl.Text = aRow("WorkID").ToString()
Cell_date.Text = aRow("Date").ToString()
Cell_Pp.Text = aRow("Pprogress").ToString()
Cell_Rp.Text = aRow("Rprogress").ToString() aTableRow.Cells.Add(Cell_zzzh)
aTableRow.Cells.Add(Cell_xb)
aTableRow.Cells.Add(Cell_sl)
aTableRow.Cells.Add(Cell_date)
aTableRow.Cells.Add(Cell_Pp)
aTableRow.Cells.Add(Cell_Rp) jb_tab.Rows.Add(aTableRow)
Next
'**开始合并单元格** Dim iRows As Integer
'DataTable的行数
Dim iColumns As Integer
'DataTable的列数
iRows = jb_tab.Rows.Count
iColumns = 2
Dim strTmp As String = Nothing
'临时变量保存单元格值
Dim iRowSpan As Integer = 1
'拉伸到几个行高
Dim iRowNo As Integer = 0
'正在拉伸的行号
Dim iColNo As Integer = 0
For i As Integer = 0 To iColumns - 1
'正在拉伸的列号
'历遍绑定到表的所有列
strTmp = ""
For j As Integer = 0 To iRows - 1
'历遍绑定到表的所有行(单元格)
If strTmp = jb_tab.Rows(j).Cells(i).Text.ToString().Trim() Then
'将临时变量与指定单元格的制进行比较
iRowSpan = iRowSpan + 1
jb_tab.Rows(j).Cells(i).Visible = False
'隐藏当前单元格
'上面的单元格在纵向改变为n个单元格的高度
jb_tab.Rows(iRowNo).Cells(iColNo).RowSpan = iRowSpan
Else
iRowNo = j
iColNo = i
iRowSpan = 1
'将当前单元格的值赋给临时变量
strTmp = jb_tab.Rows(j).Cells(i).Text.ToString().Trim()
End If
Next
Next
'**合并完毕** End SubEnd Class