ButtonColumn and EditCommandColumn don't work together as expected

P

Piotr

Hi,

I have a DataGrid with standard EditCommandColumn with PageIndex enabled.
Everything works fine.
When I add ButtonColumn

<asp:ButtonColumn
Text="Delete"
HeaderText=""
CommandName="Delete"/>

and modify DataGrid with

OnItemCommand="datagrid_Delete"

strange things happen. It seems to work until I click one of "Edit" buttons.
It changes properly to edit mode but then no matter what button I click next
("Cancel", "Update", some other "Edit" or one of page changing buttons) it
always runs OnItemCommand, and what's very strange, CommandName property has
always "Delete" value instead of "Cancel" , "Update" or whatever name of
button I clicked:

protected void datagrid_Delete(object o, DataGridCommandEventArgs e)
{
Response.Write("I clicked " + e.CommandName);
...
}

gives:

I clicked Delete

Strangly it works after another click...
Why the h... is that?

Thanks,
Piotr
 
E

Elton Wang

Hi Piotr,





Various button_click (including Sorting, Paging, Edit, Update, and so on) in
a datagrid goes datagrid_ItemCommand event first, then to be switched to
individual event accordingly. Hence, if you have the event, you should
filter (by e.CommandName) to allow only specified command to be handled
there.



HTH
 
P

Piotr

That's exactly what I did. The point is after I click Cancel or Update
e.CommandName should be "Cancel" or "Update" but it turns out to be "Delete"
Why is taht?

Piotr
 

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,766
Messages
2,569,569
Members
45,045
Latest member
DRCM

Latest Threads

Top