您可以在这里快速查找:


 
您的位置: 编程学习 > asp.net教程 > 200512
文章分类

Java技术
2005: 03 04 05 06 07 08
09 10 11 12
2006: 01 02

Asp.net
2005: 07 08 09 10 11 12
2006: 01 02

VB编程
2006: 02

Asp编程
2005: 11 12
2006: 01 02

C++/VC
2005: 10 11 12
2006: 01 02

Delphi
2005: 12
2006: 01 02

其它

 本文章适合所有读者

DataGrid合併行

slgirlcn

    Private Sub UnitDataGridItem(ByVal intCell As Integer)
        Dim objDataGridItem As DataGridItem
        Dim strCell1 As String = ""
        Dim strCell2 As String = ""
        Dim objLiteralControl As LiteralControl
        Dim intSpan As Integer = 1
        Dim objDataGridItemToSpan As DataGridItem
        Dim i, j As Integer
        Dim strTemp As String
        For i = 0 To DataGrid1.Items.Count - 1
            intSpan = 1
            objLiteralControl = CType(DataGrid1.Items(i).Cells(intCell).Controls(0), LiteralControl)
            strCell1 = objLiteralControl.Text

            For j = i + 1 To DataGrid1.Items.Count - 1
                    objLiteralControl = CType(DataGrid1.Items(j).Cells(intCell).Controls(0), LiteralControl)
                    strCell2 = objLiteralControl.Text
                    If strCell1 = strCell2 Then 
                        intSpan += 1
                        DataGrid1.Items(i).Cells(intCell).RowSpan = intSpan
                        DataGrid1.Items(j).Cells(intCell).Visible = False
                    Else
                        Exit For
                    End If
                Next
                i = j - 1
        Next

    End Sub
除了設定RowSpan 外,還要把下面行的Visible 設成False,否則不起作用,底下會多出一個column.這個DataGrid的每個cell中都包含一個LiteralControl,如果沒有的話,就直接用DataGrid1.Items(i).Cells(intCell).Text即可.參數intCell ,是指要合併的那個列.