Jacqui1811
Programmer
Hi,
I dynamically add a link button to my datagrid with a command name etc but the Item Command event handler won't fire.
I add the datagrid event handlers in the onload event like so :
grdFunds.EditCommand += new DataGridCommandEventHandler(grdFunds_Edit);
grdFunds.ItemCommand += new DataGridCommandEventHandler(grdFunds_Command);
grdFunds.DeleteCommand += new DataGridCommandEventHandler(grdFunds_Delete);
grdFunds.ItemDataBound += new DataGridItemEventHandler(grdFunds_ItemDataBound);
grdFunds.PreRender += new EventHandler(grdFunds_PreRender);
Then on the ItemDataBound event of the grid I do this and create a link button and add it to the empty column.
Like so :
protected void _view_grdFunds_ItemDataBound(Object sender, DataGridItemEventArgs e)
{
// get a reference to the empty last cell in the table.
TableCell myCell = e.Item.Cells[e.Item.Cells.Count - 1];
LinkButton lb = new LinkButton();
lb.Text = "Request Access to Extended Data";
lb.CausesValidation = false;
lb.EnableViewState = false;
lb.CommandName = "grdFunds_RequestExtendedAccess";
myCell.Controls.Add(lb);
}
I could definitely do with some help on this one folks, or even if you can think of a better way to add the button column to the end of the grid after the autogenerated rows, they have to be autogenerated as the number and content of rows can change, the button though has to be the last column.
Jacqui.
I dynamically add a link button to my datagrid with a command name etc but the Item Command event handler won't fire.
I add the datagrid event handlers in the onload event like so :
grdFunds.EditCommand += new DataGridCommandEventHandler(grdFunds_Edit);
grdFunds.ItemCommand += new DataGridCommandEventHandler(grdFunds_Command);
grdFunds.DeleteCommand += new DataGridCommandEventHandler(grdFunds_Delete);
grdFunds.ItemDataBound += new DataGridItemEventHandler(grdFunds_ItemDataBound);
grdFunds.PreRender += new EventHandler(grdFunds_PreRender);
Then on the ItemDataBound event of the grid I do this and create a link button and add it to the empty column.
Like so :
protected void _view_grdFunds_ItemDataBound(Object sender, DataGridItemEventArgs e)
{
// get a reference to the empty last cell in the table.
TableCell myCell = e.Item.Cells[e.Item.Cells.Count - 1];
LinkButton lb = new LinkButton();
lb.Text = "Request Access to Extended Data";
lb.CausesValidation = false;
lb.EnableViewState = false;
lb.CommandName = "grdFunds_RequestExtendedAccess";
myCell.Controls.Add(lb);
}
I could definitely do with some help on this one folks, or even if you can think of a better way to add the button column to the end of the grid after the autogenerated rows, they have to be autogenerated as the number and content of rows can change, the button though has to be the last column.
Jacqui.