濮阳杆衣贸易有限公司

主頁 > 知識庫 > GridView自定義分頁實例詳解(附demo源碼下載)

GridView自定義分頁實例詳解(附demo源碼下載)

熱門標簽:濮陽外呼電銷系統(tǒng)怎么樣 地圖標注的公司有哪些 地圖標注專業(yè)團隊 遂寧市地圖標注app 塔城代理外呼系統(tǒng) 天心智能電銷機器人 代理接電話機器人如何取消 地圖定位圖標標注 400電話辦理哪家性價比高

本文實例講述了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的不同標記中,舉例如下:

RowStyle BackColor="#E7E7FF" ForeColor="#4A3C8C" CssClass="gvRow" />
HeaderStyle BackColor="#4A3C8C" Font-Bold="True" ForeColor="#F7F7F7" CssClass="gvHeader" />
AlternatingRowStyle BackColor="#F7F7F7" CssClass="gvAlternatingRow" />

Pager分頁模板

其中gridview下方的換頁代碼為:

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>頁nbsp;nbsp;
     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程序設計有所幫助。

您可能感興趣的文章:
  • ASP.NET數(shù)據(jù)綁定GridView控件使用技巧
  • 淺析GridView中顯示時間日期格式的問題
  • Gridview利用DataFormatString屬性設置數(shù)據(jù)格式的方法
  • GridView中日期不顯示時分秒的完美解決方法

標簽:宜春 婁底 吉林 重慶 麗江 汕頭 本溪 河南

巨人網(wǎng)絡通訊聲明:本文標題《GridView自定義分頁實例詳解(附demo源碼下載)》,本文關鍵詞  GridView,自定義,分頁,實例,;如發(fā)現(xiàn)本文內容存在版權問題,煩請?zhí)峁┫嚓P信息告之我們,我們將及時溝通與處理。本站內容系統(tǒng)采集于網(wǎng)絡,涉及言論、版權與本站無關。
  • 相關文章
  • 下面列出與本文章《GridView自定義分頁實例詳解(附demo源碼下載)》相關的同類信息!
  • 本頁收集關于GridView自定義分頁實例詳解(附demo源碼下載)的相關信息資訊供網(wǎng)民參考!
  • 推薦文章
    丹凤县| 秭归县| 札达县| 洛阳市| 剑川县| 安多县| 南京市| 清丰县| 拜泉县| 隆化县| 都匀市| 土默特右旗| 丰顺县| 嘉荫县| 钦州市| 佛教| 木兰县| 益阳市| 乡城县| 宕昌县| 武夷山市| 芮城县| 桐城市| 武穴市| 焦作市| 平昌县| 新田县| 广水市| 永康市| 土默特右旗| 关岭| 金秀| 五峰| 渝北区| 娱乐| 京山县| 闻喜县| 万宁市| 伊宁市| 临洮县| 鄂伦春自治旗|