How to get a checkbox id through a table dimanica

3

Good morning, I wonder how I can get the id of a checkbox that is in a table with data generated from sqlserver.

This is how the design of the table is:

<asp:GridView ID="GridViewTable" runat="server" AutoGenerateColumns="False" ShowHeaderWhenEmpty="true" Width="100%" cssClass="table table-responsive">
            <Columns>
                <asp:BoundField DataField="name" HeaderText="Lineas" />
                <asp:templatefield HeaderText="ALL" ControlStyle-CssClass="clase" >
                    <itemtemplate>
                        <asp:checkbox ID="csSelectAll" 
                        CssClass="gridCB" runat="server"></asp:checkbox>
                    </itemtemplate>
                 </asp:templatefield>
                <asp:templatefield HeaderText="Turno A">
                    <itemtemplate>
                        <asp:checkbox ID="csSelectA" 
                        CssClass="gridCBA" runat="server"></asp:checkbox>
                    </itemtemplate>
                 </asp:templatefield>
                <asp:templatefield HeaderText="Turno B">
                    <itemtemplate>
                        <asp:checkbox ID="csSelectB" 
                        CssClass="gridCB" runat="server"></asp:checkbox>
                    </itemtemplate>
                 </asp:templatefield>
                <asp:templatefield HeaderText="Turno C">
                    <itemtemplate>
                        <asp:checkbox ID="csSelectC" 
                        CssClass="gridCC" runat="server"></asp:checkbox>
                    </itemtemplate>
                 </asp:templatefield>

and that's how I fill it:

SqlDataAdapter adapter = new SqlDataAdapter("SELECT fila FROM tabla", con);

            adapter.Fill(subjects);

            GridViewTable.DataSource = subjects;
            GridViewTable.DataBind();

then as they are generated in automatic according to the number of rows that the table has in sql I do not control which is the checkbox that I select

    
asked by matteo 30.05.2016 в 20:54
source

2 answers

1

You are missing link the table field with the checkbox

<asp:templatefield HeaderText="Turno A">
    <itemtemplate>
        <asp:checkbox ID="csSelectA" 
        CssClass="gridCBA" runat="server" Checked='<%# Eval("TurnoA") %>' ></asp:checkbox>
    </itemtemplate>
</asp:templatefield>         

As you will see it is defined

Checked='<%# Eval("TurnoA") %>' 

so that the field bool of the table tilde the check if it corresponds.

Populate (bind) CheckBox in GridView from database in ASP.Net using C # and VB.Net

Note: in this case use Eval ("TurnA") but you should define the correct name of the field you link to that column

    
answered by 30.05.2016 в 21:07
0

You can try with this code, although there is defined that they are static elements, I used it with a dynamic table, greetings!

jsfiddle

    
answered by 29.08.2016 в 17:12