问题描述
前台:<asp:GridViewID="GridView1"runat="server"BackColor="White"AutoGenerateColumns="False"AllowPaging="True"OnPageIndexChanging="gvwDesignationName_PageIndexChanging"CellPadding="6"style="margin-left:auto;margin-right:auto;"Width="1250px"BorderColor="#999999"><Columns><asp:TemplateFieldHeaderText="序号"InsertVisible="False"><ItemStyleHorizontalAlign="Center"/><HeaderStyleHorizontalAlign="Center"Width="5%"/><ItemTemplate><asp:LabelID="Label5"runat="server"Text='<%#this.GridView1.PageIndex*this.GridView1.PageSize+this.GridView1.Rows.Count+1%>'/></ItemTemplate></asp:TemplateField><asp:BoundFieldDataField="pro"HeaderText="省份"/><asp:BoundFieldDataField="city"HeaderText="城市"/><asp:BoundFieldDataField="are"HeaderText="区域面积(平方公里)"/><asp:BoundFieldDataField="pop"HeaderText="人口总数(人)"/><asp:BoundFieldDataField="gdp"HeaderText="GDP(区域GDP/人均GDP)"/><asp:BoundFieldDataField="adp"HeaderText="行政划分"/><asp:BoundFieldDataField="env"HeaderText="环境资源"/><asp:BoundFieldDataField="ind"HeaderText="支柱产业"/><asp:BoundFieldDataField="tra"HeaderText="交通资源"/><asp:BoundFieldDataField="uc"HeaderText="用车行为分析"/></Columns><PagerTemplate><asp:LabelID="LabelCurrentPage"runat="server"Text="<%#((GridView)Container.NamingContainer).PageIndex+1%>"></asp:Label>页/共:<asp:LabelID="LabelPageCount"runat="server"Text="<%#((GridView)Container.NamingContainer).PageCount%>"></asp:Label>页<asp:LinkButtonID="LinkButtonFirstPage"runat="server"CommandArgument="First"CommandName="Page"Visible='<%#((GridView)Container.NamingContainer).PageIndex!=0%>'ForeColor="#CCCCFF">首页</asp:LinkButton><asp:LinkButtonID="LinkButtonPreviousPage"runat="server"CommandArgument="Prev"CommandName="Page"Visible='<%#((GridView)Container.NamingContainer).PageIndex!=0%>'ForeColor="#CCCCFF">上一页</asp:LinkButton><asp:LinkButtonID="LinkButtonNextPage"runat="server"CommandArgument="Next"CommandName="Page"Visible='<%#((GridView)Container.NamingContainer).PageIndex!=((GridView)Container.NamingContainer).PageCount-1%>'ForeColor="#CCCCFF">下一页</asp:LinkButton><asp:LinkButtonID="LinkButtonLastPage"runat="server"CommandArgument="Last"CommandName="Page"Visible='<%#((GridView)Container.NamingContainer).PageIndex!=((GridView)Container.NamingContainer).PageCount-1%>'ForeColor="#CCCCFF">尾页</asp:LinkButton><asp:TextBoxID="txtNewPageIndex"runat="server"Width="20px"Text='<%#((GridView)Container.Parent.Parent).PageIndex+1%>'/>页<asp:LinkButtonID="btnGo"runat="server"CausesValidation="False"CommandArgument="-2"CommandName="Page"Text="GO"ForeColor="#CCCCFF"/></PagerTemplate><RowStyleBackColor="White"ForeColor="#003399"/><SelectedRowStyleBackColor="#009999"ForeColor="#CCFF99"Font-Bold="True"/><PagerStyleBackColor="#003399"ForeColor="#CCCCFF"HorizontalAlign="Left"/><HeaderStyleBackColor="#003399"Font-Bold="True"ForeColor="#CCCCFF"/><SortedAscendingCellStyleBackColor="#EDF6F6"/><SortedAscendingHeaderStyleBackColor="#0D4AC4"/><SortedDescendingCellStyleBackColor="#D6DFDF"/><SortedDescendingHeaderStyleBackColor="#002876"/></asp:GridView>后台:publicvoidbind(){stringsqlstr;sqlstr="select*from[list]orderbypro";sqlcon=newSqlConnection(strCon);SqlDataAdaptermyda=newSqlDataAdapter(sqlstr,sqlcon);DataSetmyds=newDataSet();sqlcon.Open();myda.Fill(myds,"[list]");GridView1.DataSource=myds;GridView1.DataKeyNames=newstring[]{"city"};GridView1.DataBind();sqlcon.Close();}//分页protectedvoidgvwDesignationName_PageIndexChanging(objectsender,GridViewPageEventArgse){GridViewtheGrid=senderasGridView;intnewPageIndex=0;if(e.NewPageIndex==-3){TextBoxtxtNewPageIndex=null;GridViewRowpagerRow=theGrid.BottomPagerRow;if(pagerRow!=null){txtNewPageIndex=pagerRow.FindControl("txtNewPageIndex")asTextBox;}if(txtNewPageIndex!=null){newPageIndex=int.Parse(txtNewPageIndex.Text)-1;}}else{newPageIndex=e.NewPageIndex;}newPageIndex=newPageIndex<0?0:newPageIndex;newPageIndex=newPageIndex>=theGrid.PageCount?theGrid.PageCount-1:newPageIndex;theGrid.PageIndex=newPageIndex;bind();}输入想要跳转的页码,点击GO后不能跳转,求帮助,紧急!
解决方案
解决方案二:
代码太长了,除非错误很明显能看出来,否则很少有人有时间帮你全部调试一遍,建议你试试,分页只需要几行代码就可以了:
解决方案三:
先设断点调试一下
解决方案四:
解决方案五:
调试一下吧,代码没法看