我只是想知道,如何编写代码(Hyperlink1_Click()),用于超链接 网格视图中的按钮。 点击 - %GT;
<asp:LinkButton ID="l1" runat="server" PostBackUrl="~/Mine.aspx"
CssClass="s11">Click Me</asp:LinkButton>
$(document).ready(function () {
$("#GridBusOne a[id*='l1']").fancybox( {
'type' : 'iframe',
'hideOnOverlayClick':false,
'hideOnContentClick': false,
'closeClick' : false,
});
});
</script>
答案 0 :(得分:2)
请尝试使用LinkButton
,如下所示:
<asp:GridView runat="server" OnRowCommand="grdProducts_RowCommand" ID="grdProducts" >
<Columns>
<asp:TemplateField ShowHeader="False">
<ItemTemplate>
<asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="false"
CommandName="myLink" CommandArgument='<%# Eval("Id") %>' Text="Button"></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
背后的代码:
protected void Page_Load(object sender, EventArgs e)
{
var r = new Repository();
this.grdProducts.DataSource = r.GetProducts();
this.grdProducts.DataBind();
}
protected void grdProducts_RowCommand(object sender, GridViewCommandEventArgs e)
{
switch (e.CommandName)
{
case "myLink":
this.lblMessage.Text = e.CommandName + " " + e.CommandArgument + " " + DateTime.Now.ToString();
break;
default:
break;
}
}
其中包含以下内容:
答案 1 :(得分:0)
使用GridView
Control的ItemCommand
事件
了解更多信息Go here