将 GridViewComboBoxColumn 绑定到数据源

发布于 2024-11-05 09:38:51 字数 877 浏览 2 评论 0原文

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

I already know how to specify the datasource but afther doing that it is not populated yet so i was thinking you need some kind of bind() command to populate the comboboxcolumn in the edit form
This below is how i bind the datasource to the comboboxcolumn (and yes i am sure that ds has data rows in it)

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

So could anyone tell me how i can now populate the comboboxcolumn in edit mode?

Edit

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

简单爱 2024-11-12 09:38:51

以下是应该有效的代码:

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

Here is the code which should work:

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

Also, please refer to the GridViewDataComboBoxColumn Class topic.

UPDATE Your code should be implemented in the CellEditorInitialize event as shown below:

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();
        }
    }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文