This example demonstrates how to create templated combo box columns, add cascading combo box editors to the templates, and configure the grid's cell edit functionality in inline mode.
Add combo box columns to the grid, specify their EditItemTemplate properties, and add combo box editors to the templates.
<dx:GridViewDataComboBoxColumn FieldName="Category1ID" VisibleIndex="4">
<PropertiesComboBox DataSourceID="dsCategory1" TextField="Name" ValueField="ID" ValueType="System.Int32" />
<EditItemTemplate>
<dx:ASPxComboBox ID="Cat1" runat="server" DataSourceID="dsCategory1" TextField="Name" ValueField="ID"
Value='<%# Bind("Category1ID") %>' AutoPostBack="true" ValueType="System.Int32"
OnSelectedIndexChanged="Cat1_SelectedIndexChanged">
</dx:ASPxComboBox>
</EditItemTemplate>
</dx:GridViewDataComboBoxColumn>
For every template editor, handle its server-side SelectedIndexChanged event. In handlers, call the grid's FindEditRowCellTemplateControl method to access the subsequent editor and filter its data source based on the selected value of the primary editor.
protected void Cat1_SelectedIndexChanged(object sender, EventArgs e) {
ASPxComboBox combo1 = (ASPxComboBox)sender;
object oldCat1 = Session["Cat1ID"];
if(oldCat1 != null && oldCat1.Equals(combo1.Value)) return;
Session["Cat1ID"] = combo1.Value;
ASPxComboBox combo2 = ((ASPxComboBox)grid.FindEditRowCellTemplateControl(
grid.Columns["Category2ID"] as GridViewDataComboBoxColumn, "Cat2"));
combo2.Value = null;
Cat2_SelectedIndexChanged(combo2, EventArgs.Empty);
}
Wrap the grid with an update panel to avoid updating the entire page.
- Default.aspx (VB: Default.aspx)
- Default.aspx.cs (VB: Default.aspx.vb)
- Data Editors for ASP.NET Web Forms - Custom callback based implementation of cascading comboboxes in inline mode
- Data Editors for ASP.NET Web Forms - How to edit hierarchical data using cascading comboboxes
(you will be redirected to DevExpress.com to submit your response)