代码
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();
}
并收到类似DataBinding的错误:'System.Data.Objects.MaterializedDataRecord'不包含名为'rollno'.i的属性,我的表名为student,列为as-rollno,name,subject。
答案 0 :(得分:3)
您只选择名称和主题字段,尝试添加rollno字段,然后重试
DbContext.students.Select("it.name,it.subject,it.rollno");