简体   繁体   English

如何通过asp.net Webforms中的data-id属性访问行?

[英]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.

相关问题 如何在ASP.NET WebForms中以HttpRequestBase的形式访问请求? - How can I access the request as HttpRequestBase in ASP.NET WebForms? ASP.Net Core MVC 中的编辑方法为什么 javascript 中的“数据 ID”总是包含 1,如果我 select 项目 2 所以数据 ID 为 2 - Edit Method in ASP.Net Core MVC why 'data-id' in javascript always contains 1 i want if i select item 2 so data-id is 2 如何将Perl与ASP.NET Webforms集成? - How can I integrate Perl with ASP.NET Webforms? 如何检查Asp.Net WebForms会话大小 - How can I inspect Asp.Net WebForms session size 如何在ASP.Net WebForms的DataField上强制执行toUpper? - How can I enforce toUpper on a DataField in ASP.Net WebForms? 如何防止Asp.net Webforms中的XSS攻击? - How can I prevent XSS attack in Asp.net Webforms? 如何快速设计具有许多数据字段的ASP.Net Web表单详细信息页面? - How can I rapidly design ASP.Net webforms detail pages with many data fields? 使用webforms asp.net的Castle.Windsor和数据访问对象 - Castle.Windsor and data access object with webforms asp.net 如何在ASP.NET Webforms网站项目中一起使用Webforms和ASP.NET MVC? - How do I use Webforms and ASP.NET MVC together in an ASP.NET Webforms Website project? ASP.NET,Webforms如何获取URL id =? - ASP.NET, Webforms how to get url id=?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM