1
如何獲取ImageButton ID以便我可以使用它打開jquery對話框?如何從GridView中的ImageButton打開jQuery對話框?
通過硬鍵入ImageButton ID,它按預期工作。即:
$('#ContentPlaceHolder1_GridView1_linkPasswordEdit_0').click(function() {
$('#dialog-modal2').dialog('open');
return false;
});
但是,我想要在GridView中的所有ImageButton而不僅僅是第一個。我已經試過各種方法,如:
$('#ContentPlaceHolder1_GridView1_' + '<%# linkPasswordEdit.ClientID %>').click(function() {
$('#dialog-modal2').dialog('open');
return false;
});
或者:
$('#' + '<%# ContentPlaceHolder1.GridView1.((GridViewRow)Container).FindControl("linkPasswordEdit").ClientID %>').click(function() {
$('#dialog-modal2').dialog('open');
return false;
});
這是ImageButton的樣子:
<asp:TemplateField ShowHeader="False">
<ItemTemplate>
<asp:ImageButton ID="linkPasswordEdit" runat="server" CausesValidation="false" OnCommand="passwordEditCommand"
CommandArgument='<%#Eval("id")%>' ToolTip="Click to edit password" ImageUrl="~/Images/imagesActions/password_edit.png"
AlternateText='<%#Eval("userName")%>' />
</ItemTemplate>
</asp:TemplateField>
任何幫助將不勝感激。
謝謝。不知何故,我沒有想到這種可能性。現在我想知道我怎麼能確定哪個鏈接被點擊了,我的意思是,哪一個打開對話框?我需要獲取<%#Eval(「id」)%>作爲jquery對話框中的參數。提前致謝! – aleafonso 2012-02-22 17:34:51
試試這個:http://stackoverflow.com/questions/48239/getting-the-id-of-the-element-that-fired-an-event-using-jquery – swannee 2012-02-22 17:43:22
在這種情況下,你可以評估數據將「Id」添加到自定義屬性中,然後按照上述帖子的一些答案中的說明操作。基本上使用JQuery .attr方法從自定義屬性中檢索值。 – swannee 2012-02-22 17:45:38