我已经知道如何指定数据源,但在这样做之后它还没有填充,所以我认为你需要某种 bind() 命令来填充编辑表单中的组合框列下面是我如何将数据源绑定(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";
}
这是应该工作的代码:
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();
}
}
我是一名优秀的程序员,十分优秀!