none
“/”应用程序中的服务器错误。 RRS feed

  • 问题

  • 分析器错误

    说明: 在分析向此请求提供服务所需资源时出错。请检查下列特定分析错误详细信息并适当地修改源文件。

    分析器错误消息: ID“HdnSelectedValues2”已被其他控件使用。

    源错误:

    行 65:        </table>
    行 66:      </div>
    行 67:       <input type="hidden" id="HdnSelectedValues2" runat="server" />
    行 68:       
    行 69:      

    源文件: /Default.aspx    行: 67


    版本信息: Microsoft .NET Framework 版本:4.0.30319; ASP.NET 版本:4.0.30319.34249

    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
    <!DOCTYPE html>
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head id="Head1" runat="server">
        <title>文书档案</title>
            <script type="text/javascript" src="js/chkcontrol.js"></script>
        <script type="text/javascript">
            function AddRemoveValues(oChk, theForm) {
                if (oChk.checked) {
                    theForm.HdnSelectedValues2.value += ",'" + oChk.value + "'";
                }
                else {
                    theForm.HdnSelectedValues2.value = theForm.HdnSelectedValues2.value.replace(",'" + oChk.value + "'", "");
                    //HdnSelectedValues2为页面上隐藏选择内容的信息 <asp:HiddenField ID="HdnSelectedValues2" runat="server" />
                }
            }
            ///全选
            function CheckAll(checkbox, theForm) {
                var elements = theForm.elements;
                for (var i = 0; i < elements.length; i++) {
                    if (elements[i].type == "checkbox" && elements[i].id != checkbox.id) {
                        elements[i].checked = checkbox.checked;
                        AddRemoveValues(elements[i], theForm);
                    }
                }
            }
        </script>
    </head>
    <body runat="server">
        <form id="ArViewFrm"  runat="server">
          <div align="center">
            <table width="780" cellpadding="0" cellspacing="0" align="center">
             <tr>
              <td>
                <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" BackColor="AliceBlue" BorderColor="#999999" BorderStyle="Solid" BorderWidth="1px" CellPadding="3" GridLines="Vertical" Width="100%" HorizontalAlign="Left" ForeColor="Black"  OnDataBound="GridView1_DataBound">
                      <FooterStyle BackColor="#CCCCCC" />
                      <SelectedRowStyle BackColor="#000099" Font-Bold="True" ForeColor="White" />
                      <PagerStyle BackColor="#999999" ForeColor="Black" HorizontalAlign="Center" />
                      <HeaderStyle BackColor="LightSteelBlue" Font-Bold="True" ForeColor="White" />
                      <AlternatingRowStyle BackColor="White" />
                    <Columns>
                        <asp:TemplateField>
                        <HeaderTemplate>
            <input  type="checkbox" id="All" name="All" onclick="CheckAll(this, document.ArViewFrm)"  runat="server"/>全选
                        </HeaderTemplate>
                            <ItemTemplate>
                            
              <input type="checkbox" id="chkSelect" onclick="javascript: AddRemoveValues(this, document.ArViewFrm);" name="chkSelect" runat="server"   value='<%# Eval("RecID")%> '/> 
              
                            </ItemTemplate>     
                        </asp:TemplateField>
                    </Columns>
                  </asp:GridView>
              </td>
             </tr>
            <tr>
               <td>
          
               </td>
             </tr>
           </table>
         </div>
          <input type="hidden" id="HdnSelectedValues2" runat="server" />
          
         
        </form>
        </body>
        </html>


    please verify my account

    2015年7月16日 5:39

