尝试在gridview中进行分页时了解错误来源

时间:2014-04-13 20:22:12

标签: c# asp.net gridview

好!所以,自从过去一周后,我试图找到为什么我收到此错误但没有任何成功。

我在网站中间有这个网格视图设置,我只是想从数据库中绘制大量的行(比如结果表中的20多行)。当我设置 AllowPaging =“true”并设置 PageSize =“10”时,我得到了 HTTP错误404.15 - 未找到请求过滤模块配置为拒绝查询字符串太长的请求。在加载网站时单击网格视图的第2或第3页时出错 / p>

但是,当我删除 AllowPaging =“True” PageSize =“10”时,我会收到相当多的条目。

CODE

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="StaffDetailsForStaffSalaryMonitoringSystemAdd.aspx.cs" Inherits="StaffDetailsForStaffSalaryMonitoringSystemAdd" %>

<!DOCTYPE html>

  <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
     <title></title>
      <style type="text/css">

        *
        {
            margin:0px;
            padding:0px;
        }

        body
        {
            font-family:Segoe UI;
        }


        div#KohinoorBanner
        {
            background-color:#004883;
            display:block;
            height:100px;
            position:relative;
        }
        div#KohinoorBanner img
        {
            position:absolute;
            left:15px;
            bottom:15px;
        }





        /* -------Styling the Horizontal Navigation Menu---------- */
       div#KohinoorNavigationMenu
        {
            /*outline:solid red 1px;*/
            height:30px;
            position:relative;
            top:1px;
            background-color:#980000;
            z-index:1;
        }

        ul#HorizontalNavigationMenu,ul#PayRollSubMenu,ul#MastersSubMenu,ul#EnquirySubMenu,ul#StudentDetailsSubMenu,ul#Account,ul#TellecallingSubMenu,ul#ReportsSubMenu,ul#LiveConversationSubMenu
        {
            list-style-type:none;
        }
        ul#HorizontalNavigationMenu a
        {
            text-decoration:none;
            display:block;
            width:175px;
            height:30px;
            background-color:#980000;
            color:white;
            line-height:30px;
            font-family:Sans-Serif;
            font-size:13px;
            outline:solid white 1px;
        }
        ul#HorizontalNavigationMenu li
        {
            position:relative;
            float:left;
            width:175px;
            display:block;
        }
        ul#HorizontalNavigationMenu ul#PayRollSubMenu
        {
            /*outline:solid blue 2px;*/
            position:relative;
            display:none;
            width:175px;
            top:1px;
        }
        ul#HorizontalNavigationMenu>li:hover ul#PayRollSubMenu
        {
            display:block;
        }

        ul#HorizontalNavigationMenu ul#PayRollSubMenu a
        {
            display:block;
            width:175px;
            background-color:#f89800;
        }
        ul#HorizontalNavigationMenu li:hover>a
        {
            background-color:#3064c8;
        }
        ul#HorizontalNavigationMenu ul#PayRollSubMenu li:hover>a
        {
            background-color:#f83000;
            display:block;
        }


        ul#HorizontalNavigationMenu ul#MastersSubMenu
        {
            /*outline:solid blue 2px;*/
            position:relative;
            display:none;
            width:175px;
            top:1px;
        }
        ul#HorizontalNavigationMenu ul#MastersSubMenu a
        {
            display:block;
            width:175px;
            background-color:#f89800;
        }
        ul#HorizontalNavigationMenu>li:hover ul#MastersSubMenu
        {
            display:block;
        }
        ul#HorizontalNavigationMenu ul#MastersSubMenu li:hover>a
        {
            background-color:#f83000;
            display:block;
        }


        ul#HorizontalNavigationMenu ul#EnquirySubMenu
        {
            /*outline:solid blue 2px;*/
            position:relative;
            display:none;
            width:175px;
            top:1px;
        }
        ul#HorizontalNavigationMenu ul#EnquirySubMenu a
        {
            display:block;
            width:175px;
            background-color:#f89800;
        }
        ul#HorizontalNavigationMenu>li:hover ul#EnquirySubMenu
        {
            display:block;
        }
        ul#HorizontalNavigationMenu ul#EnquirySubMenu li:hover>a
        {
            background-color:#f83000;
            display:block;
        }



        ul#HorizontalNavigationMenu ul#StudentDetailsSubMenu
        {
            /*outline:solid blue 2px;*/
            position:relative;
            display:none;
            width:175px;
            top:1px;
        }
        ul#HorizontalNavigationMenu ul#StudentDetailsSubMenu a
        {
            display:block;
            width:175px;
            background-color:#f89800;
        }
        ul#HorizontalNavigationMenu>li:hover ul#StudentDetailsSubMenu
        {
            display:block;
        }
        ul#HorizontalNavigationMenu ul#StudentDetailsSubMenu li:hover>a
        {
            background-color:#f83000;
            display:block;
        }


        /* -------Styling the Blue Gradient---------- */ 
        div#BlueGradient
        {
            position:absolute;
            display:block;
            height:30px;
            width:100%;
            border:solid blue 1px;
            z-index:-1;
        }





        /*--------Styling the StaffDetails--------*/
        div#StaffDetails
        {
            display:block;
            position:absolute;
            width:100%;
            height:400px;
            top:200px;
            border:solid red 1px;
            background-color:#d0dcc0;
            z-index:0;

        }

        div#StaffDetails div#StaffDetailsBanner
        {
            display:block;
            height:30px;
            line-height:30px;
            color:white;
            background-color:#3098c8;
            text-align:center;
            font-family:Calibri;
            font-weight:bold;
        }

        .GridViewTable
        {
            border-collapse:collapse;
            height:25px;
            width:100%;
            font-family:Segoe UI;
            font-size:11px;
            font-weight:bold;
            position:absolute;
            top:30px;
        }
        .TableHeadingRow
        {
            background-color:#688890;
            color:white;
            height:30px;
            text-align:center;
            font-weight:bold;
            font-size:13px;
            border:solid white 1px;
            font-family:'Segoe UI';
        }
        .TableRow
        {
            height:25px;
            color:#1b469d;
            border:solid white 1px;
            padding-left:5px;
            background-color:#d0dcc0;
            font-family:'Segoe UI';
            font-size:11px;
            text-align:center;
            font-weight:bold;
        }

        .BlueButton
        {
            background:#018788;
            width:75px;
            height:25px;
            color:white;
            border:solid white 2px;
            font-family:Segoe UI;
            font-weight:bold;
        }
        .BlueButton:hover
        {
            cursor:pointer;
        }



    </style>

  </head>
  <body>
