简体   繁体   English

AspxClientGridView AddNewRow,如何更改组合框后的值(具有selectedindexchanged事件)?

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

I'm new in DevExpress. 我是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. 我设法显示“ AddNewRow”,但是我希望当用户在组合框中选择一个项目时,其他字段会自动填写。

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 ... ). 我设法恢复了组合框项目的值(它的ID),所以我得到了所有匹配的值(通过一种向我返回ID后的值的方法,即描述,价格...)。

The problem is that I cannot change the value of other fields in the "AddNewRow." 问题是我无法更改“ AddNewRow”中其他字段的值。 How to assign the retrieved values in these fields? 如何在这些字段中分配检索到的值?

Here is my aspx code : 这是我的aspx代码:

<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 : 这是我的C#代码:

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. 考虑使用服务器端ASPxGridView.InitNewRow事件为新行提供默认值。

There is also an approach described in ASPxGridView - How to implement cascaded comboboxes when adding a new row . ASPxGridView中还介绍了一种方法-添加新行时如何实现级联组合框 Where you can handle the CellEditorInitialize event and check the IsNewRowEditing property to detect that a new row is edited. 您可以在其中处理CellEditorInitialize事件并检查IsNewRowEditing属性以检测是否编辑了新行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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