DataGrid

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?
 
C

cod3r

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,990
Messages
2,570,211
Members
46,796
Latest member
SteveBreed

Latest Threads

Top