使用 Jquery - ASP NET 绑定自定义 ListView
Bind Custom ListView with Jquery - ASP NET
我有这个习惯ListView
:
<asp:ListView ID="lvCustomers" runat="server" DataKeyNames="customerID">
<ItemTemplate>
<div id="galeria" class="gallery w3-card-4 w3-animate-zoom">
<div class="w3-container w3-center">
<asp:Label CssClass="desc_cab" ID="lblCustomerName" Text='<%# Eval("customerName") %>' runat="server" />
</div>
<div class="w3-container w3-center">
<asp:ImageButton CssClass="img" ID="imgCustomer" ImageUrl='<%# Eval("customerPicture") %>' runat="server" alt="Norway" OnClick="imgCustomer_Click" />
</div>
</div>
</ItemTemplate>
</asp:ListView>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script type="text/javascript">
$(function () {
$.ajax({
type: "POST",
url: "Default.aspx/getCustomer",
data: '{}',
contentType: "application/json; charset=utf-8",
dataType: "json",
success: OnSuccess,
failure: function (response) {
alert(response.d);
},
error: function (response) {
alert(response.d);
}
});
});
function OnSuccess(response) {
// How to written code here?
}
}
</script>
我需要在代码隐藏中创建一个 Web 方法并使用 jquery 调用,但我将如何将 listView 与 jquery 绑定?
据我所知,我认为你做不到。因为这是静态和实例的不同。
如果您只对 post 页执行此操作,那么还有一些其他方法可以避免 post 返回,但如果您只想通过 Ajax 绑定数据,那么您可以 return 来自 WebMethod 的数据,并在 ajax 成功时进行数据绑定。请看看这个 post here
我有这个习惯ListView
:
<asp:ListView ID="lvCustomers" runat="server" DataKeyNames="customerID">
<ItemTemplate>
<div id="galeria" class="gallery w3-card-4 w3-animate-zoom">
<div class="w3-container w3-center">
<asp:Label CssClass="desc_cab" ID="lblCustomerName" Text='<%# Eval("customerName") %>' runat="server" />
</div>
<div class="w3-container w3-center">
<asp:ImageButton CssClass="img" ID="imgCustomer" ImageUrl='<%# Eval("customerPicture") %>' runat="server" alt="Norway" OnClick="imgCustomer_Click" />
</div>
</div>
</ItemTemplate>
</asp:ListView>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script type="text/javascript">
$(function () {
$.ajax({
type: "POST",
url: "Default.aspx/getCustomer",
data: '{}',
contentType: "application/json; charset=utf-8",
dataType: "json",
success: OnSuccess,
failure: function (response) {
alert(response.d);
},
error: function (response) {
alert(response.d);
}
});
});
function OnSuccess(response) {
// How to written code here?
}
}
</script>
我需要在代码隐藏中创建一个 Web 方法并使用 jquery 调用,但我将如何将 listView 与 jquery 绑定?
据我所知,我认为你做不到。因为这是静态和实例的不同。
如果您只对 post 页执行此操作,那么还有一些其他方法可以避免 post 返回,但如果您只想通过 Ajax 绑定数据,那么您可以 return 来自 WebMethod 的数据,并在 ajax 成功时进行数据绑定。请看看这个 post here