<form id="StaffDetailsForm" runat="server" method="get" >
<!-- *************Kohinoor Banner****************** -->
    <div id="KohinoorBanner">
        <asp:Image runat="server" ID="KohinoorLogoImage" ImageUrl="~/Images/Kohinoor.jpg" alt="KohinoorLogo"></asp:Image>
        <div id="GoogleSearchSection"></div>
        <div id="Date"></div>
    </div>



    <!-- *************Kohinoor Horizontal Navigation Menu****************** -->
    <div id="KohinoorNavigationMenu">
        <ul id="HorizontalNavigationMenu">
            <li>
                <a href="#">&nbsp;--Masters--</a>
                 <ul id="MastersSubMenu"></ul>
          </li>
            <li>
                <a href="#">&nbsp;--Enquiry--</a>
                <ul id="EnquirySubMenu">
                    <li><a href="EnquiryRegistrationSystem.aspx" >&nbsp;>Registration</a></li>
                    <li><a href="FollowUpProcessSystem.aspx" >&nbsp;>>Followup</a></li>

                </ul>
            </li>
            <li>
                <a href="#">&nbsp;--Student Details--</a>
                <ul id="StudentDetailsSubMenu">
                    <li><a href="StudentPhotoUploadMonitoringSystem.aspx"  >&nbsp;>> Student Photo</a></li>





                </ul>
            </li>
            <li>
                <a href="#">&nbsp;--PayRoll--</a>
                <ul id="PayRollSubMenu">
                    <li><a href="StaffRegistrationSystem.aspx" >&nbsp;>> Staff Details</a></li>
                    <li><a href="StaffSalaryMonitoringsystem.aspx" >&nbsp;>> Salary Details</a></li>
                    <li><a href="StaffPhotoManagementSystem.aspx">&nbsp;>> Staff Photo</a></li>
                    <li><a href="StaffWorkProfileSystem.aspx" >&nbsp;>> Work Profile</a></li>
                    <li><a href="StaffLeaveMonitoringSystem.aspx">&nbsp;>> Leave Details</a></li>

                </ul>
            </li>
            <li><a href="#">&nbsp;--Reports--</a></li>
            <li><a href="#">&nbsp;--Live Conversation--</a></li>
            <li><a href="#">&nbsp;--Logout--</a></li>
        </ul>
    </div>





    <!-- *************Kohinoor Blue Gradient****************** -->
    <div id="BlueGradient">Blue Gradient</div>



    <!-- *************Staff Details****************** -->
    <asp:HiddenField runat="server" ID="SearchType_HiddenField" Value="" />
    <asp:HiddenField runat="server" ID="NameOrNo_HiddenField" Value="" />
    <asp:HiddenField runat="server" ID="EmployeeCode_HiddenField" Value="" />
    <asp:HiddenField runat="server" ID="FirstName_HiddenField" Value="" />
    <asp:HiddenField runat="server" ID="FirstPage" Value="true" />
    <div id="StaffDetails">
        <div id="StaffDetailsBanner">
            Staff Details
        </div>
        <div id="StaffDetailsContent">
            <asp:SqlDataSource runat="server"
                ID="SqlDataSource_FirstName"
                ConnectionString="Data Source=NIRMIT-PC\SQLEXPRESS;Initial Catalog=KohinoorDatabaseTrial3;Integrated Security=True"
                SelectCommand="SELECT SPD.emp_code, SN.first_name, SN.middle_name, SN.last_name, SPD.blood_group, SPD.religion, SPD.DOB, SPD.contact_no1, SPD.contact_no2, SED.highest_qualification, SOD.designation, SOD.aggrement_type, SOD.doj, SOD.pf_no
                FROM StaffPersonalDetails AS SPD
                LEFT OUTER JOIN StaffName AS SN
                ON SPD.emp_code = SN.emp_code
                LEFT OUTER JOIN StaffOfficialDetails AS SOD
                ON SPD.emp_code = SOD.emp_code
                LEFT OUTER JOIN StaffEducationalDetails AS SED
                ON SPD.emp_code = SED.emp_code
                WHERE SN.first_name LIKE '%' + @FirstName + '%'">
                <SelectParameters>
                    <asp:ControlParameter ControlID="FirstName_HiddenField" Name="FirstName" />
                </SelectParameters>
            </asp:SqlDataSource>
            <asp:SqlDataSource runat="server"
                ID="SqlDataSource_EmployeeCode"
                ConnectionString="Data Source=NIRMIT-PC\SQLEXPRESS;Initial Catalog=KohinoorDatabaseTrial3;Integrated Security=True"
                SelectCommand="SELECT SPD.emp_code, SN.first_name, SN.middle_name, SN.last_name, SPD.blood_group, SPD.religion, SPD.DOB, SPD.contact_no1, SPD.contact_no2, SED.highest_qualification, SOD.designation, SOD.aggrement_type, SOD.doj, SOD.pf_no
                FROM StaffPersonalDetails AS SPD
                LEFT OUTER JOIN StaffName AS SN
                ON SPD.emp_code = SN.emp_code
                LEFT OUTER JOIN StaffOfficialDetails AS SOD
                ON SPD.emp_code = SOD.emp_code
                LEFT OUTER JOIN StaffEducationalDetails AS SED
                ON SPD.emp_code = SED.emp_code
                WHERE SPD.emp_code = @EmployeeCode">
                <SelectParameters>
                    <asp:ControlParameter ControlID="EmployeeCode_HiddenField" Name="EmployeeCode" />
                </SelectParameters>
            </asp:SqlDataSource>
            <asp:GridView runat="server"
                ID="StaffDetailsGridView"
                Width="100%" 
                AllowPaging="true"
                PageSize="10"
                AutoGenerateColumns="False" 
                EmptyDataText="No Result Found"
                EnablePersistedSelection="True" 
                DataKeyNames="emp_code"
                CssClass="GridViewTable">
                <Columns>
                    <asp:BoundField DataField="emp_code" HeaderText="Emp Code"/>
                    <asp:TemplateField HeaderText="Student Name">
                        <ItemTemplate>
                            <asp:HyperLink ID="StaffNameHyperlink" NavigateUrl='<%# "~/StaffInformationBasicSalaryDetailAdd.aspx?EmpCode=" + Eval("emp_code") %>' runat="server"><asp:Label runat="server" ID="FirstNameLabel" Text='<%# Eval("first_name") + " " + Eval("middle_name") + " " + Eval("last_name")%>'></asp:Label></asp:HyperLink>
                        </ItemTemplate>
                    </asp:TemplateField>
                    <asp:BoundField DataField="blood_group" HeaderText="Blood Grp"/>
                    <asp:BoundField DataField="religion" HeaderText="Religion"/>
                    <asp:TemplateField HeaderText="DOB">
                        <ItemTemplate>
                            <asp:Label runat="server" Text='<%# Eval("DOB").ToString().Substring(0,11)%>'></asp:Label>
                        </ItemTemplate>
                    </asp:TemplateField>
                    <asp:BoundField DataField="contact_no1" HeaderText="Contact No" /> 
                    <asp:BoundField DataField="highest_qualification" HeaderText="Qualification" /> 
                    <asp:BoundField DataField="designation" HeaderText="Designation" /> 
                    <asp:BoundField DataField="aggrement_type" HeaderText="Aggrement Type" /> 
                    <asp:TemplateField HeaderText="Date of Join">
                        <ItemTemplate>
                            <asp:Label runat="server" Text='<%# Eval("doj").ToString()%>'></asp:Label>
                        </ItemTemplate>
                    </asp:TemplateField>
                    <asp:BoundField DataField="pf_no" HeaderText="Pf No" />
                </Columns>
                <HeaderStyle CssClass="TableHeadingRow" />
                <RowStyle CssClass="TableRow" />
            </asp:GridView>
        </div>
    </div>
