将GridViewComboBoxColumn绑定到数据源

本文关键字:数据源 绑定 GridViewComboBoxColumn | 更新日期: 2023-09-27 17:55:07

我已经知道如何指定数据源,但在这样做之后,它还没有填充,所以我认为你需要某种bind()命令来填充编辑表单中的comboboxcolumn下面是我如何将数据源绑定到comboboxcolumn(是的,我确信ds中有数据行)

(ASPxGridView4.Columns["Naam"] as GridViewDataComboBoxColumn).PropertiesComboBox.DataSource = ds as DataSet;

所以谁能告诉我我现在如何在编辑模式下填充comboboxcolumn ?

编辑

protected void ASPxGridView4_InitNewRow(object sender, DevExpress.Web.Data.ASPxDataInitNewRowEventArgs e)
    {
        if (dt.Rows.Count < 1)
        {
            ds = Session["ds"] as DataSet;
        }
        GridViewDataComboBoxColumn column = (ASPxGridView4.Columns["Naam"] as GridViewDataComboBoxColumn);
        column.PropertiesComboBox.DataSource = ds.Tables[0];
        column.PropertiesComboBox.ValueField = "Naam";
        column.PropertiesComboBox.ValueType = typeof(string);
        column.PropertiesComboBox.TextField = "Naam";
    }

将GridViewComboBoxColumn绑定到数据源

下面是应该工作的代码:

DataSet dataSet = ds as DataSet;
GridViewDataComboBoxColumn column = (ASPxGridView4.Columns["Naam"] as GridViewDataComboBoxColumn);
column.PropertiesComboBox.DataSource = dataSet.Tables[0];
column.PropertiesComboBox.ValueField = "SomeValueField";
column.PropertiesComboBox.ValueType = typeof(int);  // type of the SomeValueField
column.PropertiesComboBox.TextField = "SomeTextField";

另外,请参考GridViewDataComboBoxColumn类主题。

UPDATE你的代码应该在CellEditorInitialize事件中实现,如下所示:

protected void ASPxGridView1_CellEditorInitialize(object sender, ASPxGridViewEditorEventArgs e) {
        if(e.Editor is ASPxComboBox) {
            ASPxComboBox combo = ((ASPxComboBox)e.Editor);
            combo.DataSource = dataSet.Tables[0];
            combo.TextField = "Naam";
            combo.ValueField = "Naam";
            combo.DataBindItems();
        }
    }