I modified the code from ComboInGridExample to use onneeddatassource for my project. after clicking insert, my project inserts fine. It fails to close the edit form and refresh the grid to show the new inserted row though. The following contains my C# code:
protected void RadGrid1_InsertCommand(object sender, GridCommandEventArgs e)
{
try
{
//Get the GridEditFormInsertItem of the RadGrid
GridDataInsertItem insertedItem = (GridDataInsertItem)e.Item;
RadComboBox RadComboboxUnloadType = insertedItem.FindControl("RadComboBoxUnloadType") as RadComboBox;
RadDatePicker EventStartDateTime = (RadDatePicker)insertedItem["EventStartDateTime"].Controls[0];
RadDatePicker EventEndDateTime = (RadDatePicker)insertedItem["EventEndDateTime"].Controls[0];
WellVentData WellVent = new WellVentData();
WellVent.UpdateInsertEvent(CAI,
RadComboboxUnloadType.SelectedValue.ToString(),
EventStartDateTime.SelectedDate.ToString(),
EventEndDateTime.SelectedDate.ToString(),
(insertedItem["CountofEvents"].Controls[0] as RadNumericTextBox).Text,
(insertedItem["SalesLinePressure"].Controls[0] as RadNumericTextBox).Text,
(insertedItem["ShutInPressure"].Controls[0] as RadNumericTextBox).Text,
(insertedItem["FOpHierarchy_ID"].Controls[0] as TextBox).Text);
}
catch (Exception ex)
{
RadGrid1.Controls.Add(new LiteralControl("Unable to insert Event. Reason: " + ex.Message));
e.Canceled = true;
}
}
********The following contains the aspx code******************
<
telerik:RadGrid ID="RadGrid1" GridLines="None" AutoGenerateColumns="False"
runat="server" AllowPaging="True" AllowSorting="True"
OnItemDataBound="OnItemDataBoundHandler"
AllowAutomaticUpdates="True" AllowAutomaticInserts="True"
ShowStatusBar="True" AllowFilteringByColumn="True"
CellSpacing="0" EnableAJAX="True" onneeddatasource="RadGrid1_NeedDataSource"
oninsertcommand="RadGrid1_InsertCommand"
onupdatecommand="RadGrid1_UpdateCommand"
ondeletecommand="Rad" AllowAutomaticDeletes="True" >
<MasterTableView ShowFooter="false" DataKeyNames="ResultsID" EditMode="InPlace" CommandItemDisplay="TopAndBottom">