1.触发一个后台的方法
前台
<asp:TemplateField> <ItemTemplate> <asp:LinkButton ID="lb_Edit" runat="server" Text="修改" OnClick="GetIndex" /> </ItemTemplate> </asp:TemplateField>
后台
protected void GetIndex(object sender, EventArgs e) { LinkButton lbtn = (LinkButton)sender; nIndex = ((GridViewRow)lbtn.NamingContainer).RowIndex; ClientScript.RegisterStartupScript(ClientScript.GetType(), "myscript", "<script type='text/javascript'>showEditFloat();</script> ");//执行前台的js函数 }
2.前台的LinkButton也可以触发GridView事件
<asp:TemplateField> <ItemTemplate> <asp:LinkButton ID="lb_delete" runat="server" Text="删除" CommandName="Delete" /> </ItemTemplate> </asp:TemplateField>
3、服务器控件触发JS函数
<asp:LinkButton ID="LinkButton1" ForeColor="Green" runat="server" OnClientClick="addItem();return false;">xxxx</asp:LinkButton>
本文转自武沛齐博客园博客,原文链接:http://www.cnblogs.com/wupeiqi/archive/2012/11/13/2768118.html,如需转载请自行联系原作者