gpt4 book ai didi

c# - 将 GridViewComboBoxColumn 绑定(bind)到数据源

转载 作者:太空宇宙 更新时间:2023-11-03 19:29:40 26 4
gpt4 key购买 nike

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

关于c# - 将 GridViewComboBoxColumn 绑定(bind)到数据源,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5898136/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com