</form>

代码背后

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class StaffDetailsForStaffSalaryMonitoringSystemAdd : System.Web.UI.Page
{
   DropDownList SearchType_DropDownList;
   String SearchType_Selected;
   TextBox NameOrNo_TextBox;
   String NameOrNo_Selected;
   protected void Page_Load(object sender, EventArgs e)
   {
    if(FirstPage.Value.ToLower().Trim().Equals("true"))
    {
        SearchType_DropDownList = (DropDownList)PreviousPage.FindControl("SearchType");
        SearchType_Selected = SearchType_DropDownList.SelectedItem.Text;
        NameOrNo_TextBox = (TextBox)PreviousPage.FindControl("NameOrNo");
        NameOrNo_Selected = NameOrNo_TextBox.Text;

        SearchType_HiddenField.Value = SearchType_Selected;
        NameOrNo_HiddenField.Value = NameOrNo_Selected;
        if (SearchType_Selected.Equals("Employee Code"))
        {
            EmployeeCode_HiddenField.Value = NameOrNo_Selected;
            StaffDetailsGridView.DataSourceID = SqlDataSource_EmployeeCode.ID;
        }
        if (SearchType_Selected.Equals("Name"))
        {
            FirstName_HiddenField.Value = NameOrNo_Selected;
            StaffDetailsGridView.DataSourceID = SqlDataSource_FirstName.ID;
        }
        StaffDetailsGridView.DataBind();
        FirstPage.Value = "false";
    }


}

//protected void StaffDetailsGridView_PageIndexChanging(object sender, GridViewPageEventArgs e)
//{
//    //StaffDetailsGridView.PageIndex = e.NewPageIndex;
//    //SearchType_Selected = SearchType_HiddenField.Value;
//    //NameOrNo_Selected = NameOrNo_HiddenField.Value;
//    //if (SearchType_Selected.Equals("Employee Code"))
//    //{
//    //    EmployeeCode_HiddenField.Value = NameOrNo_Selected;
//    //    StaffDetailsGridView.DataSource = SqlDataSource_EmployeeCode;
//    //}
//    //if (SearchType_Selected.Equals("Name"))
//    //{
//    //    FirstName_HiddenField.Value = NameOrNo_Selected;
//    //    StaffDetailsGridView.DataSource = SqlDataSource_FirstName;
//    //}
//    //StaffDetailsGridView.DataBind();
//}
 }

