|
code
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
ButtonColumn and EditCommandColumn don't work together as expected in DataGridI 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 The EditCommandColumn server control fires up the ItemCommand event just like
the Delete button does. What you need to do is to find out during the ItemCommand handling which command was clicked. You should set the OnItemCommand="DataGrid1_Command" and within that method: protected void DataGrid1_Command(object sender, DataGridCommandEventArgs e) { switch (e.CommandName) { case "Delete": //process the delete command break; } } Show quoteHide quote "Piotr" wrote: > 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 > > > > > > > > > > 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? Piotr Show quoteHide quote U¿ytkownik "Phillip Williams" <Phillip.Willi***@webswapp.com> napisa³ w wiadomo¶ci news:DFF6E7E3-3B43-4316-8C07-0FE06BF70A9B@microsoft.com... > The EditCommandColumn server control fires up the ItemCommand event just like > the Delete button does. What you need to do is to find out during the > ItemCommand handling which command was clicked. You should set the > OnItemCommand="DataGrid1_Command" and within that method: > > protected void DataGrid1_Command(object sender, DataGridCommandEventArgs e) > { > switch (e.CommandName) > { > case "Delete": > file://process the delete command > break; > } > } > > -- > HTH, > Phillip Williams > http://www.societopia.net > http://www.webswapp.com > > > "Piotr" wrote: > > > 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 > > > > > > > > > > > > > > > > > > > >
Disable Button after click it
Panel Syntax Dynamically load webcontrol I really need to get this working...... dropdownlists, their items and viewstate WebControl Click Event Not Firing Dynamically show different web controls HTML editor for Safari browser DynamicMenuItemStyle override style (cursor:text) Clearing textbox controls after postback |
|||||||||||||||||||||||