DevExpress-Examples / asp-net-web-forms-grid-use-cascading-combo-boxes-in-inline-edit-mode

Create templated combo box columns, add cascading combo box editors to the templates, and configure the grid's cell edit functionality in inline mode.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Grid View for ASP.NET Web Forms - How to use cascading combo boxes in inline edit mode

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.

Cascading combo boxes in inline edit mode

Overview

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.

Files to Review

Documentation

More Examples

Does this example address your development requirements/objectives?

(you will be redirected to DevExpress.com to submit your response)

About

Create templated combo box columns, add cascading combo box editors to the templates, and configure the grid's cell edit functionality in inline mode.

License:Other


Languages

Language:ASP.NET 61.2%Language:C# 19.7%Language:Visual Basic .NET 19.1%