2012-10-25 80 views

回答

1

可以使用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); 

+0

如何, 你可以給我一個例子嗎 ? – Mana

+0

不能得到gvr,它只能與foreach scoope住在一起 – Mana

+0

確定我的錯誤,更新了代碼 –

0

您可以使用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); 
} 
相關問題