C# 使用组合框列在Gridview上更新DevExpress
这些是回调函数和行更新函数C# 使用组合框列在Gridview上更新DevExpress,c#,asp.net,.net,entity-framework,devexpress,C#,Asp.net,.net,Entity Framework,Devexpress,这些是回调函数和行更新函数 protected void Page_Load(object sender, EventArgs e) { if (!this.IsPostBack) { //Entity framework query Project.Include("User").ToList(); grid.DataSource = BUS.Operations.EntityOperations.ProjectOperations.Select
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
//Entity framework query Project.Include("User").ToList();
grid.DataSource = BUS.Operations.EntityOperations.ProjectOperations.SelectAllProjects();
grid.DataBind();
}
}
//Upon edit comboboxes are populated
protected void grid_CellEditorInitialize(object sender, ASPxGridViewEditorEventArgs e)
{
if (!grid.IsEditing || e.Column.FieldName != "User.DomainName") return;
if (e.KeyValue == DBNull.Value || e.KeyValue == null) return;
object val = grid.GetRowValuesByKeyValue(e.KeyValue, "ProjectID");
if (val == DBNull.Value) return;
int country = (int)val;
ASPxComboBox combo = e.Editor as ASPxComboBox;
FillCityCombo(combo);
combo.Callback += new CallbackEventHandlerBase(cmbCity_OnCallback);
}
protected void FillCityCombo(ASPxComboBox cmb)
{
cmb.DataSource= BUS.Operations.EntityOperations.UserOperations.SelectAllProjectManagers();
cmb.DataBindItems();
}
现在主要有两个问题
这是我在devexpress上的第一次试用,可能这段代码有很多错误和不必要的复杂性。我需要您的帮助以获得更好的工作代码您的第一个问题很容易解决:将
PageLoad
事件中的两行内容复制到grid\u row更新事件的末尾
。或者,始终在页面加载中执行这些行,而不仅仅是在的情况下!这是.IsPostBack
,因为网格正在进行回发,您需要刷新数据源。顺便问一下,gridView.CancelEdit()有什么原因吗;e、 取消=真代码>?关于第二个问题:不能转换为int
的sting看起来如何?我们正在讨论这一行p.ProjectManagerID=…
,对吗?
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
//Entity framework query Project.Include("User").ToList();
grid.DataSource = BUS.Operations.EntityOperations.ProjectOperations.SelectAllProjects();
grid.DataBind();
}
}
//Upon edit comboboxes are populated
protected void grid_CellEditorInitialize(object sender, ASPxGridViewEditorEventArgs e)
{
if (!grid.IsEditing || e.Column.FieldName != "User.DomainName") return;
if (e.KeyValue == DBNull.Value || e.KeyValue == null) return;
object val = grid.GetRowValuesByKeyValue(e.KeyValue, "ProjectID");
if (val == DBNull.Value) return;
int country = (int)val;
ASPxComboBox combo = e.Editor as ASPxComboBox;
FillCityCombo(combo);
combo.Callback += new CallbackEventHandlerBase(cmbCity_OnCallback);
}
protected void FillCityCombo(ASPxComboBox cmb)
{
cmb.DataSource= BUS.Operations.EntityOperations.UserOperations.SelectAllProjectManagers();
cmb.DataBindItems();
}
void cmbCity_OnCallback(object source, CallbackEventArgsBase e)
{
FillCityCombo(source as ASPxComboBox);
}
protected void grid_RowUpdating(object sender, DevExpress.Web.Data.ASPxDataUpdatingEventArgs e)
{
ASPxGridView gridView = (ASPxGridView)sender;
int ProjectID = (int)e.Keys[gridView.KeyFieldName];
P p = new P();
p.ProjectName = e.NewValues["ProjectName"].ToString();
p.ProjectInfo = e.NewValues["ProjectInfo"].ToString();
p.ProjectID = ProjectID;
//User.DomainName should be inputted as int convertable string
p.ProjectManagerID = Int32.Parse(((string)e.NewValues["User.DomainName"]));
BUS.Operations.EntityOperations.ProjectOperations.UpdateProject(p);
gridView.CancelEdit();
e.Cancel = true;
}