Gridveiew PagerTemplate模板使用

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="MaxLoadLevel.aspx.cs" Inherits="KGE.Web.Integration.App.AnalysePW.DataStat.MaxLoadLevel" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>最大负载率</title>
    <meta http-equiv="Content-Type" content="text/html;charset=GB2312"/>
    <link href=http://www.cnblogs.com/../CSS<%=mCssPath %>/body1.CSS type="text/css" rel="stylesheet"/>   
 <link href=http://www.cnblogs.com/../CSS<%=mCssPath %>/TabStyle.CSS type="text/css" rel="stylesheet"/>
 <link href=http://www.cnblogs.com/../CSS<%=mCssPath %>/Href1.CSS type="text/css" rel="stylesheet"/>
    <meta http-equiv="Content-Type" content="text/html;charset=GB2312"/>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <table align="center">
            <tr>
            <td>
                <asp:GridView Width="2000px" ID="GridView" visible="true" runat="server" AllowPaging="True" OnPageIndexChanging="GridView_PageIndexChanging" PageSize="25" AutoGenerateColumns="False" BorderStyle="Solid"  BorderWidth="1px">
                            <HeaderStyle CssClass="gvHeader" BackColor="#E7E6DA" Font-Bold="false"   Font-Size="12px"  />
                            <AlternatingRowStyle BackColor="#FFFFFF" />
                           <PagerStyle HorizontalAlign="Left"  VerticalAlign="Top" />
                    <EmptyDataTemplate>
                    <h3>没有您要查询的数据</h3>
              </EmptyDataTemplate>
                    <Columns>

                        <asp:TemplateField>
                            <HeaderTemplate>
                                 <table border="1" cellspacing="0"  width="100%" >
                                      <tr  >
                                        <td  rowspan="2">
                                            区县局</td>
                                        <td  rowspan="2">
                                            供电所</td>
                                        <td  rowspan="2">
                                            变电站</td>
                                        <td  rowspan="2">
                                            馈线GIS号</td>
                                        <td  rowspan="2">
                                            馈线名称</td>
                                        <td  rowspan="2">
                                            台区GIS号</td>
                                        <td  rowspan="2">
                                            台区名称</td>
                                        <td  rowspan="2">
                                            配变类别</td>
                                        <td  rowspan="2">
                                            容量</td>
                                        <td  rowspan="2">
                                            CT</td>
                                        <td  rowspan="2">
                                            PT</td>
                                        <td  colspan="4">
                                            A相电流最大时</td>
                                        <td  colspan="4">
                                            B相电流最大时</td>
                                        <td  colspan="4">
                                            C相电流最大时</td>
                                    </tr>
                                    <tr>
                                        <td >
                                            电流</td>
                                        <td >
                                            发生时间</td>
                                        <td >
                                            电压</td>
                                        <td >
                                            负载率%</td>
                                        <td >
                                            电流</td>
                                        <td >
                                            发生时间</td>
                                        <td >
                                            电压</td>
                                        <td >
                                            负载率%</td>
                                        <td >
                                            电流</td>
                                        <td >
                                            发生时间</td>
                                        <td >
                                            电压</td>
                                        <td >
                                            负载率%</td>
                                    </tr>
                            </HeaderTemplate>
                            <ItemTemplate>
                                <tr >   
                                    <td ><asp:Literal ID="Litergdjname" runat="server" Text='<%# Eval(" gdjname") %>'></asp:Literal></td>
                                    <td ><asp:Literal ID="Litergdsname" runat="server" Text='<%# Eval(" gdsname") %>'></asp:Literal></td>
                                    <td ><asp:Literal ID="Literbdzname" runat="server" Text='<%# Eval("bdzname") %>'></asp:Literal></td>
                                    <td ><asp:Literal ID="Literal1" runat="server" Text='<%# Eval("lineid") %>'></asp:Literal></td>
                                    <td ><asp:Literal ID="LiterCap" runat="server" Text='<%# Eval("linename") %>'></asp:Literal></td>
                                    <td ><asp:Literal ID="Literal2" runat="server" Text='<%# Eval("transformerid") %>'></asp:Literal></td>
                                    <td ><asp:Literal ID="Literal3" runat="server" Text='<%# Eval("transformername") %>'></asp:Literal></td>
                                    <td ><asp:Literal ID="Literal4" runat="server" Text='<%# Eval("配变类别") %>'></asp:Literal></td>
                                    <td ><asp:Literal ID="LiterAmmeterCode" runat="server" Text='<%# Eval("transformersize") %>'></asp:Literal></td>
                                    <td ><asp:Literal ID="Literal5" runat="server" Text='<%# Eval("CT") %>'></asp:Literal></td>
                                    <td ><asp:Literal ID="Literal6" runat="server" Text='<%# Eval("PT") %>'></asp:Literal></td> 
                                    <td ><asp:Literal ID="Literal7" runat="server" Text='<%# Eval("adl") %>'></asp:Literal></td>
                                    <td ><asp:Literal ID="Literal8" runat="server" Text='<%# Eval("adldate") %>'></asp:Literal></td>
                                    <td ><asp:Literal ID="Literal9" runat="server" Text='<%# Eval("ady") %>'></asp:Literal></td> 
                                    <td ><asp:Literal ID="Literal10" runat="server" Text='<%# Eval("afz") %>'></asp:Literal></td>
                                    <td ><asp:Literal ID="Literal11" runat="server" Text='<%# Eval("bdl") %>'></asp:Literal></td>
                                    <td ><asp:Literal ID="Literal12" runat="server" Text='<%# Eval("bdldate") %>'></asp:Literal></td>
                                    <td ><asp:Literal ID="Literal13" runat="server" Text='<%# Eval("bdy") %>'></asp:Literal></td> 
                                    <td ><asp:Literal ID="Literal14" runat="server" Text='<%# Eval("bfz") %>'></asp:Literal></td>                                                               <td ><asp:Literal ID="Literal15" runat="server" Text='<%# Eval("cdl") %>'></asp:Literal></td>
                                    <td ><asp:Literal ID="Literal16" runat="server" Text='<%# Eval("cdldate") %>'></asp:Literal></td>
                                    <td ><asp:Literal ID="Literal17" runat="server" Text='<%# Eval("cdy") %>'></asp:Literal></td> 
                                    <td ><asp:Literal ID="Literal18" runat="server" Text='<%# Eval("cfz") %>'></asp:Literal></td> 
                               </tr>
                            </ItemTemplate>
                            <FooterTemplate>
                                </table>
                            </FooterTemplate>
                        </asp:TemplateField>
                    </Columns>    
                    <PagerTemplate>
                    <tr>
                        <td colspan="23" style="text-align:left;">
                                   
                                         当前第:
                                        <asp:Label  ID="LabelCurrentPage" runat="server"
                                         Text="<%# ((GridView)Container.NamingContainer).PageIndex + 1 %>"></asp:Label>
                                         页/共:
                                        <asp:Label ID="LabelPageCount" runat="server"
                                         Text="<%# ((GridView)Container.NamingContainer).PageCount %>"></asp:Label> 页
                                          每页
                                        <asp:Label ID="Label5" runat="server"
                                         Text="25"></asp:Label>                        
                                         <asp:LinkButton ID="LinkButtonFirstPage" runat="server" CommandArgument="First" CommandName="Page"
                                         Visible='<%#((GridView)Container.NamingContainer).PageIndex != 0 %>'>首页</asp:LinkButton>
                                        <asp:LinkButton ID="LinkButtonPreviousPage" runat="server" CommandArgument="Prev" CommandName="Page"
                                         Visible='<%# ((GridView)Container.NamingContainer).PageIndex != 0 %>'>上一页</asp:LinkButton>
                                        <asp:LinkButton ID="LinkButtonNextPage" runat="server" CommandArgument="Next" CommandName="Page"
                                         Visible='<%# ((GridView)Container.NamingContainer).PageIndex != ((GridView)Container.NamingContainer).PageCount - 1 %>'>下一页</asp:LinkButton>
                                        <asp:LinkButton ID="LinkButtonLastPage" runat="server" CommandArgument="Last" CommandName="Page"
                                         Visible='<%# ((GridView)Container.NamingContainer).PageIndex != ((GridView)Container.NamingContainer).PageCount - 1 %>'>尾页</asp:LinkButton>
                                          转到第
                                        <asp:textbox id="txtNewPageIndex" runat="server" width="20px" text='<%# ((GridView)Container.Parent.Parent).PageIndex + 1 %>' />页
                                        <asp:linkbutton id="btnGo" runat="server" causesvalidation="False" commandargument="-1" commandname="Page" text="GO" />

                        </td>
            </tr>
            </PagerTemplate>
           
                    
                 </asp:GridView>
                </td>
        </tr>
        </table>
    </div>
    </form>