答案

  • 你好,

    根据你的代码,我觉得你要获取所有选中的Checkbox,并将他们的值保存在隐藏域中。我建议你可是使用下面的代码:

        <script type="text/javascript">
            function Check_Click(oChk) {
                var GridView = oChk.parentNode.parentNode.parentNode;
                var inputList = GridView.getElementsByTagName("input");
    
                var hidden1 = document.getElementById("HdnSelectedValues1");     
                var row = oChk.parentNode.parentNode;
    
                if (oChk.type == "checkbox" && oChk != inputList[0]) {
                        if (oChk.checked) {
                            //If the header checkbox is checked
                            //check all checkboxes
                            //and highlight all rows
                            row.style.backgroundColor = "aqua";
                            hidden1.value += "," + oChk.value;
                        }
                        else {
                            //If the header checkbox is checked
                            //uncheck all checkboxes
                            //and change rowcolor back to original 
                            if (row.rowIndex % 2 == 0) {
                                //Alternating Row Color
                                row.style.backgroundColor = "#C2D69B";
                            }
                            else {
                                row.style.backgroundColor = "white";
                            }
                            oChk.checked = false;
    
                            hidden1.value = hidden1.value.replace("," + oChk.value, "");
                        }
                    }
                //}
    
            }
    
            ///全选
            function checkAll(checkbox) {
                var GridView = checkbox.parentNode.parentNode.parentNode;
                var inputList = GridView.getElementsByTagName("input");
    
                var hidden1 = document.getElementById("HdnSelectedValues1");
                hidden1.value = ""; //Clear hiddenfield
                for (var i = 0; i < inputList.length; i++) {
                    //Get the Cell To find out ColumnIndex
                    var row = inputList[i].parentNode.parentNode;
    
                    if (inputList[i].type == "checkbox" && checkbox != inputList[i]) {
    
                        if (checkbox.checked) {
                            //If the header checkbox is checked
                            //check all checkboxes
                            //and highlight all rows
                            row.style.backgroundColor = "aqua";
                            inputList[i].checked = true;
                            hidden1.value += "," + inputList[i].value;
                        }
                        else {
                            //If the header checkbox is checked
                            //uncheck all checkboxes
                            //and change rowcolor back to original 
                            if (row.rowIndex % 2 == 0) {
                                //Alternating Row Color
                                row.style.backgroundColor = "#C2D69B";
                            }
                            else {
                                row.style.backgroundColor = "white";
                            }
                            inputList[i].checked = false;
    
                            hidden1.value = "";
                        }
                    }
                }
    
            }
    
            function GetHiddenValue() {
                var hidden1 = document.getElementById("HdnSelectedValues1");
                alert(hidden1.value);
                event.preventDefault();
                return false;
            }
        </script>
    
    
    
        <form id="form1" runat="server">
            <div>
                <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="ID" DataSourceID="SqlDataSource1">
                    <Columns>
                        <asp:BoundField DataField="ID" HeaderText="ID" ReadOnly="True" SortExpression="ID" InsertVisible="False" />
                        <asp:BoundField DataField="Name" HeaderText="Name" SortExpression="Name" />
                        <asp:BoundField DataField="Number" HeaderText="Number" SortExpression="Number" />
                        <asp:TemplateField>
                            <HeaderTemplate>
                                <input id="checkAll" type="checkbox" runat="server" onclick="javascript: checkAll(this);"  />
                            </HeaderTemplate>
                            <ItemTemplate>
                                <input id="Checkbox1" type="checkbox" runat="server" onclick="javascript: Check_Click(this);" value='<%# Eval("ID")%>' />
                                
                            </ItemTemplate>
                        </asp:TemplateField>
                    </Columns>
                    <FooterStyle BackColor="#CCCCCC" />
                    <SelectedRowStyle BackColor="#000099" Font-Bold="True" ForeColor="White" />
                    <PagerStyle BackColor="#999999" ForeColor="Black" HorizontalAlign="Center" />
                    <HeaderStyle BackColor="LightSteelBlue" Font-Bold="True" ForeColor="White" />
                    <AlternatingRowStyle BackColor="White" />
                </asp:GridView>
                <asp:Button ID="Button1" runat="server" Text="Button" OnClientClick="GetHiddenValue();" />
                <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>" SelectCommand="SELECT [ID], [Name], [Number] FROM [Table4]"></asp:SqlDataSource>
            </div>
            <input type="hidden" id="HdnSelectedValues1" runat="server" value="" />
        </form>

    2015年7月27日 12:30
    版主

