Detailed description of the GridView custom paging instance (with demo source code download) and gridviewdemo
This article describes how to implement the custom page of The GridView. We will share this with you for your reference. The details are as follows:
CSS style
First, paste the CSS style code:
.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 Style
Based on the CSS style name listed above, add them to different tabs of the web page GridView, for example:
<RowStyle BackColor="#E7E7FF" ForeColor="#4A3C8C" CssClass="gvRow" /><HeaderStyle BackColor="#4A3C8C" Font-Bold="True" ForeColor="#F7F7F7" CssClass="gvHeader" /><AlternatingRowStyle BackColor="#F7F7F7" CssClass="gvAlternatingRow" />
Pager Page Template
The code below the gridview is:
<PagerTemplate> <table width = "100%" style = "font-size: 12px;"> <tr> <td style = "text-align: right"> NO. <asp: label ID = "lblPageIndex" runat = "server" Text = '<% # (GridView) Container. parent. parent ). pageIndex + 1%> '> </asp: Label> page/total <asp: Label ID = "lblPageCount" runat = "server" Text =' <% # (GridView) container. parent. parent ). pageCount %> '> </asp: Label> page <asp: LinkButton ID = "LinkButtonFirstPage" runat = "server" Comma NdArgument = "First" CommandName = "Page" Visible = "<% # (GridView) Container. NamingContainer). PageIndex! = 0%> "> homepage </asp: LinkButton> <asp: linkButton ID = "LinkButtonPreviousPage" runat = "server" CommandArgument = "Prev" CommandName = "Page" Visible = "<% # (GridView) Container. namingContainer ). pageIndex! = 0%> "> previous page </asp: LinkButton> <asp: linkButton ID = "LinkButtonNextPage" runat = "server" CommandArgument = "Next" CommandName = "Page" Visible = "<% # (GridView) Container. namingContainer ). pageIndex! = (GridView) Container. namingContainer ). pageCount-1%> "> next page </asp: LinkButton> <asp: linkButton ID = "LinkButtonLastPage" runat = "server" CommandArgument = "Last" CommandName = "Page" Visible = "<% # (GridView) Container. namingContainer ). pageIndex! = (GridView) Container. namingContainer ). pageCount-1%> "> last page </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>
Trigger event
The btnGo_Click method is defined as follows:
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(); }}
Demonstration and source code download
Click here to download the complete instance code.
I hope this article will help you design your asp.net program.
Articles you may be interested in:
- Examples of pagination implementation and custom pagination style of GridView
- Four stored procedures for custom pagination in GridView
- C # display TreeView with custom DataGridViewColumn
- Use of custom buttons and links in GridView in yii2.0
- Specific methods for customizing the delete operation of the GridView
- Customize the GridView and implement drag and drop (with source code)
- Code for customizing the value of asp.net gridview
- Asp.net gridview page: First page next page 1 2 3 4 Previous Page last page
- GridView paging in asp.net
- How to Implement Tab labels using ActivityGroup + GridView in getting started with Android
- Asp.net Gridview paging save Option
- TAB Page Based on GridView and ActivityGroup (with source code)