[英]How can I access a row through data-id attribute in asp.net webforms?
How can I access a row through data-id attribute in asp.net webforms? 如何通过asp.net Webforms中的data-id属性访问行? I have an edit button in a column on my table and I need to access the User_ID in that row.
我在表格的一列中有一个编辑按钮,我需要访问该行中的User_ID。 I I've seen examples with MVC but not webforms.
我见过MVC的示例,但没有Webforms。
<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#EditMenu" id="btnEdit" data-id="<%=TableId.Rows["User_ID"] %>">
Edit
</button>
You can achieve this via jQuery as follows: 您可以通过jQuery如下实现:
$('#btnEdit').on('click', function(){
var userId = $(this).data('id');
//do something with userId
});
Please note the above snippet will work only if you are using jQuery version 1.4.3 or greater. 请注意,以上代码段仅在使用jQuery 1.4.3或更高版本时有效。 If it's not then use the below snippet:
如果不是,请使用以下代码段:
$('#btnEdit').on('click', function(){
var userId = $(this).attr("data-id")
//do something with userId
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.