上周我正在努力获得基于 Ajax 的 CollapsiblePanelExtender 解决方案(如上一篇 SO 帖子中所述) 我突然意识到嵌套 Gridview 的代码一点也不可靠。当我研究改进这部分代码时,将复选框添加到嵌套 Gridview 的复杂性(并让它们不仅在页面加载时而且在编辑模式下正常工作似乎更像是让嵌套 Gridview 工作的挑战。我尝试了不同的变体,试图让复选框在嵌套网格视图中工作(以及插入非复选框代码),结果要么是嵌套网格视图应该位于的空白区域,要么是“必须声明标量变量@ticket_number”。我也一直在搜索互联网,但似乎没有人尝试过我对复选框所做的事情。我也使用以下 MSDN 文章,了解如何利用 Northwind 示例 db 构建嵌套的 Gridview。
我的目标是让 SQL 代码坚如磐石,然后将 Ajax CollapiblePanelExtender 添加到嵌套 Gridview 以使复选框部分在 Gridview 中可折叠。
也许我对此进行了太多研究,而没有看到什么可能是一个简单的解决方法。我在这里到底做错了什么?我正在使用的代码如下。
下面的aspx代码(没有cs文件)
<%@ Page Title="Test Page" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true" CodeFile="form2.aspx.cs" Inherits="form2" %>
<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="FeaturedContent" Runat="Server">
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="MainContent" Runat="Server">
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" CellPadding="4" DataSourceID="SqlDataSource1" ForeColor="#333333" GridLines="None">
<AlternatingRowStyle BackColor="White" />
<Columns>
<asp:CommandField ShowEditButton="True" />
<asp:BoundField DataField="ticket_number" HeaderText="Ticket Number" SortExpression="ticket_number" />
<asp:BoundField DataField="Field 2" HeaderText="Field 2" SortExpression="Field_2" />
<asp:BoundField DataField="Field_3" HeaderText="Field 3" SortExpression="Field_3" />
<asp:BoundField DataField="Field_4" HeaderText="Field 4" SortExpression="Field_4" />
<asp:BoundField DataField="Field_5" HeaderText="Field 5" SortExpression="Field_5" />
<asp:BoundField DataField="Field_6" HeaderText="Field 6" SortExpression="Field_6" />
<asp:BoundField DataField="Field_7" HeaderText="Field 7" SortExpression="Field_7" />
<asp:BoundField DataField="Field_8" HeaderText="Field 8" SortExpression="Field_8" />
<asp:BoundField DataField="Field_9" HeaderText="Field 9" SortExpression="Field_9" />
<asp:TemplateField HeaderText="Servers">
<ItemTemplate>
<asp:GridView runat="server" ID="GridView2" AutoGenerateColumns="False" CellPadding="4" ForeColor="#333333" GridLines="None" DataSourceID="SqlDataSource2">
<AlternatingRowStyle BackColor="White" />
<Columns>
<asp:CheckBoxField DataField="Check_Box_1" HeaderText="Check Box 1" SortExpression="Check_Box_1" />
<asp:CheckBoxField DataField="Check_Box_2" HeaderText="Check Box 2" SortExpression="Check_Box_2" />
<asp:CheckBoxField DataField="Check_Box_3" HeaderText="Check Box 3" SortExpression="Check_Box_3" />
<asp:CheckBoxField DataField="Check_Box_4" HeaderText="Check Box 4" SortExpression="Check_Box_4" />
<asp:CheckBoxField DataField="Check_Box_5" HeaderText="Check Box 5" SortExpression="Check_Box_5" />
<asp:CheckBoxField DataField="Check_Box_6" HeaderText="Check Box 6" SortExpression="Check_Box_6" />
<asp:CheckBoxField DataField="Check_Box_7" HeaderText="Check Box 7" SortExpression="Check_Box_7" />
<asp:CheckBoxField DataField="Check_Box_8" HeaderText="Check Box 8" SortExpression="Check_Box_8" />
<asp:CheckBoxField DataField="Check_Box_9" HeaderText="Check Box 9" SortExpression="Check_Box_9" />
<asp:CheckBoxField DataField="Check_Box_10" HeaderText="Check Box 10" SortExpression="Check_Box_10" />
<asp:CheckBoxField DataField="Check_Box_11" HeaderText="Check Box 11" SortExpression="Check_Box_11" />
<asp:CheckBoxField DataField="Check_Box_12" HeaderText="Check Box 12" SortExpression="Check_Box_12" />
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource2" ConnectionString="<%$ ConnectionStrings:test_form_connect %>" runat="server" UpdateCommand="UPDATE [test].[nested_gridview_test_form] SET [Check_Box_1] = @Check_Box_1, [Check_Box_2] = @Check_Box_2, [Check_Box_3] = @Check_Box_3, [Check_Box_4] = @Check_Box_4, [Check_Box_5] = @Check_Box_5, [Check_Box_6] = @Check_Box_6, [Check_Box_7] = @Check_Box_7, [Check_Box_8] = @Check_Box_8, [Check_Box_9] = @Check_Box_9, [Check_Box_10] = @Check_Box_10, [Check_Box_11] = @Check_Box_11, [Check_Box12] = @Check_Box_12 WHERE ([ticket_number] = @ticket_number)" SelectCommand="SELECT [Check_Box_1],[Check_Box_2],[Check_Box_3],[Check_Box_4],[Check_Box_5],[Check_Box_6],[Check_Box_7],[Check_Box_8],[Check_Box_9],[Check_Box_10],[Check_Box_11],[Check_Box_12] FROM [test].[nested_gridview_test_form] WHERE ([ticket_number] = @ticket_number)">
<SelectParameter>
<asp:Parameter Name="request_id" />
</SelectParameters>
<UpdateParameters>
<asp:Parameter Name="Check_Box_1" />
<asp:Parameter Name="Check_Box_2" />
<asp:Parameter Name="Check_Box_3" />
<asp:Parameter Name="Check_Box_4" />
<asp:Parameter Name="Check_Box_5" />
<asp:Parameter Name="Check_Box_6" />
<asp:Parameter Name="Check_Box_7" />
<asp:Parameter Name="Check_Box_8" />
<asp:Parameter Name="Check_Box_9" />
<asp:Parameter Name="Check_Box_10" />
<asp:Parameter Name="Check_Box_11" />
<asp:Parameter Name="Check_Box_12" />
</UpdateParameters>
</asp:SqlDataSource>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="Field_10" HeaderText="Field 10" SortExpression="Field_10" />
<asp:BoundField DataField="Field_11" HeaderText="Field 11" SortExpression="Field_11" />
<asp:BoundField DataField="Field_12" HeaderText="Field 12" SortExpression="Field_12" />
<asp:CommandField ShowEditButton="True" />
</Columns>
<EditRowStyle BackColor="#2461BF" />
<FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
<RowStyle BackColor="#EFF3FB" />
<SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
<SortedAscendingCellStyle BackColor="#F5F7FB" />
<SortedAscendingHeaderStyle BackColor="#6D95E1" />
<SortedDescendingCellStyle BackColor="#E9EBEF" />
<SortedDescendingHeaderStyle BackColor="#4870BE" />
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="Server" ConnectionString="<%$ ConnectionStrings:test_form_connect %>" SelectCommand="SELECT ticket_number, Field_1, Field_2, Field_3, Field_4, Field_5, Field_6, Field_7, Field_8, Field_9, Field_10, Field_11, Field_12 FROM [test].[nested_gridview_test_form] ORDER BY ticket_number" UpdateCommand="UPDATE [test].[nested_gridview_test_form] SET [Field_1] = @Field_1, [Field_2] = @Field2, [Field_3] = @Field_3, [Field_4] = @Field_4, [Field_5] = @Field_5, [Field_6] = @Field_6, [Field_7] = @Field_7, [Field_8] = @Field_8, [Field_9] = @Field_9, [Field_10] = @Field_10, [Field_11] = @Field_12, [Field_12] = @Field_12 WHERE [ticket_number] = @ticket_number">
<UpdateParameters>
<asp:Parameter Name="Field_1" />
<asp:Parameter Name="Field_2" />
<asp:Parameter Name="Field_3" />
<asp:Parameter Name="Field_4" />
<asp:Parameter Name="Field_5" />
<asp:Parameter Name="Field_6" />
<asp:Parameter Name="Field_7" />
<asp:Parameter Name="Field_8" />
<asp:Parameter Name="Field_9" />
<asp:Parameter Name="Field_10" />
<asp:Parameter Name="Field_11" />
<asp:Parameter Name="Field_12" />
</UpdateParameters>
</asp:SqlDataSource>
</asp:Content>