简体   繁体   English

有没有办法使用javascript访问gridview中复选框的选中值

[英]Is there a way to access the checked value of a checkbox in a gridview using javascript

So I have a template field with a checkbox and a hidden field in it. 因此,我有一个带有复选框的模板字段和一个隐藏字段。

 <asp:TemplateField>
    <ItemTemplate>
       <asp:CheckBox runat="server" ID="chkAdd" />
       <asp:HiddenField runat="server" ID="hfValue" Value='<%Item.SomeValue%>'/>
    </ItemTemplate>
 </asp:TemplateField>

Using javascript, I want to able to look through to see which checkboxes are checked and get the corresponding value stored in the the HiddenValue control. 使用javascript,我希望能够浏览以查看选中了哪些复选框,并获取存储在HiddenValue控件中的相应值。

I know how to loop through the rows of a gridview and get a cell's innerText. 我知道如何遍历gridview的行并获取单元格的innerText。 How would I go about getting a checkbox's checked and a hidden field's value? 我将如何获取复选框的复选框和隐藏字段的值?

IF you want to find hidden field value from gridview on check changed of check box of gridview by javascript then you can use like below function. 如果您想通过javascript更改gridview复选框的复选框来从gridview查找隐藏字段值,则可以使用以下功能。

   function IAmSelected(source, eventArgs) {
                if (source) {
                    // Get the HiddenField ID.
                    var hiddenfieldID = source.get_id().replace("chkAdd", "hfValue");// here you can add any control of your gridview row which value you want
                    $get(hiddenfieldID).value = eventArgs.get_value();
                }
      }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM