使用javacsript在网格视图中获取复选框的相应行值 [英] get the corresponding row values for check box checked row in grid view using javacsript

查看:119
本文介绍了使用javacsript在网格视图中获取复选框的相应行值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

每行都有复选框,我想在选中复选框时获得相应的选定行单元格值。
当复选框被选中时,我可以给出警报但不知道如何获得选定的行单元格值。

I have following grid with check boxes on each row, i want to get the corresponding selected row cells value when i checked the check box .. I am able to give the alert when the check box is checked but not sure how to get the selected row cells value ..

这是我的gridview

this is my gridview

  <asp:GridView ID="gvPRCertInfo" runat="server" AutoGenerateColumns="False" 
      GridLines="None"                      
      CellSpacing="1" CellPadding="1"
      Width="95%" BorderWidth="0"
      AllowSorting="True"
      PageSize="30"
      OnRowDataBound="gvPRCertInfo_RowDataBound"
      CssClass="data responsive">
      <Columns>
         <asp:TemplateField HeaderText="Select" SortExpression="">
            <HeaderTemplate>
               <asp:CheckBox ID="chkboxSelectAll" runat="server" AutoPostBack="true"  OnCheckedChanged="chkboxSelectAll_CheckedChanged"/>
            </HeaderTemplate>
            <ItemTemplate>
               <asp:CheckBox ID="chkCert" AutoPostBack="true" OnCheckedChanged="chkCert_CheckedChanged" OnClick="checkForVirtual(this);" runat="server" />
               <input type="hidden" id="hdnCertId" runat="server" value='<%# DataBinder.Eval(Container.DataItem, "CertId") %>' />
            </ItemTemplate>
         </asp:TemplateField>
         <asp:BoundField DataField="CertificateID" HeaderText="Certificate ID" HeaderStyle-HorizontalAlign="Center" />
         <asp:BoundField DataField="partID" HeaderText="Part Number" HeaderStyle-HorizontalAlign="Center" />
         <asp:BoundField DataField="PartDesc" HeaderText="Part Description" HeaderStyle-HorizontalAlign="Center" />
         <asp:BoundField DataField="platformType" HeaderText="platformType" Visible="false" />

 ...................................
 ...................................

      </Columns>
      <EmptyDataRowStyle CssClass="AlternatingRowStyle" />     
  </asp:GridView>

这是我的复选框javascript函数

And this is my checkbox javascript function

  function checkForVirtual(checkBox){
    if(checkBox.checked)
    {
        alert('checked');

       /// here i need to get selected checked row all cells value 
    }
 }

任何人都可以提出任何想法,这将是非常感谢我..

Could any one please suggest any ideas on this that would be very grateful to me..

很多在此先感谢..

推荐答案

您可以这样做。它将一个函数附加到复选框更改中,找到最近的 tr 并循环所有的 td

You can do this. It attaches a function to the checkbox change, finds the nearest tr and loops all the td

<script type="text/javascript">
    $(document).ready(function () {
        $('#<%= gvPRCertInfo.ClientID %> input[type="checkbox"]').change(function () {
            $(this).closest('tr').children('td').each(function () {
                alert($(this).html());
            });
        });
    });
</script>

然而,您有一个 AutoPostBack =true在你的复选框中,所以你在javascript中做的所有事情都会因为回发而立即丢失。

However you have an AutoPostBack="true" in your checkbox, so everything you do in javascript is lost immediately due to a PostBack.

这篇关于使用javacsript在网格视图中获取复选框的相应行值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