美文网首页
ASP.NET-细节-datagrid的prerender事件上

ASP.NET-细节-datagrid的prerender事件上

作者: 柠檬正在努力 | 来源:发表于2020-05-09 09:47 被阅读0次

    话不多说,直接放代码和效果图

    /*
    ''' <summary>
    ''' 合并单元格
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    */
    Protected Sub dgdData_PreRender(ByVal sender As Object, ByVal e As EventArgs) Handles dgdData.PreRender
        Dim sColumns As Integer = 2 /*需要合并的列*/
        If dgdData.Items.Count > 1 Then
            Dim rowspan As Integer = 0
            For i As Integer = 1 To dgdData.Items.Count - 1 /*单元格合并*/
                If dgdData.Items(i - 1).Cells(sColumns).Text.Trim() = dgdData.Items(i).Cells(2).Text.Trim() Then /*分页中合并单元格*/
                    rowspan = rowspan + 1
                    dgdData.Items(i - rowspan).Cells(sColumns).RowSpan = rowspan + 1
                    dgdData.Items(i).Cells(sColumns).Visible = False
                    dgdData.Items(i - rowspan).Cells(sColumns).VerticalAlign = VerticalAlign.Middle
                Else
                    rowspan = 0
                End If
            Next
        End If
    End Sub
    
    合并单元格实例

    相关文章

      网友评论

          本文标题:ASP.NET-细节-datagrid的prerender事件上

          本文链接:https://www.haomeiwen.com/subject/bdyfnhtx.html