0
我從數據庫中動態創建了一個表。想要做的是創建一個固定的標題和一個可滾動的主體。我嘗試了CSS和JavaScript,但沒有設法做任何事情,我認爲是因爲表格是自動創建的。 幫助。在ASP.NET中動態修復表格中的HTML固定標題
這裏是我的代碼:
private void GenerateTable();
{
DataTable dt = CreateDataTable();//in CreateDataTable I just take all my reocrds from database
Table table = new Table();
TableRow row = null;
row = new TableRow();
for (int j = 0; j < dt.Columns.Count; j++)
{
TableHeaderCell headerCell = new TableHeaderCell();
headerCell.Text = dt.Columns[j].ColumnName;
row.Cells.Add(headerCell);
}
table.Rows.Add(row);
//Add the Column values
for (int i = 0; i < dt.Rows.Count; i++)
{
row = new TableRow();
for (int j = 0; j < dt.Columns.Count; j++)
{
TableCell cell = new TableCell();
cell.Text = dt.Rows[i][j].ToString();
row.Cells.Add(cell);
}
table.Rows.Add(row);
}
tablediv.Controls.Add(table);
}
事業部,我添加表:
<div class="mainEntry" style="width:90%" id="tablediv" runat="server" />
我的CSS的表:
table {
border-collapse: collapse;
width: 100%;
color: white;
}
th, td {
text-align: left;
padding: 8px;
}
th{
font-size:20px;
}
tbody{
height:500px;
overflow:auto;
display:block;
}
tr:nth-child(even){background-color: rgba(255, 255, 255, .15)}
th {
background-color: rgba(174, 183, 212, .15);
color: white;
}
我昨天剛剛回答了一個類似的問題,請看看這裏 - http://stackoverflow.com/questions/38659787/fix-header-row-in-repeater-in-asp-net/ 38666596#38666596 –
問題是我沒有在我的表中,當我創建jum dinamycally它把我的
爲什麼你不創建它?使用TableHeaderRow對象 –