I have this custom 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>
I need to create a web method in code behind and call with jquery, but how I'll bind listView with jquery?
I don't think you can do as per my knowledge. because this is due to difference in static and instance.
if you are doing this only for page post back then there are some other ways to avoid post back but if you are want to bind your data via Ajax only then you can return data from WebMethod and do your data bind on ajax success. please have a look on this post here