[英]How to passing Repeater Row ID to javascript/jquery and change image
我想做的是:
我有一張桌子(中繼器),可以顯示各種會話。 在每節課中,我可以計算您的費用。 為此,我有linkButton lnkGenerate 。 產生費用后,圖像會自動更改,並變為lnkDelete 。 (這在ascx.cs中完成)
<asp:Repeater ID="rpt1" runat="server" EnableViewState="false" OnItemCommand="rpt1_ItemCommand">
<HeaderTemplate>
<table cellpadding="4" cellspacing="0" width="100%">
<tr style="color: Black; white-space: nowrap;">
<th style="width: 90%">
Session
</th>
<th style="width: 10%;">
Session Value
</th>
<th style="white-space: nowrap;">
</th>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr id="row" runat="server">
<td align="left" style="white-space: nowrap">
<%# ((Session)Container.DataItem).Name %>
</td>
<td align="center">
<%# ((Session)Container.DataItem).ValueSession > 0 ? ((Session)Container.DataItem).ValueSession.ToString() : "-" %>
</td>
<td style="white-space: nowrap;">
<asp:LinkButton ID="lnkGenerate" runat="server" ToolTip="Generate" CausesValidation="false" OnClientClick="showImg(this);"
CommandName="generate" Visible='<%# ((Session)Container.DataItem).ValueSession == 0 && !this.IsBlock %>'>
<asp:Image ID="imgGenerate" runat="server" ToolTip="Generate" SkinID="imgGenerateAuto" />
</asp:LinkButton>
<asp:LinkButton ID="lnkDelete" runat="server" ToolTip="Delete" CausesValidation="false"
CommandName="delete" Visible='<%# ((Session)Container.DataItem).ValueSession > 0 && !this.IsBlock %>'>
<asp:Image ID="imgDelete" runat="server" ToolTip="Delete" SkinID="imgDeleteAuto" />
</asp:LinkButton>
</td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
我想要的是:
單擊圖像以生成成本,將其更改為“ 加載 ”圖像,然后進行計算,請轉到lnkDelete 。 我嘗試使用javascript,但是每一行都有我無法獲取的特定ID。
有什么建議嗎?
在嘗試了先前提出的解決方案之后,我決定從頭開始重寫答案。 我在VS上創建了一個新項目,並測試了以下代碼。 這是您所擁有的簡化版本,但是可以按預期工作:
1)請注意,您不再需要附加的OnClientClick事件。
2)只需將CssClass定義到LinkButton並將處理程序附加到click事件即可。
<head runat="server">
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(function () {
$(".linkButton").on("click", function (e) {
// As I don't have any code running on the code behind,
// it would replace the image and return to the original
// one pretty quick, so I'm stopping the postback.
e.preventDefault();
$(this).find("img").attr("src", "http://www.bedlingtonterriersfc.com/wp-content/uploads/2013/06/ball-50x50.png");
return true;
});
});
</script>
</head>
<asp:Repeater ID="rptr" runat="server" onitemcommand="rptr_ItemCommand">
<ItemTemplate>
<asp:LinkButton CssClass="linkButton" CommandName="cmd1" runat="server">
<asp:Image runat="server" AlternateText="" ImageUrl="http://static.miniclipcdn.com/images/awards/store/32_50.png" />
</asp:LinkButton>
</ItemTemplate>
</asp:Repeater>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.