且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

结合GridViewComboBoxColumn到数据源

更新时间:2023-09-21 18:39:34

下面是code这应该工作:

 数据集的数据集= DS作为数据集;
GridViewDataComboBoxColumn栏=(ASPxGridView4.Columns [纳摩]作为GridViewDataComboBoxColumn);
column.PropertiesComboBox.DataSource = dataSet.Tables [0];
column.PropertiesComboBox.ValueField =SomeValueField;
column.PropertiesComboBox.ValueType = typeof运算(INT); //将SomeValueField类型
column.PropertiesComboBox.TextField =SomeTextField;

此外,请参阅GridViewDataComboBoxColumn类话题。

更新您的code,应在CellEditorInitialize事件如下图所示:

 保护无效ASPxGridView1_CellEditorInitialize(对象发件人,ASPxGridViewEditorEventArgs E){
        如果(e.Editor是ASPxComboBox){
            ASPxComboBox组合=((ASPxComboBox)e.Editor);
            combo.DataSource = dataSet.Tables [0];
            combo.TextField =纳摩;
            combo.ValueField =纳摩;
            combo.DataBindItems();
        }
    }

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

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