开发者

JQuery selector for (ASP.NET) ButtonField in GridView

I have a couple of ButtonFields in my gridview, corresponding to "Edit" and "Delete".

I'd like to use JQuery in my code for a delete confirmation popup.

ButtonField renders as "a href"'s in HTML, but I'm at a loss in forming a JQuery selector that targets only the "Delete" link, since ButtonField doesn't accept ID nor Name. I'm considering using TemplateField instead, but I'd like to check for other alternatives as I'd like to keep my OnRowCommand attribute in the GridVi开发者_开发技巧ew tag.


if you have look at the selector documentation on the jquery site you'll see the :contains(text) selector (link).

this is how I'd use it:

$(".gridViewClass a:contains('Delete')").click(function(){ /*your code here*/ });

Please note that this is extremely fragile and that if you ever change the text of the button (or you localize it to different languages) then the code will not work.

Consider putting a css class on your delete link in which case you'll be able to do this:

$(".gridViewClass a.deleteLink").click(function() { /* your code here */ });

This is a much more robust way of doing this.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