我正在创建从 GridVew 继承的服务器控件。我有一些在控件内部动态创建的图像按钮,对于每个按钮我都有假设做某事的事件。一切看起来都不错,但从未触发该事件。这是我的代码的一部分:
//Class with dynamically created elements (custom grid pager)
public class GridPager
{
public event CommandEventHandler PageNumberClick;
//Element creation inside for scope
for(....)
{
ImageButton img = new ImageButton();
img.ImageAlign = ImageAlign.AbsMiddle;
img.ID = "lnkLastPage" + i.ToString();
img.CommandName = "Page";
img.CommandArgument = ((totalPages - 1) * maxPageRows).ToString();
imgBtn.Command += new CommandEventHandler(PageNumberClick);
tableCell.Controls.Add(img);
}
}
public class MyGridControl : GridView
{
[Bindable(true)]
[Category("Appearance")]
[DefaultValue("")]
[Localizable(true)]
GridPager.PageNumberClick += new CommandEventHandler(lnkPage_Click);
void lnkPage_Click(object sender, CommandEventArgs e)
{
PageIndex = Int32.Parse(e.CommandArgument.ToString());
BindData();
}
}