如何使用jquery获取所选值的asp.net gridview隐藏字段 [英] how to get asp.net gridview hidden field of selected value using jquery

查看:162
本文介绍了如何使用jquery获取所选值的asp.net gridview隐藏字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在网格视图中隐藏了字段值我用linq查询绑定了我想通过asp:link按钮获取所选字段值我的asp.net代码是:


< pre lang = c# > < asp:TemplateField < span class =code-keyword>>
< ItemTemplate >
< asp:LinkBut​​ton ID = EditButton runat = server CausesValidation = 错误 CommandName = EditCol > 编辑< / asp:LinkBut​​ton >
< / ItemTemplate >
< / asp:TemplateField >
< asp:TemplateField >
< ItemTemplate < span class =code-keyword>>
< 输入 id = Hidden1 runat = server type = 隐藏 可见 = true class = H value =' <% #Bind( MBody%> ' / >
< / ItemTemplate >
< / asp:TemplateField >





当我想使用这个jquery代码获取选定的行值时:



 $( document )。on( 点击   [id * = EditButton] function (event){
event.preventDefault();
var body = $( [id * = Hidden1])VAL();
alert(body);
}





它只显示第一个边界字段值未选择值你能帮我解决这个问题吗?

解决方案

document )。on( 点击 [id * = EditButton] function (event){
event.preventDefault();
var body =


[id * = Hidden1])。val();
alert(正文);
}





它只展出了第一个边界字段值没有选择值你能帮我解决这个问题吗?


你正在使用模板,所以你的id永远不会出现在网格中,否则你应该最终得到了许多具有相同id的元素。想想有10行的数据集!在每一行都有一个隐藏字段,但它们的ID必须不同!

您可以使用基于类的jQuery选择器:

 

i have hidden field value inside a grid view i bound it with a linq query i want to get selected field value through asp:link button my asp.net code is :


<pre lang="c#"><asp:TemplateField>
                            <ItemTemplate>
                                <asp:LinkButton ID="EditButton" runat="server" CausesValidation="False" CommandName="EditCol">EDIT</asp:LinkButton>
                            </ItemTemplate>
                        </asp:TemplateField>
 <asp:TemplateField>
                            <ItemTemplate>
                                <input id="Hidden1" runat="server" type="hidden" visible="true" class="H" value='<%# Bind("MBody") %>' />
                            </ItemTemplate>
                        </asp:TemplateField>



when i want to get selected row value using this jquery code :

$(document).on("click", "[id*=EditButton]", function (event) {
            event.preventDefault();
            var body = $("[id*=Hidden1]").val();
alert(body);
}



it just exhibits the first bounding field value not selected value could you please help me to overcome this issue ?

解决方案

(document).on("click", "[id*=EditButton]", function (event) { event.preventDefault(); var body =


("[id*=Hidden1]").val(); alert(body); }



it just exhibits the first bounding field value not selected value could you please help me to overcome this issue ?


You are working with templates, so your ids are never will be presented in the grid, otherwise you should end up with numerous elements with the same id. Think about a data set with 10 rows! In every row there is a hidden field, but their ids must be different!
You may use a class based jQuery selector:


这篇关于如何使用jquery获取所选值的asp.net gridview隐藏字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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