【问题标题】:Binding GridViewComboBoxColumn to a datasource将 GridViewComboBoxColumn 绑定到数据源
【发布时间】:2011-05-05 13:03:27
【问题描述】:

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

【问题讨论】:

    标签: c# asp.net devexpress aspxgridview


    【解决方案1】:

    下面是应该工作的代码:

    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();
            }
        }
    

    【讨论】:

    • 它似乎也不起作用,我将用一些额外的代码编辑我的问题,它现在是怎样的
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-03-12
    • 2010-09-26
    • 2013-02-15
    • 2020-07-19
    相关资源
    最近更新 更多