将GridViewComboBoxColumn绑定到数据源

时间:2011-05-05 13:03:28

标签: c# asp.net devexpress aspxgridview

我已经知道如何指定数据源但是还没有这样做它还没有填充,所以我认为你需要某种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";
    }

1 个答案:

答案 0 :(得分: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 Class主题。

更新您的代码应在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();
        }
    }