当我动态创建数据网格并添加新的按钮列时,如何访问buttoncolumn_click 事件?
谢谢。
最佳答案
protected void Page_Load(object sender, EventArgs e)
{
DataGrid dg = new DataGrid();
dg.GridLines = GridLines.Both;
dg.Columns.Add(new ButtonColumn {
CommandName = "add",
HeaderText = "Event Details",
Text = "Details",
ButtonType = ButtonColumnType.PushButton
});
dg.DataSource = getDataTable();
dg.DataBind();
dg.ItemCommand += new DataGridCommandEventHandler(dg_ItemCommand);
pnlMain.Controls.Add(dg);
}
protected void dg_ItemCommand(object source, DataGridCommandEventArgs e)
{
if (e.CommandName == "add")
{
throw new Exception("add it!");
}
}
protected DataTable getDataTable()
{
// returns your data table
}
关于c# - 访问动态添加的按钮列(在数据网格中)的单击事件。 C#/ASP.NET,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/149823/