I am getting a strange error when I try to insert records on a sub radgrid and I still have one other to build in yet. What happens is that it grabs all the fields and inserts into the database just fine, but when it rebinds it tells me that the intPositionId from the sub table does not exist. The following is the error that it gieves me. This is the PK of of sub table and is inserted fine, like I said its just on rebinding of the table that it goes whacky, but if I leave page and come back normal everything I inserted is there and it works just fine. It has something to do with the postback and rebind. If I take out postback rebind it works just fine but then the data inserted is not there.
if (e.CommandName == RadGrid.PerformInsertCommandName && e.Item.OwnerTableView.Name == "Positions")
{
GridEditableItem item = e.Item as GridEditableItem;
GridDataItem parentItem = e.Item.OwnerTableView.ParentItem;
//int sectionId = Convert.ToInt32(item.OwnerTableView.DataKeyValues[e.Item.ItemIndex]["intSectionId"]);
int secId = Convert.ToInt32(parentItem.OwnerTableView.DataKeyValues[parentItem.ItemIndex]["intSectionId"]);
TextBox descrip = (TextBox)item.FindControl("txtdescription");
TextBox scale = (TextBox)item.FindControl("txtScale");
TextBox posType = (TextBox)item.FindControl("txtPosType");
TextBox grade = (TextBox)item.FindControl("txtGrade");
sql = "Execute usp_InsertPosition " + secId + ", '" + c.SanitizeString(descrip.Text) + "', '" + c.SanitizeString(scale.Text) + "', '" + c.SanitizeString(posType.Text) + "', '" + c.SanitizeString(grade.Text) + "'";
c.InsertUpdateDelete(sql);
myradGrid.Rebind(); """"""If I remove works fine but in sub grid gives below error.
}
intPositionId is neither a DataColumn nor a DataRelation for table .
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.ArgumentException: intPositionId is neither a DataColumn nor a DataRelation for table .
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Stack Trace:
[ArgumentException: intPositionId is neither a DataColumn nor a DataRelation for table .]
System.Data.DataRowView.get_Item(String property) +1353926
Telerik.Web.UI.GridTableView.PopulateDataKey(Object dataItem, DataKey key, String name) +86
Telerik.Web.UI.GridTableView.PopulateDataKeys(Object dataItem) +194
[GridException: There was a problem extracting DataKeyValues from the DataSource. Please ensure that DataKeyNames are specified correctly and all fields specified exist in the DataSource.]