DataGrid

  • Thread starter Thread starter J. Babe
  • Start date Start date
J

J. Babe

I'm adding an Edit/Update/Cancel button at runtime to a datagrid in
ASP.NET. I can't get the EditCommand, ItemCommand, UpdateCommand, or
CancelCommand event handlers to fire when the button is pressed, how can
I fix this?
 
do you add your buttons in OnItemDataBound event ?

if so you can add an handler for your events when you
create them:

i did like this:

i create a new imagebutton control that inherits from
System.Web.UI.WebControls.ImageButton, and that add
a property named rowID, so when i create my control
(delete,update or insert too) i can set this property
to the key of the row i'm loading.

then in OnItemDataBound event i do these:

myImageButton imgButton = new myImageButton();
// i get the value of my ID from its column
imgButton.rowID = e.Item.Cells[0].Text;
imgButton.Click += new
System.Web.UI.ImageClickEventHandler
(this.imgButton_OnClick);
// i add the image button in my buttons column
e.Item.Cells[4].Controls.Add(imgButton);

imgButton_OnClick is so defined :

public void imgButton_OnClick(object sender,
System.Web.UI.ImageClickEventArgs e)
{
}

hope this help

for more info write me

cod3r
 
Back
Top