Проблема с привязкой ASP GridView и TemplateField? - PullRequest
0 голосов
/ 18 апреля 2019

Я новичок в ASP, но у меня GridView на 99% идеальный, за исключением того, что когда я обновляю строку в IncomeAccountDropDownList (TemplateField), она также изменяет все последующие строки в GridView. Когда я выполняю отладку.Writeline, "оценочные значения классов" после обновления, это корректно, а не то, что отображается в GridView. Я включил несколько изображений, чтобы помочь объяснить проблему.

enter image description here enter image description here

enter image description here

ASP код:

<asp:ObjectDataSource ID="GridViewDataSource" runat="server" 
            OnSelecting="ObjectDataSource1_Selecting" 
            SelectMethod="GetDistinctEstimateClasses" 
            TypeName="OAuth2_Dotnet_UsingSDK.Pages.EstimateItemsToQuickBooks" 
            DataObjectTypeName="OAuth2_Dotnet_UsingSDK.EstimateClass" 
            UpdateMethod="UpdateDistinctEstimateClasses">

            <SelectParameters>
                <asp:ControlParameter ControlID="JobListDropDownList1" DefaultValue="NULL" Name="jobID" PropertyName="SelectedValue" Type="String" />
            </SelectParameters>

        </asp:ObjectDataSource>

<asp:ObjectDataSource ID="IncomeAccountDataSource1" runat="server" SelectMethod="GetIncomeAccounts" TypeName="OAuth2_Dotnet_UsingSDK.DatabaseHelpers">
        </asp:ObjectDataSource>


    <div style="margin-bottom: 10px">
        <label>New Categories Found. Supply default information to QuickBooks</label>

        <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataSourceID="GridViewDataSource"
            CellPadding="3" CellSpacing="5" AllowPaging="True" OnSelectedIndexChanged="GridView1_SelectedIndexChanged">
            <Columns>
                <asp:CommandField ShowEditButton="True" />

                <asp:BoundField DataField="FullyQualifiedName" HeaderText="Category:SubCategory" SortExpression="FullyQualifiedName"
                    ReadOnly="true">
                    <HeaderStyle Width="200px"></HeaderStyle>
                    <ItemStyle Width="200px"></ItemStyle>
                </asp:BoundField>

                <asp:BoundField DataField="Description" ReadOnly="true" HeaderText="Description" SortExpression="Description" />

                <asp:TemplateField HeaderText="Income Account">
                    <EditItemTemplate>
                        <asp:DropDownList ID="IncomeAccountDropDownList" runat="server" CssClass="DropDownList" AutoPostBack="True" 
                            DataSourceID="IncomeAccountDataSource1" DataTextField="Text" DataValueField="Value"
                            OnSelectedIndexChanged="IncomeAccountDropDownList_SelectedIndexChanged" 
                            SelectedText ='<%# Eval("IncomeAccount") %>' />
                    </EditItemTemplate>
                    <ItemTemplate>
                        <asp:FormView ID="formview1" runat="server" DataSourceID="GridViewDataSource">
                            <ItemTemplate>
                                <asp:Label ID="label1" runat="server" Text='<%# Eval("IncomeAccount") %>' />
                            </ItemTemplate>
                        </asp:FormView>
                    </ItemTemplate>
                </asp:TemplateField>

            </Columns>
        </asp:GridView>

C #:

public static void UpdateDistinctEstimateClasses(EstimateClass estimateClass)
    {
        foreach (var item in estimateClassesDistinct)
        {
            if (item.FullyQualifiedName == estimateClass.FullyQualifiedName)
            {
                item.IncomeAccount = IncomeAccountId;
                break;
            }
        }
    }

public static List<EstimateClass> GetDistinctListOfJobEstimates(List<EstimateClass> estimateClasses)
    {
        List<EstimateClass> distinctEstimateClass = new List<EstimateClass>();

        var distinctEstimateSubCategories = estimateClasses
                        .Select(m => new { m.FullyQualifiedName, m.Description })
                        .Distinct()
                        .OrderBy(o => o.FullyQualifiedName);

        foreach (var item in distinctEstimateSubCategories)
        {
            distinctEstimateClass.Add(new EstimateClass
            {
                FullyQualifiedName = item.FullyQualifiedName,
                Description = item.Description,
                IncomeAccount = "Select Income Account22",
                ExpenseAccount = null,
            });
        }

        return distinctEstimateClass;
    }

Debug.WriteLine ofcompatimentsDistinct:

APP: ГДРС 85

APP: RG Выберите учетную запись дохода

DMO: BARR Выберите учетную запись дохода

DMO: DTRUCK Выберите учетную запись дохода

FNC: ОБУВЬ Выберите учетную запись дохода

...