Kaushik Thanki
Kaushik Thanki

Reputation: 3520

Unable to get selected item of dx:ASPxListBox on ASPxGridView_Updating event of devexpress control

I have used dx:ASPxGridView where I have one dx:GridViewDataTextColumn with EditItemTemplate which contain dx:ASPxListBox. When I click on update command I am not able to get selected items of dx:ASPxListBox under ASPxGridView_Updating.

<dx:ASPxGridView
                ID="ASPxGridView"
                runat="server"
                AutoGenerateColumns="False"
                DataSourceID="TradersDS"
                KeyFieldName="TraderId">                   
                <SettingsEditing Mode="PopupEditForm" PopupEditFormWidth="600px" />                   
                <ClientSideEvents RowDblClick="function(s, e) 
            {
                s.StartEditRow(e.visibleIndex);
            }"
                    EndCallback="PrepareGridViewForNewDesing" Init="PrepareGridViewForNewDesing" />
                <Columns>
                  ....
                                    
                    <dx:GridViewDataTextColumn FieldName="CounterParty" VisibleIndex="3">
                        <EditItemTemplate>
                            <dx:ASPxListBox ID="lstCounterParty" runat="server" SelectionMode="CheckColumn" EnableSelectAll="true"                               
                                Width="285"
                                Height="300"
                                DataSourceID="CounterPartiesDS"
                                ValueField="ID" 
                                ValueType="System.String"
                                TextField="Name">
                            <%--    <ClientSideEvents SelectedIndexChanged="function(s, e) {lbModels.PerformCallback('1');}" />--%>
                            </dx:ASPxListBox>
                        </EditItemTemplate>
                    </dx:GridViewDataTextColumn>
                 ...                        
                </Columns>
            </dx:ASPxGridView>

C# Code..

protected override void ASPxGridView_Updating(object sender, ASPxDataUpdatingEventArgs e)
        {
            var gridView = sender as ASPxGridView;
        GridViewDataColumn list = gridView.Columns["CounterParty"] as GridViewDataColumn;
        var counterPartyListBox = (ASPxListBox)gridView.FindEditRowCellTemplateControl(list, "lstCounterParty");
    
        string selectedItemsAsString = string.Empty;
        foreach (ListEditItem item in counterPartyListBox.SelectedItems)
            selectedItemsAsString += item.Value + ";";

        base.ASPxGridView_Updating(sender, e);
        }

Here I always get count 0 of SelectedItems. On addition to this My devExpress control version are 9.3.3

What is wrong with this code any help , guidance really appreciated.

Upvotes: 0

Views: 616

Answers (1)

Mikhail
Mikhail

Reputation: 9300

Make sure that you set the ASPxListBox.ValueType property to the corresponding .NET type that matches the type of the "ValueField" column.

May be, according to the (ValueField="ID"), the (ASPxListBox.ValueType) should be numeric? (System.Int32, etc.)

Upvotes: 1

Related Questions