我在我的gridviewrow中新创建的按钮没有触发它的EventHandler或RowCmmand事件,然后当按下新添加的行之后页面重新加载丢失可能是因为我无法调用我的BindData方法。我已删除从按钮的Click事件处理程序,只是使用的OnRowCommand事件,我还是我得到什么单击EventHandler not firing
protected void CustomGridView_DataBound(object sender, EventArgs e)
{
int count = ((GridView)sender).Rows.Count;
GridViewRow row = new GridViewRow(-1, -1, DataControlRowType.DataRow, DataControlRowState.Insert);
TableCell cell = new TableCell();
Button button = new Button();
button.Text = "Insert";
button.ID = "Insert";
button.CommandName = "Insert";
button.Click += new EventHandler(insertButton_Click);
cell.Controls.Add(button);
row.Cells.Add(cell);
for (int i = 0; i < ((GridView)sender).Columns.Count; i++)
{
cell = new TableCell();
cell.Controls.Add(new TextBox { ID = "Text" + i });
row.Cells.Add(cell);
}
Table table = ((GridView)sender).Rows[0].Parent as Table;
table.Rows.AddAt(count + 1, row);
}
protected void insertButton_Click(object sender, EventArgs e)
{
lblInsert.Text = "Hello World";
}
protected void CustomGridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "Insert")
{
lblInsert.Text = "Hello World";
}
}
总是有一个可靠的原因 - 为什么代码没有按预期运行。请具体说明并重新说明您的问题。 – adatapost 2012-01-04 03:39:34