CheckBox in ASP.NET GridView template field does not save its value for submission

I am trying to use CheckBoxes inside a GridView TemplateField to select multiple records from this GridView. A GridView data source is a list of items that are generated when a page loads.

<asp:GridView ID="GridView" runat="server" AutoGenerateColumns="False" 
            AllowPaging="True" onpageindexchanging="TANsGridView_PageIndexChanging" 
            DataKeyNames="GUID">
            <Columns>
                <asp:TemplateField ShowHeader="False" HeaderText="Checker">
                    <ItemTemplate>
                        <asp:CheckBox ID="SelectCheckbox" runat="server" />
                    </ItemTemplate>
                </asp:TemplateField>

The problem is that when I click the submit button, all CheckBoxes return with the checked property as "false".

To loop through rows, I use:

foreach (GridViewRow row in TANsGridView.Rows)
        {
            CheckBox cb = (CheckBox)row.FindControl("SelectCheckbox");
        }

What should I use to have access to the correct value?

Thanks Catalin

+3
source share
2 answers

gridview ? gridview if, .

?:)

+6

load.load , .

if(!ispostback)
{
..........loading data to databind.

}
0

Source: https://habr.com/ru/post/1792786/


All Articles