[英]How to add header row of a row in a gridview
我只是以編程方式將復選框添加到了gridview中,如下所示:
foreach (GridViewRow gvr in GridView1.Rows)
{
TableCell tbCell = new TableCell();
CheckBox cb1 = new CheckBox();
tbCell.Controls.Add(cb1);
gvr.Cells.Add(tbCell);
}
我的問題是我的標題行沒有創建。 如何以編程方式做到這一點?
檢查圖像鏈接上角落的間隙。
提前致謝
您可以使用HeaderRow .Cells.Add
屬性
foreach (GridViewRow gvr in GridView1.Rows)
{
TableCell tbCell = new TableCell();
CheckBox cb1 = new CheckBox();
tbCell.Controls.Add(cb1);
gvr.Cells.Add(tbCell);
}
TableCell tbCell = new TableCell();
CheckBox cb1 = new CheckBox();
tbCell.Controls.Add(cb1);
GridView1.HeaderRow.Cells.Add(tbCell);
您可以使用Gridview1.HeaderRow.Cells.Add,其中Gridview1是控件ID
TableCell tbCell1 = new TableCell();
CheckBox cb12 = new CheckBox();
tbCell1.Controls.Add(cb12);
Gridview1.HeaderRow.Cells.Add(tbCell1);
foreach (GridViewRow gvr in Gridview1.Rows)
{
TableCell tbCell = new TableCell();
CheckBox cb1 = new CheckBox();
tbCell.Controls.Add(cb1);
gvr.Cells.Add(tbCell);
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.