</body>
</html>

 

 

 protected void GridView_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            //this.GridView1.PageIndex = e.NewPageIndex;
            //this.GridView1.DataBind(); 
            //gvProject.PageIndex = e.NewPageIndex;
            //this.BindProjectList();
            GridView theGrid = sender as GridView; // refer to the GridView
            int newPageIndex = 0;
            if (-2 == e.NewPageIndex)
            { // when click the "GO" Button
                TextBox txtNewPageIndex = null;
                //GridViewRow pagerRow = theGrid.Controls[0].Controls[theGrid.Controls[0].Controls.Count - 1] as GridViewRow; // refer to PagerTemplate
                GridViewRow pagerRow = theGrid.BottomPagerRow; //GridView较DataGrid提供了更多的API,获取分页块可以使用BottomPagerRow 或者TopPagerRow,当然还增加了HeaderRow和FooterRow
                //updated at 2006年月日:15:33
                if (null != pagerRow)
                {
                    txtNewPageIndex = pagerRow.FindControl("txtNewPageIndex") as TextBox;   // refer to the TextBox with the NewPageIndex value
                }
                if (null != txtNewPageIndex)
                {
                    newPageIndex = int.Parse(txtNewPageIndex.Text) - 1; // get the NewPageIndex
                }
            }
            else
            { // when click the first, last, previous and next Button
                newPageIndex = e.NewPageIndex;
            }
            // check to prevent form the NewPageIndex out of the range
            newPageIndex = newPageIndex < 0 ? 0 : newPageIndex;
            newPageIndex = newPageIndex >= theGrid.PageCount ? theGrid.PageCount - 1 : newPageIndex;
            // specify the NewPageIndex
            theGrid.PageIndex = newPageIndex;
            // rebind the control
            // in this case of retrieving the data using the xxxDataSoucr control,
            // just do nothing, because the asp.net engine binds the data automatically

            //this.Search();//数据绑定的方法
            GetQuery();
            DataLoad();
            GridView.Attributes.Add("BorderColor", "#C0C0C0");
        }

 


 

posted @ 2009-11-24 17:12  XGU_Winner  阅读(324)  评论(0编辑  收藏  举报