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

Insert/Update/Delete at database level with queries

1 Answer 81 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Minh
Top achievements
Rank 1
Minh asked on 08 Aug 2011, 11:18 PM
Hi,

I'm following the example for Insert/Update/Delete at database level with queries
http://www.telerik.com/help/aspnet/grid/grdinsertupdatedeleteatdatabaselevel.html

during the insert section, I received the following error:
Unable to cast object of type 'Telerik.Web.UI.GridDataInsertItem' to type 'Telerik.Web.UI.GridEditFormInsertItem'.

the following contains my code behind.

protected

 

 

void RadGrid1_InsertCommand(object sender, GridCommandEventArgs e)

{

try

{

//Get the GridEditFormInsertItem of the RadGrid

GridEditFormInsertItem insertedItem = (GridEditFormInsertItem)e.Item;

RadComboBox RadCombobox = insertedItem.FindControl("RadComboBoxArea") as RadComboBox;

string strArea = RadCombobox.SelectedItem.Text; //Area

 RadCombobox = insertedItem.FindControl(

 

 

"RadComboBoxFMT") as RadComboBox

string strFMT = RadCombobox.SelectedItem.Text; //FMT or Asset

RadCombobox = insertedItem.FindControl( 

"RadComboBoxField") as RadComboBox

string strField = RadCombobox.SelectedItem.Text; //Field

 RadCombobox = insertedItem.FindControl(

 

 

"RadComboBoxWell") as RadComboBox;  

string strWell = RadCombobox.SelectedItem.Text; //Well 

RadCombobox = insertedItem.FindControl( 

"RadComboBoxUnloadType") as RadComboBox;  

string strUnloadType = RadCombobox.SelectedItem.Text; //Unload Type  

 

RadDatePicker EventStartDateTime = (RadDatePicker)insertedItem["EventStartDateTime"].Controls[0]; //Events start date time  

 

string strEventStartDateTime = EventStartDateTime.SelectedDate.ToString();  

RadDatePicker EventEndDateTime = (RadDatePicker)insertedItem["EventEndDateTime"].Controls[0]; //Events end date time

string strEventEndDateTime = EventEndDateTime.SelectedDate.ToString();

string CountofEvents = (insertedItem["CountofEvents"].Controls[0] as RadNumericTextBox).Text; //Count of Events

string SalesLinePressure = (insertedItem["SalesLinePressure"].Controls[0] as RadNumericTextBox).Text; //Sales Line Pressure

string ShutInPressure = (insertedItem["ShutInPressure"].Controls[0] as RadNumericTextBox).Text; //Shut In Pressure

string FOpHierarchyID = (insertedItem["FOpHierarchy_ID"].Controls[0] as TextBox).Text; //FOpHierarchy

 }

 

catch (Exception ex)

 {

RadGrid1.Controls.Add( 

new LiteralControl("Unable to insert Event. Reason: " + ex.Message));

 

e.Canceled =

 

true;

 

}

}

Please assist.
thanks,
Minh Bui

1 Answer, 1 is accepted

Sort by
0
Accepted
Shinu
Top achievements
Rank 2
answered on 09 Aug 2011, 04:42 AM
Hello Minh,

In the example you are trying EditMode property is not mentioned in MasterTableView.
If EditMOde is either EditForm or PopUp use GridEditFormInsertItem and if it is InPlace use GridEditableItem.

Thanks,
Shinu.
Tags
Grid
Asked by
Minh
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Share this question
or