Search This Blog

Tuesday, August 28, 2012

Get selected checkbox row from datagrid by jquery

HTML Code:


<asp:DataGrid ID="dgdProduct" runat="server"  >
                 <Columns>
                         <asp:TemplateColumn>
                                <ItemTemplate>
                                      <asp:CheckBox ID="chkP" runat="server"     />
                                     <input id="hdID" type="hidden"  value='<%# Eval("pCode") %>' />
                                    </ItemTemplate>
                           </asp:TemplateColumn>
                           <asp:BoundColumn DataField="pDescription" HeaderText="Product Description">
                              </asp:BoundColumn>
                             <asp:BoundColumn DataField="Quantity" HeaderText="Quantity">
                            </asp:BoundColumn>
                          </Columns>
 </asp:DataGrid>

JQuery Code:

         var $table = $("#dgdProduct"),
              $headerCells = $table.find("thead th"),
              $rows = $table.find("tbody tr");
          var   rows = [];
          var isChecked;
          var pcode;
         var pDescription;
          $rows.each(function(row, v) {
              var $td = $(this).closest('tr').children('td');
              $td.find("input:checkbox").each(function() {
                  isChecked = $(this).attr('checked');
                
              });

              if ($td.length > 0) {
                  if (isChecked == true) {
                      pcode= $td.find('input:hidden[id$=hdID]').val();
                    pDescription=$td.eq(1).text() ;
                  }
              }
          });

2 comments: