1
我想動態地在GridView的OnRowCreated事件中插入第二個標題行。但是,我似乎無法將行插入到gridview的行索引中的第一個位置之外的任何地方。下面的代碼在最後一行失敗,其中標題實際上被添加到網格中。索引超出界限例外。我如何在下面添加這個標題行已經存在的標題行?非常感謝幫助,謝謝!添加第二個標題行到GridView下面已經存在的標題行
protected void gvwProd_RowCreated(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.Header)
{
GridView gvw = (GridView)sender;
GridViewRow HeaderRow = new GridViewRow(1, 1, DataControlRowType.Header, DataControlRowState.Insert);
TableCell HeaderCell = new TableCell();
HeaderCell.Text = "Prod Comments - TS/LID";
HeaderCell.Style["font-weight"] = "bold";
HeaderCell.ColumnSpan = 4;
HeaderCell.Wrap = false;
HeaderRow.Cells.Add(HeaderCell);
HeaderCell = new TableCell();
HeaderCell.Text = "Materials Comments - TS/LD";
HeaderCell.Style["font-weight"] = "bold";
HeaderCell.ColumnSpan = 8;
HeaderCell.Wrap = false;
HeaderRow.Cells.Add(HeaderCell);
HeaderCell = new TableCell();
HeaderCell.Text = "Plant Comments - TS/LID";
HeaderCell.Style["font-weight"] = "bold";
HeaderCell.ColumnSpan = 11;
HeaderCell.Wrap = false;
HeaderRow.Cells.Add(HeaderCell);
gvw.Controls[0].Controls.AddAt(1, HeaderRow);
}
}
如果這是ASP.NET,那麼你應該標記是這樣的 – Paparazzi 2012-07-24 21:46:38