GridView自定義分頁實例詳解(附demo源碼下載)
本文實例講述了GridView自定義分頁實現(xiàn)方法。分享給大家供大家參考,具體如下:
CSS樣式
首先把CSS樣式代碼粘貼過來:
.gv { border: 1px solid #D7D7D7; font-size:12px; text-align:center; } .gvHeader { color: #3F6293; background-color: #F7F7F7; height: 24px; line-height: 24px; text-align: center; font-weight: normal; font-variant: normal; } .gvHeader th { font-weight: normal; font-variant: normal; } .gvRow, .gvAlternatingRow, .gvEditRow { line-height: 20px; text-align: center; padding: 2px; height: 20px; } .gvAlternatingRow { background-color: #F5FBFF; } .gvEditRow { background-color: #FAF9DD; } .gvEditRow input { background-color: #FFFFFF; width: 80px; } .gvEditRow .gvOrderId input, .gvEditRow .gvOrderId { width: 30px; } .gvEditRow .checkBox input, .gvEditRow .checkBox { width: auto; } .gvCommandField { text-align: center; width: 130px; } .gvLeftField { text-align: left; padding-left: 10px; } .gvBtAField { text-align: center; width: 130px; } .gvCommandField input { background-image: url(../Images/gvCommandFieldABg.jpg); background-repeat: no-repeat; line-height: 23px; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; width: 50px; height: 23px; margin-right: 3px; margin-left: 3px; text-indent: 10px; } .gvPage { padding-left: 15px; font-size: 18px; color: #333333; font-family: Arial, Helvetica, sans-serif; } .gvPage a { display: block; text-decoration: none; padding-top: 2px; padding-right: 5px; padding-bottom: 2px; padding-left: 5px; border: 1px solid #FFFFFF; float: left; font-size: 12px; font-weight: normal; } .gvPage a:hover { display: block; text-decoration: none; border: 1px solid #CCCCCC; }
GridView樣式
根據(jù)上面列出的CSS樣式樣式名稱,將他們分別加入網(wǎng)頁GridView的不同標(biāo)記中,舉例如下:
<RowStyle BackColor="#E7E7FF" ForeColor="#4A3C8C" CssClass="gvRow" /> <HeaderStyle BackColor="#4A3C8C" Font-Bold="True" ForeColor="#F7F7F7" CssClass="gvHeader" /> <AlternatingRowStyle BackColor="#F7F7F7" CssClass="gvAlternatingRow" />
Pager分頁模板
其中g(shù)ridview下方的換頁代碼為:
<PagerTemplate> <table width="100%" style="font-size:12px;"> <tr> <td style="text-align: right"> 第<asp:Label ID="lblPageIndex" runat="server" Text='<%# ((GridView)Container.Parent.Parent).PageIndex + 1 %>'></asp:Label>頁 /共<asp:Label ID="lblPageCount" runat="server" Text='<%# ((GridView)Container.Parent.Parent).PageCount %>'></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" Text='<%# ((GridView)Container.Parent.Parent).PageIndex + 1 %>' Width="20px" AutoPostBack="true" ></asp:TextBox> <asp:LinkButton ID="btnGo" runat="server" CommandArgument="GO" CommandName="Page" Text="GO" OnClick="btnGo_Click"></asp:LinkButton> </td> </tr> </table> </PagerTemplate>
觸發(fā)事件
方法btnGo_Click的定義如下所示:
protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e) { GridView1.PageIndex = e.NewPageIndex; BindData(); } protected void btnGo_Click(object sender, EventArgs e) { if (((LinkButton)sender).CommandArgument.ToString().ToLower().Equals("go")) { GridViewRow gridViewRow = GridView1.BottomPagerRow; TextBox numBox = (TextBox)GridView1.BottomPagerRow.FindControl("txtNewPageIndex"); int inputNum = Convert.ToInt32(numBox.Text); GridView1.PageIndex = inputNum - 1; BindData(); } }
效果圖展示及源碼下載
完整實例代碼點擊此處本站下載。
希望本文所述對大家asp.net程序設(shè)計有所幫助。
相關(guān)文章
一步步打造簡單的MVC電商網(wǎng)站BooksStore(4)
這篇文章主要和大家一起一步步打造一個簡單的MVC電商網(wǎng)站,MVC電商網(wǎng)站BooksStore第四篇,具有一定的參考價值,感興趣的小伙伴們可以參考一下2017-04-04ASP.NET對txt文件相關(guān)操作(讀取、寫入、保存)
這篇文章主要介紹了ASP.NETtxt文件相關(guān)操作,包括讀取、寫入、保存,需要的朋友可以參考下2015-09-09C#數(shù)據(jù)導(dǎo)入/導(dǎo)出Excel文件及winForm導(dǎo)出Execl總結(jié)
在asp.net中導(dǎo)出Execl有兩種方法.一種是將導(dǎo)出的文件存放在服務(wù)器某個文件夾下面.一種是將文件直接將文件輸出流寫給瀏覽器2013-01-01ASP.NET小結(jié)之MVC, MVP, MVVM比較以及區(qū)別(一)
MVC, MVP和MVVM都是用來解決界面呈現(xiàn)和邏輯代碼分離而出現(xiàn)的模式。以前只是對它們有部分的了解,沒有深入的研究過,對于一些里面的概念和區(qū)別也是一知半解?,F(xiàn)在一邊查資料,并結(jié)合自己的理解,來談一下對于這三種模式思想的理解,以及它們的區(qū)別。歡迎各位高手拍磚。2014-05-05ASP.NET MVC視圖頁使用jQuery傳遞異步數(shù)據(jù)的幾種方式詳解
本文詳細講解了ASP.NET MVC視圖頁使用jQuery傳遞異步數(shù)據(jù)的幾種方式,文中通過示例代碼介紹的非常詳細。對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下2022-09-09.NET?6新特性試用之System.Text.Json功能改進
這篇文章主要介紹了.NET?6新特性試用之System.Text.Json功能改進,2022-03-03在asp.net中實現(xiàn)datagrid checkbox 全選的方法
在asp.net中實現(xiàn)datagrid checkbox 全選的方法...2006-12-12