我是ASP的新手,但是GridView 99%完美,但是当我更新IncomeAccountDropDownList(TemplateField)中的一行时,它也会更改GridView中的所有后续行。当我在更新后执行Debug.Writeline“ estimateClassesDistinct”时,它是正确的,而不是GridView中显示的内容。我提供了一些图片以帮助解释问题。
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;
}
estimateClassesDistinct的Debug.WriteLine:
APP:GDRS 85
APP:RG选择收入帐户
DMO:BARR选择收入帐户
DMO:DTRUCK选择收入帐户
FNC:SHOE选择收入帐户