本文介绍了与CollapsiblePanelExtender未知的控制误差在GridView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在在我试图插入来自Ajax控件工具包一个CollapsiblePanelExtender(在Visual Studio 2012)成一个复选框部分的GridView排查编码挑战的过程。什么我希望做的是让复选框崩溃的整个部分,并在用户要求扩展。

我面对(ASP的code低于 - 没有CS code)所面临的挑战是,在< ASP:面板ID =pnlClick的$ C的...部分$ C下面有面板和CheckBoxField字段的每一个实例下一个绿色的波浪线与下面的错误(从调试输出指出):

 元素面板是不是一个已知的元素。如果在网站编译错误,或者在web.config文件丢失可能出现这种情况。元素CheckBoxField字段不是已知元件。如果在网站编译错误,或者在web.config文件丢失可能出现这种情况。

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

 错误创建控制 -  GridView1System.Web.UI.WebControls.DataControlFieldCollection必须有类型System.Web.UI.WebControlField'的项目。 'ASP:面板的类型是System.Web.UI.WebControls.Panel'的。

这难题的SQL部分是坚如磐石,所以我不需要assitance与此有关。我是新来的Ajax控件工具包,所以我试图确定究竟我需要调整,使这项工作(如果这甚至是为了什么,我试图完成正确的解决方案)。我已经浇通过谷歌寻找答案,但没有帮助我解决这个问题有一个gridview。下面的code是试图将过去的半年到一年内拼凑其他非gridview的解决方案的产品。有些事我可能丢失,我敢打赌,这可能是一些简单的,需要加以固定。缺少什么我在这里(下图),如果这甚至有可能?

如果有谁还知道一个良好的非MSDN参考结合实例,这将是pciated太大AP $ P $的。

.aspx的code:

 <%@页标题=测试页LANGUAGE =C#的MasterPageFile =〜/ Site.master母AutoEventWireup =真codeFILE =窗口2。 aspx.cs继承=窗体2%GT;<%@注册大会=AjaxControlToolkit命名空间=AjaxControlToolkit标签preFIX =CC1%GT;
< ASP:内容ID =内容1ContentPlaceHolderID =HeadContent=服务器>
< / ASP:内容>
< ASP:内容ID =内容2ContentPlaceHolderID =FeaturedContent=服务器>
< / ASP:内容>
< ASP:内容ID =Content3ContentPlaceHolderID =日程地址搜索Maincontent=服务器>
    < CC1:ToolkitScriptManager ID =ToolkitScriptManager1=服务器>< / CC1:ToolkitScriptManager>
    < ASP:GridView控件ID =GridView1=服务器的AutoGenerateColumns =FALSE的cellpadding =4的DataSourceID =SqlDataSource1前景色=#333333网格=无>
        < AlternatingRowStyle背景色=白/>
        <柱体和GT;
            < ASP:CommandField中ShowEditButton =真/>
            < ASP:BoundField的数据字段=字段1的HeaderText =字段1SORTEX pression =字段1/>
            < ASP:BoundField的数据字段=字段2的HeaderText =字段2SORTEX pression =字段2/>
            < ASP:BoundField的数据字段=栏3的HeaderText =栏3SORTEX pression =栏3/>
            < ASP:BoundField的数据字段=4场的HeaderText =4场SORTEX pression =字段4/>
            < ASP:BoundField的数据字段=字段5的​​HeaderText =字段5SORTEX pression =字段5/>
            < ASP:BoundField的数据字段=字段6的HeaderText =字段6SORTEX pression =字段6/>
            < ASP:BoundField的数据字段=字段7的HeaderText =字段7SORTEX pression =字段7/>
            < ASP:BoundField的数据字段=字段8的HeaderText =字段8SORTEX pression =字段8/>
            < ASP:BoundField的数据字段=9场的HeaderText =字段9SORTEX pression =字段9/>
          < ASP:面板ID =pnlClick=服务器的CssClass =collapsiblepanelCSS>
              < D​​IV的风格=背景色:蓝色;高度:30PX;垂直对齐:中间的>
                  < D​​IV的风格=浮动:左;颜色:白色;填充:5像素为5px 0 0>
                      服务器列表可折叠面板
                  < / DIV>
                  < D​​IV的风格=浮动:权利;颜色:白色;填充:5像素为5px 0 0ID =divshow>
                      < ASP:标签ID =lblMessage=服务器文本=标签/>
                      < / DIV>
                  < D​​IV的风格=明确:既>
                < / DIV>
                    < / DIV>
                  < / ASP:面板>
            < ASP:面板ID =pnlCollapsable=服务器HEIGHT =0的CssClass =collapsiblepanelCSS>
            < ASP:CheckBoxField字段的DataField =复选框1的HeaderText =复选框1SORTEX pression =复选框1/>
            < ASP:CheckBoxField字段的DataField =复选框2的HeaderText =复选框2SORTEX pression =复选框2/>
            < ASP:CheckBoxField字段的DataField =复选框3的HeaderText =复选框3SORTEX pression =复选框3/>
            < ASP:CheckBoxField字段的DataField =复选框4的HeaderText =复选框4SORTEX pression =复选框4/>
            < ASP:CheckBoxField字段的DataField =复选框5的HeaderText =复选框5SORTEX pression =复选框5/>
            < ASP:CheckBoxField字段的DataField =复选框6的HeaderText =复选框6SORTEX pression =复选框6/>
            < ASP:CheckBoxField字段的DataField =复选框7的HeaderText =复选框7SORTEX pression =复选框7/>
            < ASP:CheckBoxField字段的DataField =复选框8的HeaderText =复选框8SORTEX pression =复选框8/>
            < ASP:CheckBoxField字段的DataField =复选框9的HeaderText =复选框9SORTEX pression =复选框9/>
            < ASP:CheckBoxField字段的DataField =复选框10的HeaderText =复选框10SORTEX pression =复选框10/>
            < ASP:CheckBoxField字段的DataField =复选框11的HeaderText =复选框11SORTEX pression =复选框11/>
            < ASP:CheckBoxField字段的DataField =复选框12的HeaderText =复选框12SORTEX pression =复选框12/>
              < / ASP:面板>
            < CC1:CollapsiblePanelExtender ID =CollapsiblePanelExtender1坍塌=真ExpandControlID =pnlClickTextLabelID =lblMessageCollapsedText =点击查看ExpandedText =点击隐藏ImageControlID =imgArrowsExpandDirection =垂直的TargetControlID =pnlCollapsableScrollContents =假=服务器>< / CC1:CollapsiblePanelExtender>            < ASP:BoundField的数据字段=10场的HeaderText =10场SORTEX pression =字段10/>
            < ASP:BoundField的数据字段=11场的HeaderText =11场SORTEX pression =场11/>
            < ASP:BoundField的数据字段=12场的HeaderText =12场SORTEX pression =场12/>
            < ASP:CommandField中ShowEditButton =真/>
        < /专栏>
        < EditRowStyle背景色=#2461BF/>
        < FooterStyle背景色=#507CD1FONT-粗体=真前景色=白/>
        < HeaderStyle背景色=#507CD1FONT-粗体=真前景色=白/>
        < PagerStyle背景色=#2461BF前景色=白Horizo​​ntalAlign =中心/>
        < RowStyle的BackColor =#EFF3FB/>
        < SelectedRowStyle背景色=#D1DDF1FONT-粗体=真前景色=#333333/>
        < SortedAscendingCellStyle背景色=#F5F7FB/>
        < SortedAscendingHeaderStyle背景色=#6D95E1/>
        < SortedDescendingCellStyle背景色=#E9EBEF/>
        < SortedDescendingHeaderStyle背景色=#4870BE/>
    < / ASP:GridView的>    < SQL连接字符串,插入/更新SQL code,更新参数,并关闭ASP / HTML标签>


解决方案

一切这是你的Columns集合的直接孩子需要有一个的DataControlField 键入Control(CheckBoxField字段,ButtonField字段等)。

这样。你需要把所有这一切面板里面的东西一<模板列> ,它允许您创建一个自定义字段

