You only need to drag a Table control to the front-end to give an ID, and all our operations can be performed in the background.
| The code is as follows: |
Copy code |
<Asp: table ID = "table" runat = "server" BorderColor = "#000000" BorderStyle = "Solid" BorderWidth = "0px" Caption = "Table title" CellPadding = "0" CellSpacing = "0" Font-Bold = "False" Font-Italic = "False" Font-Overline = "False" Font-Size = "30px" Font-Strikeout = "False" Font -Underline = "False" Width = "980px"> </Asp: Table> |
The Table here is a control that allows you to change the rows and columns of a Table in the background.
The TableRow class is used to add a row. This class is equivalent to the tr label inside the table label in the HTML standard. To add a row, we can write as follows:
| The code is as follows: |
Copy code |
TableRow headUpTr = new TableRow (); Table. Rows. Add (headUpTr) |
In this way, a row is added to the table.
The method for adding a column in a row is the same as that in TableCell. Similarly, this class is equivalent to the td tag in HTML. Table, TableRow, and TableCell constitute a complete Table.
| The code is as follows: |
Copy code |
TableCell td = new TableCell (); HeadUpTr. Cells. Add (td); TableCell |
You can change the style of a table. When filtering the result set of data, you can customize the table based on different values in the loop output.
The most common TableCell attributes are:
ColumnSpan; used for columns
RowSpan; used for cross-row
Text; used to write strings
The Controls. Add (); method is used as the output control in the cell.
Attributes. Add (); this adds Attributes to cells and html tags, such as Style and Align.
Sometimes there may be many reuse cases, so I will write some operations as a method for convenient calls, such
| The code is as follows: |
Copy code |
Private void addtr (ref TableRow tr, string data, int colspan, int rowspan, string align, int width, string fontsize, int height, string style) { TableCell td = new TableCell (); Td. Width = width; Td. Attributes. Add ("align", align ); Td. Attributes. Add ("style", fontsize ); Td. CssClass = style; Td. ColumnSpan = colspan; If (height! = 20) { Td. Height = height; } Td. RowSpan = rowspan; Td. Text = data. ToString (); Tr. Cells. Add (td );
|
} I think there should be a simpler and more efficient method, but at present I have limited capabilities, but I can only find this method. Although it is not very advanced, it may be helpful for beginners.