Solution
I downloaded the code at -
LOAD ON DEMAND DATA IN GRIDVIEW ON SCROLL USING ASP.NET AND JQUERY AJAX[
^].
Then added one
LinkButton
to the
GridView
, so modified
GridView
is as follows...
<asp:GridView ID="gvCustomers" runat="server" AutoGenerateColumns="false" CssClass="Grid"
Width="500" OnRowCommand="gvCustomers_RowCommand">
<Columns>
<asp:BoundField DataField="ContactName" HeaderText="Customer Name" ItemStyle-CssClass="name"
ItemStyle-Width="200" HeaderStyle-Width="200" />
<asp:BoundField DataField="City" HeaderText="City" ItemStyle-CssClass="city" ItemStyle-Width="100"
HeaderStyle-Width="100" />
<asp:BoundField DataField="Country" HeaderText="Country" ItemStyle-CssClass="country"
ItemStyle-Width="100" HeaderStyle-Width="100" />
<asp:BoundField DataField="PostalCode" HeaderText="Postal Code" ItemStyle-CssClass="postal"
ItemStyle-Width="100" HeaderStyle-Width="100" />
<asp:TemplateField>
<ItemTemplate>
<asp:LinkButton ID="btn" runat="server" ClientIDMode="Static" CommandName="click"
CommandArgument='<%# Bind("ContactName") %>'>Click</asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
</Columns>
Now added the
RowCommand
Event in Code Behind and put a Break Point inside the function as follows.
protected void gvCustomers_RowCommand(Object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "click")
{
}
}
Now, it's hitting the
RowCommand
Event for all the rows created dynamically by
jQuery
.
Modified Demo
GridView OnDemand Row OnScrolling[
^]
Update
As the
href
attribute were same for all the dynamically created rows by
jQuery
, so the
OnSuccess
Method is modified to make it unique.
function OnSuccess(response) {
var xmlDoc = $.parseXML(response.d);
var xml = $(xmlDoc);
pageCount = parseInt(xml.find("PageCount").eq(0).find("PageCount").text());
var customers = xml.find("Customers");
$("[id$=gvCustomers] .loader").remove();
customers.each(function () {
var customer = $(this);
var row = $("[id$=gvCustomers] tr").eq(0).clone(true);
$(".name", row).html(customer.find("ContactName").text());
$(".city", row).html(customer.find("City").text());
$(".postal", row).html(customer.find("PostalCode").text());
$(".country", row).html(customer.find("Country").text());
var lastRowNumber = parseInt($("[id$=gvCustomers] tr").eq($("[id$=gvCustomers] tr").length - 1).index()) + 2;
$("#btn", row).attr("href", "javascript:__doPostBack('gvCustomers$ctl" + (lastRowNumber + 1) + "$btn','')");
$("[id$=gvCustomers]").append(row);
});
$("#loader").hide();
}