J
John
The ItemCommand event not getting fired when I add both a BoundColumn and a
ButtonColumn to a datagrid. When I add a ButtonColumn by itself, everything
works fine, but as soon as I add a BoundColumn, the ItemCommand event
doesn't seem to get called.
I've been struggling with this for too long now, I'm certain there's
something I'm not getting. Here's the relevant code. Thanks in advance!
// As is, this code does not correctly call the ItemCommand event handler.
// Comment out AddIDColumn however and the ItemCommand event handler
// is called when expected.
private void Page_Load(object sender, System.EventArgs e) {
AddIDColumn();
AddButtonColumn();
dg.DataSource = GetDataSource();
dg.DataKeyField = "employeeid";
if ( !IsPostBack )
dg.DataBind();
}
private void AddIDColumn() {
BoundColumn bound = new BoundColumn();
bound.DataField = "EmployeeID";
bound.HeaderText = "EmployeeID";
dg.Columns.Add( bound );
}
private void AddButtonColumn() {
ButtonColumn button = new ButtonColumn();
button.ButtonType = ButtonColumnType.LinkButton;
button.Text = "Click Me";
button.CommandName = "whatever";
dg.Columns.Add( button );
}
private void dg_ItemCommand(object source,
System.Web.UI.WebControls.DataGridCommandEventArgs e) {
dg.DataBind();
}
ButtonColumn to a datagrid. When I add a ButtonColumn by itself, everything
works fine, but as soon as I add a BoundColumn, the ItemCommand event
doesn't seem to get called.
I've been struggling with this for too long now, I'm certain there's
something I'm not getting. Here's the relevant code. Thanks in advance!
// As is, this code does not correctly call the ItemCommand event handler.
// Comment out AddIDColumn however and the ItemCommand event handler
// is called when expected.
private void Page_Load(object sender, System.EventArgs e) {
AddIDColumn();
AddButtonColumn();
dg.DataSource = GetDataSource();
dg.DataKeyField = "employeeid";
if ( !IsPostBack )
dg.DataBind();
}
private void AddIDColumn() {
BoundColumn bound = new BoundColumn();
bound.DataField = "EmployeeID";
bound.HeaderText = "EmployeeID";
dg.Columns.Add( bound );
}
private void AddButtonColumn() {
ButtonColumn button = new ButtonColumn();
button.ButtonType = ButtonColumnType.LinkButton;
button.Text = "Click Me";
button.CommandName = "whatever";
dg.Columns.Add( button );
}
private void dg_ItemCommand(object source,
System.Web.UI.WebControls.DataGridCommandEventArgs e) {
dg.DataBind();
}