我有这个带有EF数据源的RadGrid,它使用JOIN,例如
var result = db.Programmes.Join(db.Faculties, prog => prog.FacultyID, fac => fac.ID,
(prog, fac) => new {
ID = prog.ID,
FacultyID = prog.FacultyID,
FacultyText = fac.FacultyName_mk,
StudyLevelID = prog.StudyLevelID,
Ects = prog.Ects
}).ToList();
RadGrid1.DataSource = result;
到目前为止一切顺利。我正确显示了数据。
当我想插入新项目(程序)或更新现有项目时,问题就出现了。
protected void RadGrid1_UpdateCommand(object sender, GridCommandEventArgs e)
{
GridEditableItem item = e.Item as GridEditableItem;
// get the ID
Int32 id = (Int32)item.GetDataKeyValue("ID");
// get the current record
var record = db.Programmes.Where(r => r.ID == id).FirstOrDefault();
//update entity's information with what was entered in the RadGrid
item.UpdateValues(record);
db.SaveChanges();
// close the edit form
RadGrid1.MasterTableView.ClearEditItems();
}
这个东西会更新除了应该从RadComboBox控件获取的FacultyID之外的所有列;
<EditItemTemplate>
<telerik:RadComboBox runat="server" ID="cmbFacultyID" />
</EditItemTemplate>
我在ItemDataBound中对组合进行出价,并从Faculties实体中读取。
如何更新从此ComboBox读取FacultyID的程序表?
非常感谢
答案 0 :(得分:0)
在我从查询中得到新选择的教师时,我只需要更新记录,例如
// get the current record
var record = db.Programmes.Where(r => r.ID == id).FirstOrDefault();
// FIX
record.FacultyID = Convert.ToInt32(facultyid.SelectedValue);
// update entity's information with what was entered in the RadGrid
item.UpdateValues(record);
现在工作正常:) 谢谢