【发布时间】:2015-05-28 10:16:36
【问题描述】:
我的代码
<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>
我无法向 asp:CheckBoxField 添加和 id,我尝试从代码隐藏中这样调用它:
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?
-
这里你可以看到如何在 GridView 中找到控件:stackoverflow.com/questions/6873973/…
-
@nZeus 你不能向 asp:CheckBoxField 添加 id,我希望我可以
-
你实现了这个
foreach什么事件? -
您可以使用
<asp:TemplateField>并将Checkbox控件放在里面