title: Looping through GridView rows and Checking Checkbox Control
body: <p>I currently have a GridView which displays data from a Student Table, here is my Grid and associated SQLDataSource;</p>
  
  <pre><code>                      &lt;asp:GridView ID="GridView2" 
                          style="position:absolute; top: 232px; left: 311px;" 
                              AutoGenerateColumns="false" runat="server"
                          DataSourceID="SqlDataSource4"&gt;
                          &lt;Columns&gt;
                              &lt;asp:TemplateField&gt;
                              &lt;ItemTemplate &gt;
                              &lt;asp:CheckBox runat="server" ID="AttendanceCheckBox" /&gt;
                              &lt;/ItemTemplate&gt;
                              &lt;/asp:TemplateField&gt;
                              &lt;asp:TemplateField&gt;
                              &lt;ItemTemplate&gt;
                              &lt;asp:Label ID="studentIDLabel" Text='&lt;%# Eval("StudentID") %&gt;' runat="server"&gt;&lt;/asp:Label&gt;
                              &lt;/ItemTemplate&gt;
                              &lt;/asp:TemplateField&gt;                       
                              &lt;asp:BoundField DataField="Name" HeaderText="Name" /&gt;
                          &lt;/Columns&gt;
                       &lt;/asp:GridView&gt;
  
                      &lt;asp:SqlDataSource ID="SqlDataSource4" runat="server"
                          ConnectionString="&lt;%$ ConnectionStrings:RegisterConnectionString %&gt;" 
                          SelectCommand="SELECT [StudentID], [Name] FROM [Student] WHERE CourseID = @CourseID "&gt;                         
                          &lt;SelectParameters&gt;
                              &lt;asp:ControlParameter ControlID="CourseDropDownList" Name="CourseID" 
                                  PropertyName="SelectedValue" Type="Int32" /&gt;
                          &lt;/SelectParameters&gt;
                      &lt;/asp:SqlDataSource&gt;
  </code></pre>
  
  <p>I have a button on the page which when the user clicks the button I need to loop through each row in the GridView, then find the CheckBox then I need to check if the checkbox is checked or not. If the checkbox is checked I need to add the value in the Label Template Field to a different table in the database. 
  I am using C# Code.
  Any help is much appreciated, thanks in advance!</p>