GridView自定义模版中用的 LinkButton
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>