动态加载的gridview中的Fire事件 [英] Fire event in dynamically loaded gridview
问题描述
大家好。我想触发gridview的commandevent,它是动态加载的。动态意味着在网格div的滚动上,我在gridview中绑定数据。为此,我将关注这篇文章 http://www.aspsnippets.com/Articles/Load-on-demand-data-in-GridView-on-scroll-using-ASPNet-and-jQuery-AJAX.aspx [ ^ ]
但是现在假设我想在gridview中添加按钮,点击那个按钮我想要触发gridview的commandevent 。我可以使用jquery来做到这一点。但是我想要触发gridview的命令事件。
是否可以这样做?我再次使用jquery可以做到这一点,但我想使用gridview rowcommand来做到这一点。是否可以这样做?
希望最好的答案将会出来。
谢谢,
Harshil
解决方案
我下载了代码 - 使用ASP.NET和JQUERY AJAX在GRIDVIEW上加载需求数据 [ ^ ]。
然后在GridView
中添加了一个LinkButton
,因此修改了GridView
如下...
< asp: GridView ID = gvCustomers runat = server AutoGenerateColumns = false CssClass = 网格
宽度 = 500 OnRowCommand = gvCustomers_RowCommand >
< 列 >
< asp:BoundField < span class =code-attribute> DataField = ContactName HeaderText = 客户名称 ItemStyle-CssClass = name
ItemStyle-Width = 200 HeaderStyle-Width = 200 / >
< asp: BoundField DataField = 城市 HeaderText = 城市 ItemStyle-CssClass = city ItemStyle-Width = 100
HeaderStyle-Width = 100 / < span class =code-keyword>>
< asp:BoundField DataField = 国家/地区 HeaderText = 国家/地区 ItemStyle-CssClass = country
< span class =code-attribute> ItemStyle-Width = 100 HeaderStyle-Width = 100 / >
< asp:BoundField DataField = PostalCode HeaderText = 邮政编码 ItemStyle-CssClass = 邮政
< span class =code-attribute> ItemStyle-Width = 100 HeaderStyle-Width = 100 / >
< asp:TemplateField >
< ItemTemplate >
< asp :LinkButton ID = btn runat = server ClientIDMode = 静态 CommandName = 点击
< span class =code-attribute> CommandArgument =' <% #Bind( ContactName)%> ' > 点击< / asp:LinkButton >
< / ItemTemplate >
< / asp:TemplateField >
< /列 >
现在在Code Behind中添加RowCommand
事件,并在函数中放置一个断点,如下所示。
受保护 void gvCustomers_RowCommand( Object sender,GridViewCommandEventArgs e)
{
// 如果在GridView控件中使用了多个按钮,使用
// CommandName属性来确定单击了哪个按钮。
if (e.CommandName == 点击)
{
// 您的代码......
}
}
现在,它正在点击RowCommand
由jQuery
动态创建的所有行的事件。
修改演示
GridView OnDemand Row OnScrolling [ ^ ]
更新
作为href
属性对于所有动态创建的行都是相同的jQuery
,所以OnSuccess
修改方法以使其唯一。
function OnSuccess(响应) {
var xmlDoc =
.parseXML(response.d);
var xml =
(xmlDoc);
pageCount = parseInt (xml.find( PageCount)。eq(0 )。find( 页页次跨度>)文本())。
var customers = xml.find( 顾客跨度>);
Hi,
Hello to all experts. I want to fire commandevent of gridview, which is loaded dynamically. Dynamically means on scroll of grid div, i am binding data in gridview. For this i am following this article http://www.aspsnippets.com/Articles/Load-on-demand-data-in-GridView-on-scroll-using-ASPNet-and-jQuery-AJAX.aspx[^]
But now suppose i want to add button in gridview, and on click of that button i want to fire commandevent of gridview. I am able to do it with use of jquery. but i want to fire command event of gridview.
Is it possible to do so? Again i can do it with jquery, but i want to do it with use of gridview rowcommand. Is it possible to do so?
Hope best answers will come out.
Thanks,
Harshil
Solution
I downloaded the code at - LOAD ON DEMAND DATA IN GRIDVIEW ON SCROLL USING ASP.NET AND JQUERY AJAX[^].
Then added oneLinkButton
to theGridView
, so modifiedGridView
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 theRowCommand
Event in Code Behind and put a Break Point inside the function as follows.
protected void gvCustomers_RowCommand(Object sender, GridViewCommandEventArgs e) { // If multiple buttons are used in a GridView control, use the // CommandName property to determine which button was clicked. if (e.CommandName == "click") { // Your codes... } }
Now, it's hitting theRowCommand
Event for all the rows created dynamically byjQuery
.
Modified Demo
GridView OnDemand Row OnScrolling[^]
Update
As thehref
attribute were same for all the dynamically created rows byjQuery
, so theOnSuccess
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");
这篇关于动态加载的gridview中的Fire事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!