Sometimes, we have to merge the same cells in a column. As shown below:
Merger rendering:
Let's talk about how to do it:
Sub Spanrid () DIM I AS INTEGER DIM J AS INTEGER DIM INTSPAN AS INTEGER, NOWSPAN AS INTEGER = 0 DIM STRTEMP AS STRING FOR I = 0 to DGRID.ITEMS.COUNT - 1 INTSPAN = 1
'Get the first column (color), the contents of the first line cell. Here is "red red". (Template column in DataGrid) strTemp = CType (DGrid.Items (i) .Cells (0) .controls (1), system.web.ui.webcontrols.label) .Text
'Cycle judgment. Determine the same content in the first column and the first line. Same as a mark, INTSPAN plus a for j = i 1 to dgrid.Items.count - 1 if string.compare (strtemp, ctype (dgrid.Items (j) .cells (1) .controls (1), System.Web .Ui.webcontrols.label) .text) = 0 THEN INTSPAN = 1
'Use the DataGrid's ROWSPAN attribute. (Set the number of lines across the cells in the Control) DGRID.Items (i) .cells (0) .rowspan = INTSPAN
'Hide DGRID.Items (j) in the same cells (j) .Cells (0) .visible = false else exit for end if next' i = j - 1 I originally
NOWSPAN = INTSPAN 'After modification, you can save a cycle. I = NowSPAN - 1 Next End Sub
=======
Quote:
Sub bindgrid () 'Binds the data to DataGrid ........ spangrid () end SUB
================= Add content. Merged in the same cell ========
In the case where the first column has been merged, the same cells are the same.
As long as you do a category loop before I = J-1. The following is the rendering: