1

我正在对 gridview 中的编码挑战进行故障排除,我试图将 Ajax Control Toolkit(在 Visual Studio 2012 中)中的 CollapsiblePanelExtender 插入复选框的一部分。我希望做的是使复选框的整个部分在用户请求时折叠和展开。

我面临的挑战(asp 代码在下面 - 没有 cs 代码)是在代码的“< asp:Panel ID="pnlClick"...”部分中,“Panel”下方有一条绿色波浪线,并且在具有以下错误的“CheckBoxField”的每个实例下(如调试输出中所述):

Element 'Panel' is not a known element. This can occur if there is a compilation error in the Web site, or the web.config file is missing.

Element 'CheckBoxField' is not a known element. This can occur if there is a compilation error in the Web site, or the web.config file is missing.

此外,当我切换到此页面的设计视图时,我收到以下错误:

Error Creating Control - GridView1

System.Web.UI.WebControls.DataControlFieldCollection must have items of type 'System.Web.UI.WebControlField'.  'asp:Panel' is of type 'System.Web.UI.WebControls.Panel'.

这个谜题的 SQL 部分坚如磐石,所以我不需要帮助。我是 Ajax Control Toolkit 的新手,所以我试图确定我需要进行哪些调整才能使其工作(如果这甚至是我想要完成的正确解决方案)。我一直在通过谷歌寻找答案,但没有什么能帮助我用 gridview 解决这个问题。下面的代码是在过去六个月到一年内尝试拼凑其他非 gridview 解决方案的产物。我可能遗漏了一些东西,我敢打赌这可能是需要修复的简单问题。如果这是可能的,我在这里(下)缺少什么?

如果有人还知道一个很好的非 msdn 参考以及示例,那也将不胜感激。

ASP代码:

<%@ Page Title="Test Page" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true" CodeFile="form2.aspx.cs" Inherits="form2" %>

<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>


<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">
    <cc1:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server"></cc1:ToolkitScriptManager> 
    <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="Field 1" HeaderText="Field 1" SortExpression="Field 1" />
            <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:Panel ID="pnlClick" runat="server" CssClass="collapsiblepanelCSS">
              <div style="background-color:blue;height:30px; vertical-align: middle">
                  <div style="float: left;color:white;padding: 5px 5px 0 0 ">
                      Server List Collapsable Panel
                  </div>
                  <div style="float: right; color: white; padding: 5px 5px 0 0" id="divshow">
                      <asp:Label ID="lblMessage" runat="server" Text="Label" />
                      </div>
                  <div style="clear:both">
                </div>
                    </div>
                  </asp:Panel>
            <asp:Panel ID="pnlCollapsable" runat="server" Height="0" CssClass="collapsiblepanelCSS">
            <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" />
              </asp:Panel>
            <CC1:CollapsiblePanelExtender ID="CollapsiblePanelExtender1" Collapsed="true" ExpandControlID="pnlClick" TextLabelID="lblMessage" CollapsedText="Click To Show" ExpandedText="Click To Hide" ImageControlID="imgArrows" ExpandDirection="Vertical" TargetControlID="pnlCollapsable" ScrollContents="false" runat="server"></CC1:CollapsiblePanelExtender>

            <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>

    <sql connection strings, insert/update SQL code, update parameters, and closing ASP/HTML tags>
4

1 回答 1

2

作为 Columns 集合的直接子项的所有内容都必须是DataControlField类型控件(CheckBoxField、ButtonField 等)。

因此。您需要将所有这些Panel内容放在 a<Templatefield>中,这样您就可以创建自定义字段。

而且您需要将所有这些 CheckBoxFields 转换为常规复选框,将这些 CheckBoxes 绑定到您想要的数据字段,您应该会很好

<asp:TemplateField>
    <asp:Panel ID="pnlClick" runat="server" CssClass="collapsiblepanelCSS">
        <div style="background-color:blue;height:30px; vertical-align: middle">
            <div style="float: left;color:white;padding: 5px 5px 0 0 ">
                Server List Collapsable Panel
            </div>
            <div style="float: right; color: white; padding: 5px 5px 0 0" id="divshow">
                <asp:Label ID="lblMessage" runat="server" Text="Label" />
             </div>
             <div style="clear:both">
             </div>
         </div>
    </asp:Panel>
    <asp:Panel ID="pnlCollapsable" runat="server" Height="0" CssClass="collapsiblepanelCSS">
        <asp:CheckBox ID="CheckBox1" runat="server" Checked='<%=Eval("Check Box 1") %>' Text="Check Box 1" />
        <asp:CheckBox ID="CheckBox2" runat="server" Checked='<%=Eval("Check Box 2") %>' Text="Check Box 2" />
        <asp:CheckBox ID="CheckBox3" runat="server" Checked='<%=Eval("Check Box 3") %>' Text="Check Box 3" />
        <asp:CheckBox ID="CheckBox4" runat="server" Checked='<%=Eval("Check Box 4") %>' Text="Check Box 4" />
        <asp:CheckBox ID="CheckBox5" runat="server" Checked='<%=Eval("Check Box 5") %>' Text="Check Box 5" />
        <asp:CheckBox ID="CheckBox6" runat="server" Checked='<%=Eval("Check Box 6") %>' Text="Check Box 6" />
        <asp:CheckBox ID="CheckBox7" runat="server" Checked='<%=Eval("Check Box 7") %>' Text="Check Box 7" />
        <asp:CheckBox ID="CheckBox8" runat="server" Checked='<%=Eval("Check Box 8") %>' Text="Check Box 8" />
        <asp:CheckBox ID="CheckBox9" runat="server" Checked='<%=Eval("Check Box 9") %>' Text="Check Box 9" />
        <asp:CheckBox ID="CheckBox10" runat="server" Checked='<%=Eval("Check Box 10") %>' Text="Check Box 10" />
        <asp:CheckBox ID="CheckBox11" runat="server" Checked='<%=Eval("Check Box 11") %>' Text="Check Box 11" />
        <asp:CheckBox ID="CheckBox12" runat="server" Checked='<%=Eval("Check Box 12") %>' Text="Check Box 12" />
    </asp:Panel>
    <CC1:CollapsiblePanelExtender ID="CollapsiblePanelExtender1" Collapsed="true" 
        ExpandControlID="pnlClick" TextLabelID="lblMessage" CollapsedText="Click To Show" 
        ExpandedText="Click To Hide" ImageControlID="imgArrows" ExpandDirection="Vertical" 
        TargetControlID="pnlCollapsable" ScrollContents="false" runat="server">
    </CC1:CollapsiblePanelExtender>
</asp:Templatefield>
于 2013-07-10T20:26:02.293 回答