我需要有关此代码的帮助,在其中检查GridView
中是否检查了CheckBox
中的每一行。但是仍然存在错误。你能帮我吗?
<asp:GridView ID="GridView1" CssClass="tabulka" runat="server" AutoGenerateColumns="false" />
<Columns>
<asp:TemplateField HeaderText="Placení">
<ItemTemplate>
<asp:CheckBox ID="Poslano" runat="server" Text="Vyřešeno" />
<asp:HiddenField ID="id" runat="server" Value='<%# Eval("id").ToString() %>' />
</ItemTemplate>
</asp:TemplateField>
</Columns>
<FooterStyle BackColor="#CCCCCC" />
<HeaderStyle BackColor="Black" Font-Bold="True" ForeColor="White" />
</asp:GridView>
protected void Button1_Click(object sender, EventArgs e)
{
foreach (GridViewRow gvRow in GridView1.Rows)
{
if (((CheckBox)gvRow.FindControl("Poslano")).Checked) // here is a problem - still false
{
Tabor tab = new Tabor();
tab.Id = Convert.ToInt32(((HiddenField)gvRow.FindControl("id")).Value); // here is good value
}
}
}
答案 0 :(得分:0)
Pleae check with below code
foreach(var gvItem in GridView1.Items)
{
CheckBox chkItem = (CheckBox) gvItem.FindControl("Poslano");
if (chkItem.Checked)
{
//Do stuff
}
}