很抱歉将它放在这里,因为它不适合评论 这是我在回发时获得的链接(即点击网格的某些页码后

//本地主机:55415 / StaffDetailsForStaffSalaryMonitoringSystemAdd.aspx __ EVENTTARGET = StaffDetailsGridView&安培; __ EVENTARGUMENT =页%243安培; __ VIEWSTATE = 9z9ztJ5%2Ftwu4G%的2Fe%2Fu1hJUeTt4CsKw0J6Iv%2BR0ruYcADC572F%2B9bgbQrdk6T8l%2FbEMDhBagjhIKaGlAWq%2BkUKGgEvIoEHoqCxPRn4lfMe4l2K8ZLl%2FkTUwx20NhOWW9Gr8heXkjbEVz8cS1zhxrSW7s28OZFAs20x8vi2EmOrSlFUKjeYDShlfDgDz .....

1 个答案:

答案 0 :(得分:1)

您是否尝试在网络配置中添加此行

     <system.web>
      <httpRuntime maxQueryStringLength="32768" maxUrlLength="65536"/>

     </system.web>

   <system.webServer>
   <security>
       <requestFiltering>
       <requestLimits maxQueryString="2097151"/>
    </requestFiltering>
  </security>
 </system.webServer>

在分页时,你的查询字符串似乎太长了,因为你有很长的类名,例如&#34; StaffDetailsForStaffSalaryMonitoringSystemAdd&#34;。你的网址在分页时会变成这样的东西

  <a    href="javascript:__doPostBack('ctl00$ContentPlaceholder$StaffDetailsForStaffSalaryMonitoringSystemAdd$StaffDetailsGridView','Page$2')">2</a>

因此出错。根据您的喜好增加webconfig中设置的值。