全部回复

  • 您好,

    aspx中只有一個 id 為 HdnSelectedValue2 ,是否可以檢查一下,aspx.cs 中是否有 控件 id 為 HdnSelectedValue2 的code嗎?


    亂馬客blog: http://www.dotblogs.com.tw/rainmaker/

    2015年7月16日 15:19
  • 你好,

    根据你的代码,我觉得你要获取所有选中的Checkbox,并将他们的值保存在隐藏域中。我建议你可是使用下面的代码:

        <script type="text/javascript">
            function Check_Click(oChk) {
                var GridView = oChk.parentNode.parentNode.parentNode;
                var inputList = GridView.getElementsByTagName("input");
    
                var hidden1 = document.getElementById("HdnSelectedValues1");     
                var row = oChk.parentNode.parentNode;
    
                if (oChk.type == "checkbox" && oChk != inputList[0]) {
                        if (oChk.checked) {
                            //If the header checkbox is checked
                            //check all checkboxes
                            //and highlight all rows
                            row.style.backgroundColor = "aqua";
                            hidden1.value += "," + oChk.value;
                        }
                        else {
                            //If the header checkbox is checked
                            //uncheck all checkboxes
                            //and change rowcolor back to original 
                            if (row.rowIndex % 2 == 0) {
                                //Alternating Row Color
                                row.style.backgroundColor = "#C2D69B";
                            }
                            else {
                                row.style.backgroundColor = "white";
                            }
                            oChk.checked = false;
    
                            hidden1.value = hidden1.value.replace("," + oChk.value, "");
                        }
                    }
                //}
    
            }
    
            ///全选
            function checkAll(checkbox) {
                var GridView = checkbox.parentNode.parentNode.parentNode;
                var inputList = GridView.getElementsByTagName("input");
    
                var hidden1 = document.getElementById("HdnSelectedValues1");
                hidden1.value = ""; //Clear hiddenfield
                for (var i = 0; i < inputList.length; i++) {
                    //Get the Cell To find out ColumnIndex
                    var row = inputList[i].parentNode.parentNode;
    
                    if (inputList[i].type == "checkbox" && checkbox != inputList[i]) {
    
                        if (checkbox.checked) {
                            //If the header checkbox is checked
                            //check all checkboxes
                            //and highlight all rows
                            row.style.backgroundColor = "aqua";
                            inputList[i].checked = true;
                            hidden1.value += "," + inputList[i].value;
                        }
                        else {
                            //If the header checkbox is checked
                            //uncheck all checkboxes
                            //and change rowcolor back to original 
                            if (row.rowIndex % 2 == 0) {
                                //Alternating Row Color
                                row.style.backgroundColor = "#C2D69B";
                            }
                            else {
                                row.style.backgroundColor = "white";
                            }
                            inputList[i].checked = false;
    
                            hidden1.value = "";
                        }
                    }
                }
    
            }
    
            function GetHiddenValue() {
                var hidden1 = document.getElementById("HdnSelectedValues1");
                alert(hidden1.value);
                event.preventDefault();
                return false;
            }
        </script>
    
    
    
        <form id="form1" runat="server">
            <div>
                <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="ID" DataSourceID="SqlDataSource1">
                    <Columns>
                        <asp:BoundField DataField="ID" HeaderText="ID" ReadOnly="True" SortExpression="ID" InsertVisible="False" />
                        <asp:BoundField DataField="Name" HeaderText="Name" SortExpression="Name" />
                        <asp:BoundField DataField="Number" HeaderText="Number" SortExpression="Number" />
                        <asp:TemplateField>
                            <HeaderTemplate>
                                <input id="checkAll" type="checkbox" runat="server" onclick="javascript: checkAll(this);"  />
                            </HeaderTemplate>
                            <ItemTemplate>
                                <input id="Checkbox1" type="checkbox" runat="server" onclick="javascript: Check_Click(this);" value='<%# Eval("ID")%>' />
                                
                            </ItemTemplate>
                        </asp:TemplateField>
                    </Columns>
                    <FooterStyle BackColor="#CCCCCC" />
                    <SelectedRowStyle BackColor="#000099" Font-Bold="True" ForeColor="White" />
                    <PagerStyle BackColor="#999999" ForeColor="Black" HorizontalAlign="Center" />
                    <HeaderStyle BackColor="LightSteelBlue" Font-Bold="True" ForeColor="White" />
                    <AlternatingRowStyle BackColor="White" />
                </asp:GridView>
                <asp:Button ID="Button1" runat="server" Text="Button" OnClientClick="GetHiddenValue();" />
                <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>" SelectCommand="SELECT [ID], [Name], [Number] FROM [Table4]"></asp:SqlDataSource>
            </div>
            <input type="hidden" id="HdnSelectedValues1" runat="server" value="" />
        </form>

    2015年7月27日 12:30
    版主