jQuery to loop through ASP.NET gridview asp.net
<p>suppose i have gridview in my aspx page and gridivew has many rows and 3 columns. column are </p>

<p>select - checkbox, first name - textbox ,last name - textbox etc</p>

<p>i want to loop through gridview by jquery and read those textbox value from that row where check box is selected.</p>

<h2>gridview look like</h2>

<pre><code>&lt;asp:GridView
    id="GridView1"
    DataSourceID="srcMovies"
    DataKeyNames="Id"
    Runat="server" AutoGenerateColumns="false"&gt;
</code></pre>

<p>
    
        
        
        
    </p>

<pre><code>&lt;asp:TemplateField&gt;
    &lt;ItemTemplate&gt;
    &lt;asp:Label ID="lblslno" runat="server" /&gt;    
    &lt;/ItemTemplate&gt;
&lt;/asp:TemplateField&gt;

&lt;asp:TemplateField&gt;
    &lt;ItemTemplate&gt;
    &lt;asp:TextBox ID="txtFName" runat="server" /&gt;    
    &lt;/ItemTemplate&gt;
&lt;/asp:TemplateField&gt;

&lt;asp:TemplateField&gt;
    &lt;ItemTemplate&gt;
    &lt;asp:TextBox ID="txtLName" runat="server" /&gt;    
    &lt;/ItemTemplate&gt;
&lt;/asp:TemplateField&gt;

&lt;/Columns&gt;
&lt;/asp:GridView&gt;   
</code></pre>

<p>i got jquery code to read textbox value from each row if checkbox is selected...here is code</p>

<pre><code> &lt;script type="text/javascript"&gt;
 $(document).ready(function () {
     var sum = 0;
     $('#btn1').click(function () {
         $('#tr').each(function () {
             if ($(this).find('input:checkbox').attr("checked"))
                 sum += parseInt($(this).find('input:text').attr("value"));
         });
         window.alert(sum.toString());
     });
 });
&lt;/script&gt;
</code></pre>

<p>my concern is how to read data from txtFName &amp; txtLName textboxes and label lblslno on each row. can anyone drive toward right code. thanks</p>

<h2>i got a good solution....here it is</h2>

<pre><code>&lt;script src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.5.js" type="text/javascript"&gt;&lt;/script&gt;
&lt;script src="http://jquery-json.googlecode.com/files/jquery.json-2.2.min.js" type="text/javascript"&gt;&lt;/script&gt;

&lt;script type="text/javascript"&gt;
$(document).ready(function() {
    var jsonData = new Array();
    $(".getJSON").click(function() {
        $.map($("table[id*=gvPurchaseOrderDetails] tr"), function(item, index) {
            if ($(item).find("input[type=text]").length&gt;0) {
                jsonData[index] = new Object();
                jsonData[index].employeeid = $(item).find("input[type=text][id*=employeeid]").val();
                jsonData[index].employeename = $(item).find("input[type=text][id*=employeename]").val();
                jsonData[index].sex = $(item).find("select[id*=sex]").val();
                jsonData[index].graduate = $(item).find("input[type=checkbox][id*=graduate]").attr("checked");
            }
        });

        var jsonStringData = JSON.stringify(jsonData);
    });
});
</code></pre>

<p></p>

<pre><code>&lt;asp:GridView ID="gvPurchaseOrderDetails" runat="server"
    AutoGenerateColumns="false"&gt;
    &lt;Columns&gt;
        &lt;asp:TemplateField HeaderText="employeeid"&gt;
            &lt;ItemTemplate&gt;
                &lt;asp:TextBox ID="employeeid" runat="server" /&gt;
            &lt;/ItemTemplate&gt;
        &lt;/asp:TemplateField&gt;
        &lt;asp:TemplateField HeaderText="employeename"&gt;
            &lt;ItemTemplate&gt;
                &lt;asp:TextBox ID="employeename" runat="server" /&gt;
            &lt;/ItemTemplate&gt;
        &lt;/asp:TemplateField&gt;
       &lt;asp:TemplateField HeaderText="sex"&gt;
            &lt;ItemTemplate&gt;
                &lt;asp:DropDownList ID="sex" runat="server" &gt;&lt;asp:ListItem&gt;Male&lt;/asp:ListItem&gt;&lt;asp:ListItem&gt;Female&lt;/asp:ListItem&gt;&lt;/asp:DropDownList&gt;
            &lt;/ItemTemplate&gt;
        &lt;/asp:TemplateField&gt;
        &lt;asp:TemplateField HeaderText="Is Graduate"&gt;
            &lt;ItemTemplate&gt;
                &lt;asp:CheckBox ID="graduate" runat="server" /&gt;
            &lt;/ItemTemplate&gt;
        &lt;/asp:TemplateField&gt;
    &lt;/Columns&gt;
&lt;/asp:GridView&gt;
&lt;a class="getJSON" href="#"&gt;get json data&lt;/a&gt;
</code></pre>
