views:

36

answers:

3

I have a telerik radgrid that is doing an insert using an objectdatasource. The insert method the objectdatasource calls has a boolean return value that I want to check in the radgrid's ItemInserted event.

Is this possible and what is the code to do it. I checked the GridInsertedEventArgs e and there is no way I can see to get the return value but it must be there, I think I am just missing it.

Any help would be appreciated.

A: 

This may help, converted from VB.net:

    protected void RadGrid1_InsertCommand(object source, Telerik.Web.UI.GridCommandEventArgs e) {

//Get the GridEditFormInsertItem of the RadGrid

GridEditFormInsertItem insertedItem = (GridEditFormInsertItem)e.Item;

//Access the textbox from the edit form template and store the values in string variables.
string CurrentCode = (insertedItem.FindControl("txtEditCurrentCode") as TextBox).Text;

}

Markive
If there is anything that I dont want displayed but need access to I store it in a hidden field use FindControl to get the value
Markive
+3  A: 

The ItemInserted event is better used with exceptions, hence it includes an Exception and ExceptionHandled property.

If your object data source insertion method fails (which, I trust, is what the boolean return value is intended to indicate), you should throw an Exception of a specific type which you can then inspect within the ItemInserted event.

Then depending on the type of exception, you can choose to modify the ExceptionHandled property and the KeepInInsertMode of the Telerik.Web.UI.GridInsertedEventArgs parameter.

Rabid
+1  A: 

In addition to Rabid's good suggestion, you can handle the ObjectDataSource control's Inserted event. This does allow direct access to the ReturnValue.

protected void myOds_Inserted(object sender, ObjectDataSourceStatusEventArgs e)
{
   int rtrnVal = Convert.ToInt32(e.ReturnValue);
}

Based on the return value inspected in this event, you can throw an exception that will be handled by RadGrid in the ItemInserted event.

Todd