简体   繁体   中英

AspxClientGridView AddNewRow, how to change values following a combobox (with selectedindexchanged event)?

I'm new in DevExpress.

I managed to display the "AddNewRow" but I would like when the user selects an item in the combo box, the other fields are filled in automatically.

I managed to recover the value of combobox item (its ID) and so I get all matching values (via a method that returns me the values following ID, so the description, price ... ).

The problem is that I cannot change the value of other fields in the "AddNewRow." How to assign the retrieved values in these fields?

Here is my aspx code :

<dx:ASPxGridView OnCustomCallback="ASPxGridViewArticles_CustomCallback" OnInit="ASPxGridViewArticles_Init" ID="ASPxGridViewArticles" ClientInstanceName="ClientGridArticles" runat="server" Width="1399px" AutoGenerateColumns="False" KeyFieldName="RefArticle" OnRowUpdating="ASPxGridViewArticles_RowUpdating">                          
                        <Columns>
                            <%--<dx:GridViewCommandColumn EditButton-Visible="true" NewButton-Visible="true"></dx:GridViewCommandColumn>--%>
                            <dx:GridViewCommandColumn ShowSelectCheckbox="True" VisibleIndex="0">
                                <EditButton Visible="true"/>
                                <HeaderCaptionTemplate>
                                    <dx:ASPxHyperLink ID="btnNew" runat="server" Text="New">
                                        <ClientSideEvents Click="function (s, e) { ClientGridArticles.AddNewRow();}" />
                                    </dx:ASPxHyperLink>
                                </HeaderCaptionTemplate>
                            </dx:GridViewCommandColumn>
                            <dx:GridViewDataComboBoxColumn Name="RefArticle" FieldName="RefArticle">
                                <PropertiesComboBox TextField="Description" ValueField="Id" DataSourceID="ListArticlesDS">
                                    <ClientSideEvents SelectedIndexChanged="function(s, e) {                                           
                                        var t = s.GetValue();
                                        ClientGridArticles.PerformCallback('ComboBoxArticles' + ';' + s.GetValue());
                                        }"></ClientSideEvents>
                                </PropertiesComboBox>
                                <EditFormSettings VisibleIndex="1" />
                            </dx:GridViewDataComboBoxColumn>
                            <dx:GridViewDataColumn Name="Description" FieldName="Description">
                                <EditFormSettings VisibleIndex="2" />
                            </dx:GridViewDataColumn>
                            <dx:GridViewDataColumn Name="Quantity" FieldName="Quantity">
                                <EditFormSettings VisibleIndex="3" />
                            </dx:GridViewDataColumn>
                            <dx:GridViewDataColumn Name="PU" FieldName="PU">
                                <EditFormSettings VisibleIndex="4" />
                            </dx:GridViewDataColumn>
                            <dx:GridViewDataColumn Name="PUCurrency" FieldName="PUCurrency">
                                <EditFormSettings VisibleIndex="5" />
                            </dx:GridViewDataColumn>
                            <dx:GridViewDataColumn Name="Discount" FieldName="Discount">
                                <EditFormSettings VisibleIndex="6" />
                            </dx:GridViewDataColumn>
                            <dx:GridViewDataColumn Name="Amount" FieldName="Amount">
                                <EditFormSettings VisibleIndex="7" />
                            </dx:GridViewDataColumn>
                            <dx:GridViewDataColumn Name="AmountCurrency" FieldName="AmountCurrency">
                                <EditFormSettings VisibleIndex="8" />
                            </dx:GridViewDataColumn>
                        </Columns>
                        <SettingsBehavior AllowSort="false" AllowDragDrop="false" />
                    </dx:ASPxGridView>
                    <asp:ObjectDataSource ID="ListArticlesDS" runat="server" SelectMethod="Helper_Get_RefArticles2" TypeName="AlphaNetworks_PRO_DevExpress.Helpers.Helper"></asp:ObjectDataSource>

Here is my C# code :

protected void ASPxGridViewArticles_CustomCallback(object sender, DevExpress.Web.ASPxGridView.ASPxGridViewCustomCallbackEventArgs e)
    {
        var args = e.Parameters.Split(';');
        if (args[0] == "ComboBoxArticles") 
        {
            if (args[1] == "New Article")
            {
            }
            else
            {
                int id = Convert.ToInt32(args[1]);
                Article article = Helper.Helper_Get_ArticleById(id);;
            }
        }
    }

Consider using the server-side ASPxGridView.InitNewRow event to provide default values for a new row.

There is also an approach described in ASPxGridView - How to implement cascaded comboboxes when adding a new row . Where you can handle the CellEditorInitialize event and check the IsNewRowEditing property to detect that a new row is edited.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM