1

As I was working on getting an Ajax based CollapsiblePanelExtender solution this past week (as noted in this previous SO post) it dawned on me that the code for a Nested Gridview was anything but solid. As I looked into improving this part of the code the complexity of adding checkboxes to the Nested Gridview (and getting them to work correctly not only when the page loads but when in edit mode seemed more of a challenge that getting the Nested Gridview to work. I've tried different varations of trying to get the checkboxes to work (along with inserting non checkbox code) in the Nested Gridview with the results either being a blank area where the nested gridview is supposed to be at or a "Must declare the scalar variable @ticket_number". I've also been scouring the interwebs but it seems that no one has tried what I'm doing with checkboxes. I also used the following MSDN article on how to build a Nested Gridview leveraging the Northwind sample db.

My goal is to get the SQL code rock solid and then add the Ajax CollapiblePanelExtender to the Nested Gridview to make the section of checkboxes collapsable in a Gridview.

Perhaps I'm looking too much into this and not seeing what is probably an easy fix for this. What exactly am I doing wrong here? The code I'm working with is below.

aspx code below (no cs file)

    <%@ 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>  
Community
  • 1
  • 1
Techie Joe
  • 847
  • 2
  • 14
  • 32

0 Answers0