code behind
protected void RadGrid1_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
{
RadGrid1.DataSource = DbContext.students.Select("it.name,it.subject");
}
protected void RadGrid1_InsertCommand(object sender, GridCommandEventArgs e)
{
GridEditableItem item = e.Item as GridEditableItem;
Hashtable values = new Hashtable();
item.ExtractValues(values);
student stdd = new student();
item.UpdateValues(stdd);
DbContext.AddTostudents(stdd);
DbContext.SaveChanges();
}
protected void RadGrid1_UpdateCommand(object sender, GridCommandEventArgs e)
{
GridEditableItem item = e.Item as GridEditableItem;
int roll = (int)item.GetDataKeyValue("rollno");
//int t = Int32.Parse(roll);
student stdd = DbContext.students.Where(p => p.rollno == roll).FirstOrDefault();
item.UpdateValues(stdd);
//DbContext.AddTostudents(stdd);
DbContext.SaveChanges();
}
protected void RadGrid1_DeleteCommand(object sender, GridCommandEventArgs e)
{
GridDataItem item = e.Item as GridDataItem;
int roll=(int)item.GetDataKeyValue("rollno");
student stdd = DbContext.students.Where(p => p.rollno == roll).FirstOrDefault();
DbContext.DeleteObject(stdd);
DbContext.SaveChanges();
}
and getting error like DataBinding: ‘System.Data.Objects.MaterializedDataRecord’ does not contain a property with the name ‘rollno’.i have my table name as student and columns as-rollno,name,subject.
you only select name and subject fields, try to add rollno field as well and try again