我在的asp:GridView
内部asp:UpdatePanel
,其中有一列asp:LinkButton
控件。
在行数据绑定事件上,LinkButton为其分配了单击事件处理程序。
我已经尝试了各种可能的方法来连连点击,但没有任何事件触发过。
难道我做错了什么?
aspx:
<asp:UpdatePanel ID="MainUpdatePanel" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:Label ID="lblTest" Text="test" runat="server" />
<asp:GridView ID="gvClientsArchive" runat="server" AllowSorting="true" DataSourceID="dsClients"
OnRowDataBound="gvClientsArchive_RowDataBound" SkinID="gvList"
AllowPaging="true" PageSize="25" Visible="false">
...
后面的代码:
protected void gvClientsArchive_RowDataBound(object sender, GridViewRowEventArgs e)
{
...
int company_id = int.Parse(drvRow["company_id"].ToString());
LinkButton lnkRestore = (LinkButton)e.Row.FindControl("lnkRestore");
lnkRestore.Click += new System.EventHandler(this.doRestore);
按钮处理程序代码:
private void doRestore(object sender, EventArgs e)
{
lblTest.Text = "restore clicked";
}
我也尝试过:
protected void gvClientsArchive_RowDataBound(object sender, GridViewRowEventArgs e)
{
...
LinkButton lnkRestore = (LinkButton)e.Row.FindControl("lnkRestore");
lnkRestore.Click += delegate
{
lblTest.Text = "restore clicked";
};
RowDataBound
如果要注册事件处理程序,则不合适。用途RowCreated
:
protected void gvClientsArchive_RowCreated(object sender, GridViewRowEventArgs e)
{
if(e.Row.RowType == DataControlRowType.DataRow)
{
LinkButton lnkRestore = (LinkButton)e.Row.FindControl("lnkRestore");
lnkRestore.Click += new System.EventHandler(this.doRestore);
}
}
RowDataBound
仅当您不需要在每个回发上对网格进行数据绑定时才会触发,因为所有控件都在页面生命周期的末尾处理,因此不需要每次回发。还为时已晚。
如果使用TemplateFields
,则更容易在aspx上声明式注册处理程序。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句