我有一个带有GridViewComboBoxColumn列的网格。我有一个数据源是一个对象列表。我需要在Page_Load中分配数据。这不起作用:
protected void Page_Load() {
GridViewDataComboBoxColumn gridColumn = Grid.Columns["NumericData"]
as GridViewDataComboBoxColumn;
gridColumn.PropertiedropsComboBox.DataSource = DataSourceMadeUpOfAList;
gridColumn.PropertiesComboBox.TextField = "SpelledOutNumbers";
gridColumn.PropertiesComboBox.ValueField = "ActualNumbers";
...
我看过这里:Binding GridViewComboBoxColumn to a datasource
这确实有效,但仅限于编辑表单。我启用了过滤器行,并且还需要填充这些下拉列表。上述解决方案不适用于过滤器(出于显而易见的原因)。任何想法都表示赞赏。
感谢。
答案 0 :(得分:1)
此代码在这里工作正常。请确保,ValueField的类型和ComboBoxColumn绑定到的列的类型(column.FieldName)是相同的。最后,这是我的例子:
<dx:ASPxGridView ID="ASPxGridView1" Width="100%" ClientInstanceName="grid"
DataSourceID="SqlDataSource2" KeyFieldName="ProductID" AutoGenerateColumns="False" runat="server">
<Columns>
<dx:GridViewCommandColumn VisibleIndex="0">
<ClearFilterButton Visible="True">
</ClearFilterButton>
</dx:GridViewCommandColumn>
<dx:GridViewDataTextColumn FieldName="ProductID" ReadOnly="True" VisibleIndex="0">
<EditFormSettings Visible="False" />
</dx:GridViewDataTextColumn>
<dx:GridViewDataTextColumn FieldName="ProductName" VisibleIndex="1">
</dx:GridViewDataTextColumn>
<dx:GridViewDataTextColumn FieldName="SupplierID" VisibleIndex="2">
</dx:GridViewDataTextColumn>
<dx:GridViewDataComboBoxColumn FieldName="CategoryID" VisibleIndex="3">
<PropertiesComboBox ValueType="System.String">
</PropertiesComboBox>
</dx:GridViewDataComboBoxColumn>
</Columns>
</dx:ASPxGridView>
<asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
ProviderName="<%$ ConnectionStrings:ConnectionString.ProviderName %>" SelectCommand="SELECT * FROM [Products]">
</asp:SqlDataSource>
protected void Page_Load(object sender, EventArgs e) {
GridViewDataComboBoxColumn col = ASPxGridView1.Columns["CategoryID"] as GridViewDataComboBoxColumn;
col.PropertiesComboBox.DataSource = GetDataSource();
col.PropertiesComboBox.ValueField = "Id";
col.PropertiesComboBox.TextField = "Text";
}
...
public class Record {
public Record(int id) {
this.id = id;
this.text = "Row " + id.ToString();
}
private int id;
public int Id {
get { return id; }
set {
id = value;
}
}
private string text;
public string Text {
get { return text; }
}