1

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

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

那么谁能告诉我现在如何在编辑模式下填充组合框列?

编辑

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";
    }
4

1 回答 1

6

这是应该工作的代码:

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 类主题。

更新您的代码应该在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();
        }
    }
于 2011-05-05T13:39:22.247 回答