如何在运行时在 gridview 标题中执行 Rowspan 和 Columnspan?
目前我正在做一个复杂的过程,首先创建一个表,然后将所有行和列添加到其中。
稍后在行创建事件中对 gridview 标题进行 colspan 并在其中添加表格。
代码片段:
Table headerTable = new Table();
headerTable.CssClass = "tbl";
headerTable.CellPadding = 1;
headerTable.CellSpacing = 0;
TableRow headerRow1 = new TableRow();
TableHeaderCell headerTableCell = new TableHeaderCell();
headerTableCell.RowSpan = 2;
headerTableCell.Text = "SL No";
headerTableCell.CssClass = "inputFromTo";
headerRow1.Controls.Add(headerTableCell);
headerTableCell = new TableHeaderCell();
headerTableCell.ColumnSpan = 3;
headerTableCell.Text = "MH1 <br> M. Mark";
headerRow1.Controls.Add(headerTableCell);
for (int i = 1; i <= Convert.ToInt16(txtHHColumn.Text); i++)
{
headerTableCell = new TableHeaderCell();
headerTableCell.ColumnSpan = 3;
headerTableCell.Text = "HH-" + i + "<br> M. Mark";
headerRow1.Controls.Add(headerTableCell);
}
headerTableCell = new TableHeaderCell();
headerTableCell.ColumnSpan = 3;
headerTableCell.Text = "MH2 <br> M. Mark";
headerRow1.Controls.Add(headerTableCell);
TableRow headerRow2 = new TableRow();
TableHeaderCell headerCell1;
TableHeaderCell headerCell2;
TableHeaderCell headerCell3;
for (int i = 1; i < Convert.ToInt16(3 + Convert.ToInt16(txtHHColumn.Text)); i++)
{
headerCell1 = new TableHeaderCell();
headerCell2 = new TableHeaderCell();
headerCell3 = new TableHeaderCell();
headerCell1.Text = "D Entry";
headerCell1.CssClass = "inputFromTo";
headerCell2.Text = "D Exit";
headerCell2.CssClass = "inputFromTo";
headerCell3.Text = "Slack";
headerCell3.CssClass = "inputFromTo";
headerRow2.Controls.Add(headerCell1);
headerRow2.Controls.Add(headerCell2);
headerRow2.Controls.Add(headerCell3);
}
headerTable.Rows.Add(headerRow1);
headerTable.Rows.Add(headerRow2);
GridViewRow HeaderRow = new GridViewRow(0, 0, DataControlRowType.Header, DataControlRowState.Insert);
TableCell Cell_Header = new TableCell();
Cell_Header.ColumnSpan = 10 + (Convert.ToInt16(txtHHColumn.Text) * 3);
Cell_Header.Controls.Add(headerTable);
HeaderRow.Cells.Add(Cell_Header);
gvOfcManHole.Controls[0].Controls.AddAt(0, HeaderRow);
有比这更好的主意的人吗?