0

Hi I have following grid view

 <asp:GridView ID="GridView3" runat="server" AutoGenerateColumns="False">
            <Columns>
                <asp:TemplateField>
            <HeaderTemplate>
                <asp:CheckBox runat="server" ID="chkAll" />
            </HeaderTemplate>
            <ItemTemplate>
                <asp:CheckBox runat="server" ID="chkEmployee" />
            </ItemTemplate>
        </asp:TemplateField>
                <asp:TemplateField HeaderText="Id">
                    <ItemTemplate>
                        <asp:Label ID="lblId" runat="server" Text='<%# Eval("Id") %>'></asp:Label>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="Company">
                    <ItemTemplate>
                        <asp:Label ID="lblCompany" runat="server" Text='<%# Eval("Company") %>'></asp:Label>
                    </ItemTemplate>
                </asp:TemplateField>              
            </Columns>
        </asp:GridView>

Than I am using following jquery code to iterate through the gridview for the selected check boxes and retrieve the values of columns for each row. Code will iterate through each row fine but cant pick the values.

 $(document).ready(function () {
           $("#submit").click(function () {
               alert("clicked");
               $("#<%=GridView3.ClientID%> input[id*='chkEmployee']:checked").each(function () {

               var values=$(this).find("td:Company")+$(this).find("td:Id");
               });
           });
       });

Following line is the one not working.

 var values=$(this).find("td:Company")+$(this).find("td:Id");

Please help! Thanks

2 Answers 2

1

I have made sample for you.

$('[type="button"]').live("click", function () {
  $('tr [type="checkbox"]:checked').parent().parent().each(function () {    
     if ($(this).find('input[id*="lblCompany"]').length > 0) {
   alert($(this).find('input[id*="lblCompany"]').val() + "---" +    $(this).find('input[id*="lblId"]').val())
}

});

 });

FIDDLE Demo

Hope it helps your problem.

Sign up to request clarification or add additional context in comments.

Comments

0
<asp:GridView ID="gvUserInfo" runat="server" >  
 <HeaderStyle BackColor="#df5015" Font-Bold="true" ForeColor="White" />  
 <Columns>  
    <asp:TemplateField>  
    <ItemTemplate>  
             <asp:CheckBox ID="chkChild" runat="server" />  
           <asp:Label ID="lblId" runat="server" Text='<%# Eval("Id") %>'></asp:Label>  
            <asp:Label ID="lblCompany" runat="server" Text='<%# Eval("Company") %>'> </asp:Label>  
           <asp:HiddenField ID="hdnId" runat="server" Value='<%#Eval("Id") %>' />  
         <asp:HiddenField ID="hdnCompany" runat="server" Value='<%#Eval("Company") %>' />  
       </ItemTemplate>  
    </asp:TemplateField>  
    </Columns>  
   </asp:GridView>  
   </div>  
    <input type="button" id="btnGet" value="Get Selected Values" /><br /><br />  
    <b>Select UserNames:</b><label id="lbltxt"/>


   <script type="text/javascript">      
$(document).ready(function () {  
    $('#btnGet').click(function () {  
        var hdntxt = '';  
        $("input[name$=chkChild]:checked").each(function () {  
            hdntxt += "," + $(this).siblings("input[name$=lblId]").val()  
        });  
        $('#lbltxt').text(hdntxt.substring(1, hdntxt.length))  
    });  
});  
      </script>

Hope it will help

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.