This is a migrated thread and some comments may be shown as answers.

[Solved] OnDeleteCommand method not being called

1 Answer 316 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Matt
Top achievements
Rank 1
Matt asked on 22 Apr 2009, 02:03 AM
I recently changed from using the radgrid contol for .NET2.0 to the 3.5 control.  But now I've noticed that my delete is not working.  When I click the delete button, the record is removed from the grid but the RadGrid1_DeleteCommand method is never called.  But it is called when the RebindGrid button is clicked.  I also have the same problem when delete from a grid where the delete command is defined in the datasource and there is no delete command method in the code behind.  I'm not sure if I'm doing something wrong or if something changed between the 2 versions.  I'm not having any problems with insert or update.

<

 

asp:LinkButton ID="LinkButton4" runat="server" CommandName="RebindGrid"><img style="border:0px;vertical-align:middle;" alt="" src="Images/Refresh.gif" />

 

Refresh Allocation list

</asp:LinkButton>

 

...

<

 

radG:GridClientDeleteColumn ConfirmText="Delete this Project?" ButtonType="ImageButton"

 

 

ImageUrl="Images\Delete.gif" CommandName="Delete" Text="Delete"

 

 

UniqueName="DeleteColumn">

 

 

<HeaderStyle Width="16px" />

 

 

<ItemStyle HorizontalAlign="Center" />

 

 

</radG:GridClientDeleteColumn>
...

 

 

protected void RadGrid1_DeleteCommand(object source, GridCommandEventArgs e)

 

{

 

if (e.CommandName == RadGrid.DeleteCommandName)

 

{

 

string ProjectId = e.Item.OwnerTableView.DataKeyValues[e.Item.ItemIndex]["ProjectId"].ToString();

 

 

string Resource = e.Item.OwnerTableView.Items[e.Item.ItemIndex]["Resource"].ToString();

 

 

string Role = e.Item.OwnerTableView.Items[e.Item.ItemIndex]["Role"].ToString();

 

 

string Year = e.Item.OwnerTableView.Items[e.Item.ItemIndex]["Year"].ToString();

 

AllocationsDataSource.DeleteCommandType =

SqlDataSourceCommandType.StoredProcedure;

 

AllocationsDataSource.DeleteCommand =

"RAT_OWNER.DeleteAllocations";

 

AllocationsDataSource.DeleteParameters.Clear();

AllocationsDataSource.DeleteParameters.Add(

"ProjectId", ProjectId);

 

AllocationsDataSource.DeleteParameters.Add(

"Resource", Resource);

 

AllocationsDataSource.DeleteParameters.Add(

"Role", Role);

 

AllocationsDataSource.DeleteParameters.Add(

"Year", Year);

 

RadGrid1.Rebind();

}

}




1 Answer, 1 is accepted

Sort by
0
Accepted
Shinu
Top achievements
Rank 2
answered on 22 Apr 2009, 05:01 AM
Hi Matt,

In the above given aspx code I can see that you are using a GridClientDeleteColumn. It is a special type of GridButtonColumn, including a delete buttons in each row. It provides the functionality of erasing records client-side, without making a round trip to the server. I would suggest you to use a GridButtonColumn with CommandName as Delete.

ASPX:
 
  <rad:GridButtonColumn HeaderText="DeleteColumn"  UniqueName="DeleteColumn" CommandName="Delete"  Text="Delete" > </rad:GridButtonColumn> 


Shinu
Tags
Grid
Asked by
Matt
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Share this question
or