【发布时间】:2015-07-30 07:50:54
【问题描述】:
- 我在一个页面上有两个网格视图,它们都绑定到一个 sqldatasource。第一个 gridview (GVMonthReport) 显示表格中的数据
- 我的目标是从 GVMonthReport 中选择一行来过滤另一个表 (GridView2) sqldatasource 中的三个项目(Location、Trans_Budget_Code、Transaction Date)。
- 问题如下:我可以使用其中一个过滤项(Location 或 Trans_Budget_Code)和相应的 GridView2 过滤器,两者都有效。但是,当我将 Location 和 Trans_Budget_Code 一起尝试作为过滤器时,GridView2 上没有显示任何内容。我可以手动将值放入 Trans_Budget_Code 和 Location 的 GridView2s sqldatasource 中,结果是我所期望的。为什么这有效,但当我在 GVMonthReport 中选择一行时无效。
- 我认为这与 GVMonthReports DataKeyNames(“Trans_Budget_Code,Location”)有关。但到目前为止,我没有运气。 Trans_Budget_Code 和 Location 不是主键是这个问题吗?
<asp:SqlDataSource ID="MonthUsed0" runat="server" , SelectCommand="SELECT DISTINCT dbo.[ID Inventory$].[Item Description], dbo.[ID Transactions This Week$].Location, dbo.[ID Transactions This Week$].[Trns Date], dbo.[ID Transactions This Week$].Budget, dbo.[ID Inventory$].[Item Number] FROM dbo.[ID Transactions This Week$] INNER JOIN dbo.[ID Inventory$] ON dbo.[ID Transactions This Week$].[Item Number] = dbo.[ID Inventory$].[Item Number] WHERE (dbo.[ID Transactions This Week$].Location = @Location) AND (dbo.[ID Transactions This Week$].Budget = @Trans_Budget_Code)"
UpdateCommand="UPDATE zBudgetDetails SET Budget_ID = @Budget_ID, Budget_Account_ID = @Budget_Account_ID, Amount = @Amount, Memo = @Memo WHERE (Budget_Detail_ID = @Budget_Detail_ID)">
<SelectParameters>
<asp:ControlParameter ControlID="GVMonthReport" Name="Location" PropertyName="SelectedValue" />
<asp:ControlParameter ControlID="GVMonthReport" Name="Trans_Budget_Code" PropertyName="SelectedValue" />
</SelectParameters>
<UpdateParameters>
<asp:Parameter Name="Budget_ID" Type="Int32" />
<asp:Parameter Name="Budget_Account_ID" Type="Int32" />
<asp:Parameter Name="Amount" Type="Decimal" />
<asp:Parameter Name="Memo" Type="String" />
<asp:Parameter Name="Budget_Detail_ID" Type="Int32" />
</UpdateParameters>
</asp:SqlDataSource>
<br />
<asp:GridView ID="GridView2" runat="server" AutoGenerateColumns="False" DataSourceID="MonthUsed0" style="margin-top: 1px">
<Columns>
<asp:BoundField DataField="Item Description" HeaderText="Item Description" SortExpression="Item Description" />
<asp:BoundField DataField="Location" HeaderText="Location" SortExpression="Location" />
<asp:BoundField DataField="Trns Date" HeaderText="Trns Date" SortExpression="Trns Date" />
<asp:BoundField DataField="Budget" HeaderText="Budget" SortExpression="Budget" />
<asp:BoundField DataField="Item Number" HeaderText="Item Number" SortExpression="Item Number" />
</Columns>
</asp:GridView>
<br />
<br />
<br />
<asp:GridView ID="GVMonthReport" runat="server" AllowPaging="True" AllowSorting="True" DataKeyNames="Trans_Budget_Code,Location" AutoGenerateColumns="False" CellPadding="4" DataSourceID="MonthReport" ForeColor="#333333" GridLines="None" style="margin-right: 0px; margin-top: 0px;">
<AlternatingRowStyle BackColor="White" ForeColor="#284775" />
<Columns>
<asp:BoundField DataField="No#" HeaderText="No#" ReadOnly="True" SortExpression="No#" />
<asp:BoundField DataField="Transaction Type" HeaderText="Transaction Type" ReadOnly="True" SortExpression="Transaction Type" />
<asp:BoundField DataField="Trans_Budget_Code" HeaderText="Trans_Budget_Code" ReadOnly="True" SortExpression="Trans_Budget_Code" />
<asp:BoundField DataField="Location" HeaderText="Location" ReadOnly="True" SortExpression="Location" />
<asp:BoundField DataField="Supplier/Employee Name" HeaderText="Supplier/Employee Name" ReadOnly="True" SortExpression="Supplier/Employee Name" />
<asp:BoundField DataField="Project Code" HeaderText="Project Code" ReadOnly="True" SortExpression="Project Code" />
<asp:BoundField DataField="WOID" HeaderText="WOID" ReadOnly="True" SortExpression="WOID" />
<asp:BoundField DataField="Transaction Date" HeaderText="Transaction Date" ReadOnly="True" SortExpression="Transaction Date" />
<asp:BoundField DataField="Craft" HeaderText="Craft" ReadOnly="True" SortExpression="Craft" />
<asp:BoundField DataField="Transaction Description" HeaderText="Transaction Description" ReadOnly="True" SortExpression="Transaction Description" />
<asp:BoundField DataField="Purpose Description" HeaderText="Purpose Description" ReadOnly="True" SortExpression="Purpose Description" />
<asp:BoundField DataField="Quantity" HeaderText="Quantity" ReadOnly="True" SortExpression="Quantity" />
<asp:BoundField DataField="Unit Cost" HeaderText="Unit Cost" ReadOnly="True" SortExpression="Unit Cost" />
<asp:BoundField DataField="Total Cost" HeaderText="Total Cost" ReadOnly="True" SortExpression="Total Cost" />
<asp:BoundField DataField="Purchased by" HeaderText="Purchased by" ReadOnly="True" SortExpression="Purchased by" />
<asp:CommandField ShowSelectButton="True" />
</Columns>
<EditRowStyle BackColor="#999999" />
<FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
<RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
<SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
<SortedAscendingCellStyle BackColor="#E9E7E2" />
<SortedAscendingHeaderStyle BackColor="#506C8C" />
<SortedDescendingCellStyle BackColor="#FFFDF8" />
<SortedDescendingHeaderStyle BackColor="#6F8DAE" />
</asp:GridView>
<br />
<asp:SqlDataSource ID="MonthReport" runat="server" SelectCommand="SELECT No#, [Transaction Type], Trans_Budget_Code, Location, [Supplier/Employee Name], [Project Code], WOID, [Transaction Date], Craft, [Transaction Description], [Purpose Description], Quantity, [Unit Cost], [Total Cost], [Purchased by] FROM dbo.[MD Transactions] WHERE ([WO Budget Code] = @Acount) AND (YEAR([Transaction Date]) = @yeardate) AND (MONTH([Transaction Date]) = @monthdate) AND (Trans_Budget_Code = 'Maintenance') UNION ALL SELECT No#, [Transaction Type], Trans_Budget_Code, Location, [Supplier/Employee Name], [Project Code], WOID, [Transaction Date], Craft, [Transaction Description], [Purpose Description], Quantity, [Unit Cost], [Total Cost], [Purchased by] FROM dbo.[MD Transactions This Week$] WHERE ([WO Budget Code] = @Acount) AND (YEAR([Transaction Date]) = @yeardate) AND (MONTH([Transaction Date]) = @monthdate) AND (Trans_Budget_Code = 'Maintenance')"
UpdateCommand="UPDATE zBudgetDetails SET Budget_ID = @Budget_ID, Budget_Account_ID = @Budget_Account_ID, Amount = @Amount, Memo = @Memo WHERE (Budget_Detail_ID = @Budget_Detail_ID)">
<SelectParameters>
<asp:ControlParameter ControlID="DDLMonthAcount" Name="Acount" PropertyName="SelectedValue" />
<asp:ControlParameter ControlID="DDLYear" Name="yeardate" PropertyName="SelectedValue" />
<asp:ControlParameter ControlID="DDLMonth" Name="monthdate" PropertyName="SelectedValue" />
</SelectParameters>
<UpdateParameters>
<asp:Parameter Name="Budget_ID" Type="Int32" />
<asp:Parameter Name="Budget_Account_ID" Type="Int32" />
<asp:Parameter Name="Amount" Type="Decimal" />
<asp:Parameter Name="Memo" Type="String" />
<asp:Parameter Name="Budget_Detail_ID" Type="Int32" />
</UpdateParameters>
</asp:SqlDataSource>
【问题讨论】:
-
代码片段是我让它看起来不错的唯一原因。运行它不会做任何事情。很抱歉给您带来不便
标签: asp.net gridview sqldatasource