這是我的ListView控件:如何在jQuery中在asp.net中觸發按鈕單擊事件內部列表視圖?
<asp:ListView ID="PortfolioListView" runat="server" onitemcommand="PortfolioListView_ItemCommand">
<ItemTemplate>
<li class="item brick1 <%# Eval(" CategoryName ")%> isotope-item">
<a class="item-popup" href="Gallery/195x195/<%# Eval(" MainImage ") %>" title="<%# Eval(" ShortDesc ") %>">
<img src="Gallery/195x195/<%# Eval("MainImage") %>" alt="<%# Eval("Title") %>" />
<div class="hover">
<span class="Popup">
<i class="fa fa-search-plus"></i>
</span>
<span><%# Eval("CategoryName")%></span>
</div>
</a>
<div class="bottom">
<div class="isotope-title"><span><%# Eval("Title")%></span>
</div>
<div class="like">
<a class="update">
<i class="fa fa-thumbs-o-up"></i>
<span><%# Eval("Counter")%></span>
</a>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<div class="flike">
<asp:LinkButton ID="LikeLBTN" runat="server" CssClass="likeBTN" ClientIDMode="AutoID" CommandName="Like" CommandArgument="<%# Bind('GalleryID') %>">
<i class="fa fa-thumbs-o-up"></i>
<span><%# Eval("Counter")%></span>
</asp:LinkButton>
</div>
</ContentTemplate>
</asp:UpdatePanel>
</div>
</div>
</li>
</ItemTemplate>
</asp:ListView>
我有一個LinkButton內的ListView和LinkButton(CommandName="Like" CommandArgument="<%# Bind('GalleryID') %>")
onitemcommand
事件列表視圖觸發的。
我在aspx.cs PortfolioListView_ItemCommand:
protected void PortfolioListView_ItemCommand(object sender, ListViewCommandEventArgs e)
{
DBClass dbc = new DBClass();
int index = int.Parse(e.CommandArgument.ToString());
string cmd = e.CommandName;
if (cmd == "Like")
{
string selstr = String.Format("Update Gallery set [Counter]=[Counter]+1 where GalleryID = {0}", index.ToString());
int res = dbc.RunCommand(selstr);
selstr = String.Format("SELECT GalleryID, Title, MainImage, Counter, ShortDesc, CategoryName FROM Gallery inner join GalleryCat on Gallery.CatID = GalleryCat.CatID Order By PDate desc");
dbc.LoadInList(PortfolioListView, selstr);
}
}
我要當點擊a
標籤與ListView中class="update"
,點擊LinkButton的觸發和我PortfolioListView_ItemCommand事件代碼的事件運行。現在這應該怎麼用jQuery或JavaScript來完成?謝謝。
當我使用你的代碼時,我遇到了錯誤,因爲我的LinkButton在ListView裏面。你有另一種解決方案嗎? –
會有多個linkButton,所以你想打電話給哪一個? – Rajesh
我想要點擊類更新時,我的代碼在PortfolioListView_ItemCommand中的服務器端運行。所以所有的LinkButton。 –