title: Loop through GridView using JQuery or Javascript
body: <p>I am developing a form on which i have a <code>GridView</code>.In each row of <code>GridView</code>,i have one <code>DropDownList</code> with values Present &amp; Absent and some TextBoxes and one submit button.
  If i select Present then all the TextBoxes get enabled and enters values.
  If i select Absent then all the TextBoxes get disabled.</p>
  
  <p>On submit button i want to write a JQuery Or Javascript Code to check if user has selected Present and do not enter marks and want to show an alert.</p>
  
  <p>I've tried following JQuery Code but i don't understand what i'm doing wrong in that code.</p>
  
  <pre><code>$("#&lt;%=grdOJTResult.ClientID%&gt; tr").each(function () {
  
                  var Value = $(this).closest("tr").find("select[id*=ddlStatus]").val();
  
                  if (Value == 0) {
                      if ($(this).closest("tr").find("input[id*=txtAttendance]").val() == "") {
                          alert("Please Enter Attendance.");
                          $(this).closest("tr").find("input[id*=txtAttendance]").focus();
                          return false;
                      }
                      else if ($(this).closest("tr").find("input[id*=txtWritten]").val() == "") {
                          alert("Please Enter Written Marks.");
                          $(this).closest("tr").find("input[id*=txtWritten]").focus();
                          return false;
                      }
                      else if ($(this).closest("tr").find("input[id*=txtTurnOut]").val() == "") {
                          alert("Please Enter TurnOut Marks.");
                          $(this).closest("tr").find("input[id*=txtTurnOut]").focus();
                          return false;
                      }
                      else if ($(this).closest("tr").find("input[id*=txtSmartness]").val() == "") {
                          alert("Please Enter Smartness Marks.");
                          $(this).closest("tr").find("input[id*=txtSmartness]").focus();
                          return false;
                      }
                      else if ($(this).closest("tr").find("input[id*=txtKnowledge]").val() == "") {
                          alert("Please Enter Knowledge Marks.");
                          $(this).closest("tr").find("input[id*=txtKnowledge]").focus();
                          return false;
                      }
                      else if ($(this).closest("tr").find("input[id*=txtLanguage]").val() == "") {
                          alert("Please Enter Language Marks.");
                          $(this).closest("tr").find("input[id*=txtLanguage]").focus();
                          return false;
                      }
                      else if ($(this).closest("tr").find("input[id*=txtAttitude]").val() == "") {
                          alert("Please Enter Attitude Marks.");
                          $(this).closest("tr").find("input[id*=txtAttitude]").focus();
                          return false;
                      }
                  }
              });
  </code></pre>
  
  <p>Below is my GridView.</p>
  
  <pre><code>&lt;asp:GridView ID="grdOJTResult" runat="server" AutoGenerateColumns="false" Width="98%"
                      CssClass="mGrid" DataKeyNames="EmpId,BatchId" HorizontalAlign="Center"&gt;
                      &lt;Columns&gt;
                          &lt;asp:BoundField DataField="EmpCode" HeaderText="Employee Code" ItemStyle-HorizontalAlign="Center"&gt;
                              &lt;ItemStyle HorizontalAlign="Center" /&gt;
                          &lt;/asp:BoundField&gt;
                          &lt;asp:BoundField DataField="EmpFullName" HeaderText="Employee Name" ItemStyle-HorizontalAlign="Center"&gt;
                              &lt;ItemStyle HorizontalAlign="Center" /&gt;
                          &lt;/asp:BoundField&gt;
                          &lt;asp:TemplateField HeaderText="ATTENDANCE (16)" ItemStyle-HorizontalAlign="Center"&gt;
                              &lt;ItemTemplate&gt;
                                  &lt;asp:TextBox ID="txtAttendance" Width="50px" MaxLength="4" runat="server" &gt;&lt;/asp:TextBox&gt;
                                  &lt;Cc1:FilteredTextBoxExtender ID="FilteredTextBoxExtender1" runat="server" Enabled="True"
                                      FilterType="Custom,Numbers" TargetControlID="txtAttendance" ValidChars="."&gt;
                                  &lt;/Cc1:FilteredTextBoxExtender&gt;
                              &lt;/ItemTemplate&gt;
                              &lt;ItemStyle HorizontalAlign="Center" /&gt;
                          &lt;/asp:TemplateField&gt;
                          &lt;asp:TemplateField HeaderText="WRITTEN MARKS (34)" ItemStyle-HorizontalAlign="Center"&gt;
                              &lt;ItemTemplate&gt;
                                  &lt;asp:TextBox ID="txtWritten" Width="50px" MaxLength="3" runat="server" &gt;&lt;/asp:TextBox&gt;
                                  &lt;Cc1:FilteredTextBoxExtender ID="FilteredTextBoxExtender2" runat="server" Enabled="True"
                                      FilterType="Custom,Numbers" TargetControlID="txtWritten" ValidChars="."&gt;
                                  &lt;/Cc1:FilteredTextBoxExtender&gt;
                              &lt;/ItemTemplate&gt;
                              &lt;ItemStyle HorizontalAlign="Center" /&gt;
                          &lt;/asp:TemplateField&gt;
                          &lt;asp:TemplateField HeaderText="TURN OUT (10)" ItemStyle-HorizontalAlign="Center"&gt;
                              &lt;ItemTemplate&gt;
                                  &lt;asp:TextBox ID="txtTurnOut" Width="50px" MaxLength="3" runat="server" &gt;&lt;/asp:TextBox&gt;
                                  &lt;Cc1:FilteredTextBoxExtender ID="FilteredTextBoxExtender3" runat="server" Enabled="True"
                                      FilterType="Custom,Numbers" TargetControlID="txtTurnOut" ValidChars="."&gt;
                                  &lt;/Cc1:FilteredTextBoxExtender&gt;
                              &lt;/ItemTemplate&gt;
                              &lt;ItemStyle HorizontalAlign="Center" /&gt;
                          &lt;/asp:TemplateField&gt;
                          &lt;asp:TemplateField HeaderText="SMARTNESS (10)" ItemStyle-HorizontalAlign="Center"&gt;
                              &lt;ItemTemplate&gt;
                                  &lt;asp:TextBox ID="txtSmartness" Width="50px" MaxLength="3" runat="server" &gt;&lt;/asp:TextBox&gt;
                                  &lt;Cc1:FilteredTextBoxExtender ID="FilteredTextBoxExtender4" runat="server" Enabled="True"
                                      FilterType="Custom,Numbers" TargetControlID="txtSmartness" ValidChars="."&gt;
                                  &lt;/Cc1:FilteredTextBoxExtender&gt;
                              &lt;/ItemTemplate&gt;
                              &lt;ItemStyle HorizontalAlign="Center" /&gt;
                          &lt;/asp:TemplateField&gt;
                          &lt;asp:TemplateField HeaderText="KNOWLEDGE (10)" ItemStyle-HorizontalAlign="Center"&gt;
                              &lt;ItemTemplate&gt;
                                  &lt;asp:TextBox ID="txtKnowledge" Width="50px" MaxLength="3" runat="server" &gt;&lt;/asp:TextBox&gt;
                                  &lt;Cc1:FilteredTextBoxExtender ID="FilteredTextBoxExtender5" runat="server" Enabled="True"
                                      FilterType="Custom,Numbers" TargetControlID="txtKnowledge" ValidChars="."&gt;
                                  &lt;/Cc1:FilteredTextBoxExtender&gt;
                              &lt;/ItemTemplate&gt;
                              &lt;ItemStyle HorizontalAlign="Center" /&gt;
                          &lt;/asp:TemplateField&gt;
                          &lt;asp:TemplateField HeaderText="LANGUAGE (10)" ItemStyle-HorizontalAlign="Center"&gt;
                              &lt;ItemTemplate&gt;
                                  &lt;asp:TextBox ID="txtLanguage" Width="50px" MaxLength="3" runat="server" &gt;&lt;/asp:TextBox&gt;
                                  &lt;Cc1:FilteredTextBoxExtender ID="FilteredTextBoxExtender6" runat="server" Enabled="True"
                                      FilterType="Custom,Numbers" TargetControlID="txtLanguage" ValidChars="."&gt;
                                  &lt;/Cc1:FilteredTextBoxExtender&gt;
                              &lt;/ItemTemplate&gt;
                              &lt;ItemStyle HorizontalAlign="Center" /&gt;
                          &lt;/asp:TemplateField&gt;
                          &lt;asp:TemplateField HeaderText="ATTITUDE (10)" ItemStyle-HorizontalAlign="Center"&gt;
                              &lt;ItemTemplate&gt;
                                  &lt;asp:TextBox ID="txtAttitude" Width="50px" MaxLength="3" runat="server" &gt;&lt;/asp:TextBox&gt;
                                  &lt;Cc1:FilteredTextBoxExtender ID="FilteredTextBoxExtender7" runat="server" Enabled="True"
                                      FilterType="Custom,Numbers" TargetControlID="txtAttitude" ValidChars="."&gt;
                                  &lt;/Cc1:FilteredTextBoxExtender&gt;
                              &lt;/ItemTemplate&gt;
                              &lt;ItemStyle HorizontalAlign="Center" /&gt;
                          &lt;/asp:TemplateField&gt;
                          &lt;asp:TemplateField HeaderText="TOTAL MARKS (100)" ItemStyle-HorizontalAlign="Center"&gt;
                              &lt;ItemTemplate&gt;
                                  &lt;asp:TextBox ID="txtTotal" Width="50px" MaxLength="3" runat="server" ReadOnly="true"&gt;&lt;/asp:TextBox&gt;
                              &lt;/ItemTemplate&gt;
                              &lt;ItemStyle HorizontalAlign="Center" /&gt;
                          &lt;/asp:TemplateField&gt;
                          &lt;asp:TemplateField HeaderText="STATUS" ItemStyle-HorizontalAlign="Center"&gt;
                              &lt;ItemTemplate&gt;
                                  &lt;asp:DropDownList ID="ddlStatus" Width="50px" runat="server" CssClass="ddlRes"&gt;
                                      &lt;asp:ListItem Text="Present" Value="0"&gt;&lt;/asp:ListItem&gt;
                                      &lt;asp:ListItem Text="Absent" Value="1"&gt;&lt;/asp:ListItem&gt;
                                      &lt;/asp:DropDownList&gt;
                              &lt;/ItemTemplate&gt;
                          &lt;/asp:TemplateField&gt;
                      &lt;/Columns&gt;
                  &lt;/asp:GridView&gt;
  </code></pre>