1

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

            }
        }
    }
4

1 回答 1

0
    Pleae check with below code

   foreach(var gvItem in GridView1.Items)
    {
      CheckBox chkItem = (CheckBox) gvItem.FindControl("Poslano");
      if (chkItem.Checked)
     {
       //Do stuff
     }
    }
于 2019-07-10T06:19:21.297 回答