而你需要所有这些CheckBoxFields只是普通的复选框那些转换的CheckBox,绑定到你想要的数据字段,然后你要善于

 < ASP:的TemplateField>
    < ASP:面板ID =pnlClick=服务器的CssClass =collapsiblepanelCSS>
        < D​​IV的风格=背景色:蓝色;高度:30PX;垂直对齐:中间的>
            < D​​IV的风格=浮动:左;颜色:白色;填充:5像素为5px 0 0>
                服务器列表可折叠面板
            < / DIV>
            < D​​IV的风格=浮动:权利;颜色:白色;填充:5像素为5px 0 0ID =divshow>
                < ASP:标签ID =lblMessage=服务器文本=标签/>
             < / DIV>
             < D​​IV的风格=明确:既>
             < / DIV>
         < / DIV>
    < / ASP:面板>
    < ASP:面板ID =pnlCollapsable=服务器HEIGHT =0的CssClass =collapsiblepanelCSS>
        < ASP:复选框ID =CheckBox1=服务器选中='<%=的eval(复选框1)%GT;'文本=复选框1/>
        < ASP:复选框ID =CheckBox2=服务器选中='<%=的eval(复选框2)%GT;'文本=复选框2/>
        < ASP:复选框ID =CheckBox3=服务器选中='<%=的eval(复选框3)%GT;'文本=复选框3/>
        < ASP:复选框ID =CheckBox4=服务器选中='<%=的eval(复选框4)%GT;'文本=复选框4/>
        < ASP:复选框ID =CheckBox5=服务器选中='<%=的eval(复选框5)%GT;'文本=复选框5/>
        < ASP:复选框ID =CheckBox6=服务器选中='<%=的eval(复选框6)%GT;'文本=复选框6/>
        < ASP:复选框ID =CheckBox7=服务器选中='<%=的eval(复选框7)%GT;'文本=复选框7/>
        < ASP:复选框ID =CheckBox8=服务器选中='<%=的eval(复选框8)%GT;'文本=复选框8/>
        < ASP:复选框ID =CheckBox9=服务器选中='<%=的eval(复选框9)%GT;'文本=复选框9/>
        < ASP:复选框ID =CheckBox10=服务器选中='<%=的eval(复选框10)%GT;'文本=复选框10/>
        < ASP:复选框ID =CheckBox11=服务器选中='<%=的eval(复选框11)%GT;'文本=复选框11/>
        < ASP:复选框ID =CheckBox12=服务器选中='<%=的eval(复选框12)%GT;'文本=复选框12/>
    < / ASP:面板>
    < CC1:CollapsiblePanelExtender ID =CollapsiblePanelExtender1坍塌=真
        ExpandControlID =pnlClickTextLabelID =lblMessageCollapsedText =点击查看
        ExpandedText =点击隐藏ImageControlID =imgArrowsExpandDirection =垂直
        的TargetControlID =pnlCollapsableScrollContents =假=服务器>
    < / CC1:CollapsiblePanelExtender>
< / ASP:的TemplateField>

I'm in the process of troubleshooting a coding challenge in a gridview where I'm attempting to insert a CollapsiblePanelExtender from the Ajax Control Toolkit (in Visual Studio 2012) into a section of checkboxes. What I'm hoping to do is to make the entire section of checkboxes collapse and expand at the users request.

The challenge I'm facing (the asp code is below - no cs code) is that in the " < asp:Panel ID="pnlClick"..." portion of the code there is a green squiggly line below 'Panel' and under every instance of 'CheckBoxField' with the following errors (as noted from the debug output):

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.

Also, when I switch to the design view of this page I get the following error:

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

The SQL portion of this puzzle is rock solid so I don't need assitance with this. I'm new to the Ajax Control Toolkit so I'm trying to determine what exactly I need to tweak to make this work (if this is even the right solution for what I'm attempting to accomplish). I've been pouring through Google for answers but nothing has helped me to resolve this matter with a gridview. The code below is the product of trying to piece together other non gridview solutions within the past six months to a year. There's something I'm probably missing and I'm willing to bet this is probably something simple that needs to be fixed. What am I missing here (below) if this is even possible?

If anyone also knows of a good non-msdn reference with examples that would be greatly appreciated too.

Aspx code:

<%@ 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>
解决方案

Everything that's a direct child of your Columns collection needs to be a DataControlField type control (CheckBoxField, ButtonField, etc).

Thus. you need to put all of that Panel stuff inside a <Templatefield>, which allows you to create a custom field.

And you need to convert all of those CheckBoxFields to just regular checkboxes, bind those CheckBoxes to the data fields you wanted, and you should be good

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

这篇关于与CollapsiblePanelExtender未知的控制误差在GridView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-12 13:16