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

Accessing deleted item values before delete

5 Answers 57 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Philip
Top achievements
Rank 1
Philip asked on 29 Apr 2009, 12:24 PM
I am attempting to create a change log when a radgrid item has been deleted. I would like to take the current values and write them to a different table. How can I access the values before they are deleted? I am using the methods below.

<

 

asp:LinkButton ID="LinkButton1" OnClientClick="javascript:return confirm('Delete all selected customers?')"

 

runat

 

="server" CommandName="DeleteSelected"><img style="border:0px;vertical-align:middle;" alt="" src="Img/Delete.gif" />Delete selected customers</asp:LinkButton>

 



 

If e.CommandName = "DeleteSelected" Then

 

......
end if

5 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 1
answered on 29 Apr 2009, 01:13 PM
Hello Philip,

You can access the items in the Delete Command before you perform the delete operation:
c#:
  protected void RadGrid2_DeleteCommand(object source, GridCommandEventArgs e) 
    { 
        if (e.Item is GridDataItem) 
        { 
            GridDataItem dataItem = (GridDataItem)e.Item; 
            string strtxt1 = dataItem["ContactName"].Text; 
            string strtxt2 = dataItem["ContactTitle"].Text; 
        } 
       // code to delete 
    } 

Thanks
Princy.
0
Monica
Top achievements
Rank 1
answered on 01 Mar 2012, 07:15 PM
Princy,

If the column have a bool value; the property Text doesn´t work for get the value; ( text="&nbsp;")

What I can do to get the value?

Thanks in advance
0
Princy
Top achievements
Rank 1
answered on 02 Mar 2012, 07:55 AM
Hello,

You can access the bool value as shown below.
C#:
bool strtxt1 =Convert.ToBoolean(dataItem["UniqueName"]);

Thanks,
Princy.
0
Monica
Top achievements
Rank 1
answered on 02 Mar 2012, 03:28 PM
Hello Princy

If it is a GridCheckBoxColumn a get the value as follows:

bool checkbox;

if (e.Item is GridDataItem)
{
   GridDataItem deletedItem = e.Item
as GridDataItem;               
   checkbox =
bool.Parse((deletedItem["UniqueName"].Controls[0] as CheckBox).Checked.ToString());
}

That it is correct?
Have a nice day!

0
Antonio Stoilkov
Telerik team
answered on 07 Mar 2012, 12:24 PM
Hello Monica,

You are accessing the CheckBox control inside GridCheckBoxColumn properly. Note that you could access the CheckBox Checked properly directly without the need of parsing.
bool checkbox;
 
if (e.Item is GridDataItem)
{
    GridDataItem deletedItem = e.Item as GridDataItem;
    checkbox = (deletedItem["UniqueName"].Controls[0] as CheckBox).Checked;
}

Additionally, you could go through the help article below for more in depth information on the topic:

Regards,
Antonio Stoilkov
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Tags
Grid
Asked by
Philip
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 1
Monica
Top achievements
Rank 1
Antonio Stoilkov
Telerik team
Share this question
or