<asp:GridView ID="FireFighters" runat="server" AutoGenerateColumns="false" OnRowDataBound="FireFighters_RowDataBound" >
<Columns>
<asp:BoundField HeaderText="שם הכבאי" DataField="username" />
<asp:CheckBoxField HeaderText="מצוות לאירוע" DataField="IsLinked" />
</Columns>
</asp:GridView>
我不能添加和id到ASP:CheckBoxField字段,我試着給它像這樣從後臺代碼:
foreach(GridViewRow gvr in FireFighters.Rows)
{
lst.Add(new FireFighter{username=gvr.Attributes["id"].ToString(),IsLinked=((gvr.Cells[1] as Control) as CheckBox).Checked});
}
但它的空,我怎麼能得到複選框的值(選中或不選)?
爲什麼你不能添加一個ID到複選框? – nZeus 2015-03-24 22:18:57
在這裏你可以看到如何在GridView中查找控件:http://stackoverflow.com/questions/6873973/how-to-find-control-in-templatefield-of-gridview – nZeus 2015-03-24 22:21:06
@nZeus你不能添加一個id以asp:CheckBoxField,我希望我能 – 2015-03-24 22:22:20