Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/33.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 使用组合框列在Gridview上更新DevExpress_C#_Asp.net_.net_Entity Framework_Devexpress - Fatal编程技术网

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();
    }
现在主要有两个问题

  • 第一个也是次要的一个是在从组合框中选择另一个项目经理并单击“更新”后,我在web视图中看不到更改,尽管数据库已更改,并且在页面刷新后可以看到效果

  • 第二个也是最主要的是,如果我不点击combobox并更改其他字段,比如项目名称,然后单击update,我会在rowupdate方法上得到一个字符串,它不能转换为int。但是,如果我从combobox中选择并更新一个int用户ID,它会像我预期的那样出现


  • 这是我在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;
    }