简体   繁体   中英

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? I have an edit button in a column on my table and I need to access the User_ID in that row. I I've seen examples with MVC but not 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:

$('#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. If it's not then use the below snippet:

$('#btnEdit').on('click', function(){
    var userId = $(this).attr("data-id")
    //do something with userId 
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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