非常实用的GridView.PagerTemplate 属性

article/2025/9/23 0:08:03

获取或设置 GridView 控件中页导航行的自定义内容。

命名空间:System.Web.UI.WebControls
程序集:System.Web(在 system.web.dll 中)

语法:C#

[TemplateContainerAttribute( typeof (GridViewRow))] 
public   virtual  ITemplate PagerTemplate {  get set ; }

 

属性值

一个 System.Web.UI.ITemplate ,包含页导航行的自定义内容。默认值为 null,表示未设置此属性。

备注下面的代码示例演示如何创建一个允许用户使用 DropDownList 控件在 GridView 控件中进行导航的自定义页导航模板。

启用分页功能时(即 AllowPaging 属性设置为 true 时),GridView 控件中显示一个页导航行。该页导航行包含允许用户导航到该控件的不同页面的控件。可以不使用内置页导航行用户界面 (UI),而使用 PagerTemplate 属性定义您自己的用户界面。

注意

设置 PagerTemplate 属性时,该属性重写内置页导航行用户界面。

若要为页导航行指定自定义模板,先要在 GridView 控件的开始标记和结束标记之间放置 <PagerTemplate> 标记。然后可以在开始和结束 <PagerTemplate> 标记之间列出模板的内容。若要控制页导航行的外观,请使用 PagerStyle 属性。

通常,将按钮控件添加到页导航模板以执行分页操作。单击 CommandName 属性设置为“Page”的按钮控件时,GridView 控件会执行分页操作。按钮的 CommandArgument 属性确定要执行的分页操作的类型。下表列出了 GridView 控件支持的命令参数值。

CommandArgument 值

说明

“Next”

导航至下一页。

“Prev”

导航至上一页。

“First”

导航至第一页。

“Last”

导航至最后一页。

整数值

导航至指定页码。

示例

说明:演示如何创建一个允许用户使用 DropDownList 控件在 GridView 控件中进行导航的自定义页导航模板。

<% @ Page language = " C# "   %>

< script runat = " server " >

  
void  PageDropDownList_SelectedIndexChanged(Object sender, EventArgs e)
  
{

    
// Retrieve the pager row.
    GridViewRow pagerRow = CustomersGridView.BottomPagerRow;
    
    
// Retrieve the PageDropDownList DropDownList from the bottom pager row.
    DropDownList pageList = (DropDownList)pagerRow.Cells[0].FindControl("PageDropDownList");

    
// Set the PageIndex property to display that page selected by the user.
    CustomersGridView.PageIndex = pageList.SelectedIndex;

  }


  
void  CustomersGridView_DataBound(Object sender, EventArgs e)
  
{

    
// Retrieve the pager row.
    GridViewRow pagerRow = CustomersGridView.BottomPagerRow;
    
    
// Retrieve the DropDownList and Label controls from the row.
    DropDownList pageList = (DropDownList)pagerRow.Cells[0].FindControl("PageDropDownList");
    Label pageLabel 
= (Label)pagerRow.Cells[0].FindControl("CurrentPageLabel");
        
    
if(pageList != null)
    
{
        
      
// Create the values for the DropDownList control based on 
      
// the  total number of pages required to display the data
      
// source.
      for(int i=0; i<CustomersGridView.PageCount; i++)
      
{
            
        
// Create a ListItem object to represent a page.
        int pageNumber = i + 1;
        ListItem item 
= new ListItem(pageNumber.ToString());         
            
        
// If the ListItem object matches the currently selected
        
// page, flag the ListItem object as being selected. Because
        
// the DropDownList control is recreated each time the pager
        
// row gets created, this will persist the selected item in
        
// the DropDownList control.   
        if(i==CustomersGridView.PageIndex)
        
{
          item.Selected 
= true;
        }

            
        
// Add the ListItem object to the Items collection of the 
        
// DropDownList.
        pageList.Items.Add(item);
                
      }

        
    }

        
    
if(pageLabel != null)
    
{
        
      
// Calculate the current page number.
      int currentPage = CustomersGridView.PageIndex + 1;     
        
      
// Update the Label control with the current page information.
      pageLabel.Text = "Page " + currentPage.ToString() +
        
" of " + CustomersGridView.PageCount.ToString();
        
    }
    
    
  }


</ script >

< html >
  
< body >
    
< form runat = " server " >
        
      
< h3 > GridView PagerTemplate Example </ h3 >

      
< asp:gridview id = " CustomersGridView "  
        datasourceid
= " CustomersSqlDataSource "    
        autogeneratecolumns
= " true "
        allowpaging
= " true "
        ondatabound
= " CustomersGridView_DataBound "   
        runat
= " server " >
              
        
< pagerstyle forecolor = " Blue "
          backcolor
= " LightBlue " />
              
        
< pagertemplate >
          
          
< table width = " 100% " >                     
            
< tr >                         
              
< td width = " 70% " >
                          
                
< asp:label id = " MessageLabel "
                  forecolor
= " Blue "
                  text
= " Select a page: "  
                  runat
= " server " />
                
< asp:dropdownlist id = " PageDropDownList "
                  autopostback
= " true "
                  onselectedindexchanged
= " PageDropDownList_SelectedIndexChanged "  
                  runat
= " server " />
                      
              
</ td >    
                      
              
< td width = " 70% "  align = " right " >
                      
                
< asp:label id = " CurrentPageLabel "
                  forecolor
= " Blue "
                  runat
= " server " />
                      
              
</ td >
                                            
            
</ tr >                     
          
</ table >
          
        
</ pagertemplate >  
          
      
</ asp:gridview >
            
      
<!--  This example uses Microsoft SQL Server and connects   -->
      
<!--  to the Northwind sample database. Use an ASP.NET      -->
      
<!--  expression to retrieve the connection  string  value    -->
      
<!--  from the Web.config file.                             -->
      
< asp:sqldatasource id = " CustomersSqlDataSource "   
        selectcommand
= " Select [CustomerID], [CompanyName], [Address], [City], [PostalCode], [Country] From [Customers] "
        connectionstring
= " <%$ ConnectionStrings:NorthWindConnectionString%> "
        runat
= " server " >
      
</ asp:sqldatasource >
            
    
</ form >
  
</ body >
</ html >

http://chatgpt.dhexx.cn/article/IUeTIrmU.shtml

相关文章

ViewPager的PagerAdapter中的notifyDataSetChanged更新数据总结

最近在工作中遇到了一个问题&#xff0c;就是在viewpager中调用pageradapter.notifydatasetchanged方法&#xff0c;好像没有任何效果&#xff0c;相应的view也没有更新数据&#xff0c;根据官方API是这样解释的&#xff1a;大概是说明Adapter会自动管辖ViewPager每一页(Item)的…

GridView1_PageIndexChanging 分页

//这里点击页面会报错所以要写这个 然后从新刷新一下 可以调一下属性什么的 this.GridView1.PageIndex e.NewPageIndex;jiazai(); c#后台写弹窗 跳转 Response.Write("<script>alert(修改成功);window.location.hrefhttp://localhost:65390/%E6%88%BF%E5%B1…

ViewPager控件之PagerAdapter适配器

一、ViewPager的基本用法 1、简介 ViewPager可以实现多个界面的左右滑动。ViewPager最典型的应用场景主要包 括引导页导航&#xff0c;轮转广告和页面菜单。 ViewPager最早出自4.0版本,为了兼容低版本安卓设备&#xff0c;谷歌官方给我们提供了 一个的软件包android.support.v4…

ViewPager onPageChangeListener总结

android ViewPager滑动事件讲解 今天在做项目的时候&#xff0c;由于要处理viewPager页面滑动的事件&#xff0c;所以对其进行了一个小小的研究&#xff1a; 首先ViewPager在处理滑动事件的时候要用到OnPageChangeListener OnPageChangeListener这个接口需要实现三个方法&am…

ViewPager onPageChangeListener总结

android ViewPager滑动事件讲解 今天在做项目的时候&#xff0c;由于要处理viewPager页面滑动的事件&#xff0c;所以对其进行了一个小小的研究&#xff1a; 首先ViewPager在处理滑动事件的时候要用到OnPageChangeListener OnPageChangeListener这个接口需要实现三个方法&#…

iscsi命令

iscsi客户端命令 iscsiadm 1.发现target设备 iscsiadm -m discovery -t sendtargets -p 10.12.22.61 疑问&#xff1a;10.12.22.60&#xff1a;3260&#xff0c;1 1表示什么意思(表示portal group tag,参考补充资料1)&#xff0c;此外&#xff0c;为什么连同ip为60的信息…

iSCSI 协议

iSCSI 协议 iSCSI协议结构 如同任何一个协议一样&#xff0c;iSCSI也有一个清晰的层次结构&#xff0c;根据OSI模型&#xff0c;iSCSI的协议栈自顶向下一共可以分为五层&#xff0c;如图所示&#xff1a; SCSI层&#xff1a;根据应用发出的请求建立SCSI CDB(命令描述块)&…

Linux与ISCSI

ISCSI&#xff08;Internet Small Computer System Interface&#xff09;:Internet 小型计算机系统接口&#xff0c;是一个基于 TCP/IP 的协 议&#xff0c;主要用于通过 IP 网络仿真 SCSI&#xff0c;从而为远程块存储设备提供数据传输和管理。说白了&#xff0c;就是通过 网…

ISCSI服务

Internet Small Computer System Interface:Internet 小型计算机系统接口&#xff0c;是一个基于 TCP/IP 的协 议&#xff0c;主要用于通过 IP 网络仿真 SCSI&#xff0c;从而为远程块存储设备提供数据传输和管理。说白了&#xff0c;就是通过 网络由专门的服务器提供存储管理&…

iSCSI 网络磁盘共享

17.1 iSCSI技术介绍 iSCSI技术实现了物理硬盘设备与TCP/TP网络传输协议的相互结合&#xff0c;使得用户可以通过互联网方便的获取到远程机房提供的共享存储资源 硬盘是计算机硬件设备中重要的组成部分之一&#xff0c;存储设备的IO读写速度快慢也直接影响着服务器整体性能的高…

ISCSI的部署与安装

iSCSI&#xff08;Internet Small Computer System Interface&#xff0c;Internet小型计算机系统接口&#xff09;是一种由IBM公司研究开发的IP SAN技术。 该技术是将现有SCSI接口与以太网络(Ethernet)技术结合&#xff0c;基于 TCP/IP的协议连接iSCSI服务端&#xff08;Targe…

SCSI协议与iSCSI协议

文章目录 1.SCSI协议2.iSCSI协议3.IO--SCSI错误处理机制 1.SCSI协议 SCSI的起源 SCSI出现的原因主要是因为原来的IDE接口的硬盘转速太慢&#xff0c;传输速率太低&#xff0c;因此高速的SCSI硬盘出现。其实SCSI并不是专为硬盘设计的&#xff0c;实际上它是一种总线型接口。由…

ISCSI详解(三)——ISCSI原理和架构

今天继续给大家介绍Linux运维相关知识&#xff0c;本文主要内容是ISCSI基础知识。 一、ISCSI架构 ISCSI的架构主要有以下两种&#xff1a; 1、控制器架构 在控制器架构下&#xff0c;ISCSI使用专门的数据传输芯片&#xff0c;专门的RAID数据校验芯片、高性能的cache缓存以及专…

iscsi服务器搭建

iscsi搭建 ISCSI服务介绍服务器配置&#xff08;IP:192.168.155.28&#xff09;客户端配置Linux&#xff08;IP:192.168.155.30&#xff09;Windows配置&#xff08;192.168.155.200&#xff09; ISCSI服务介绍 全称&#xff1a;Internet Small Computer System Interface——…

Windows iSCSI

iSCSI 题目一、安装iSCSI并创建存储位置二、配置iSCSI三、DC1连接iSCSI四、创建盘提示:若需要问题欢迎私聊‘ 题目 iSCSI 磁盘存储在D:\ISCSIDATA 中; iSCSI 磁盘提供给DC1 使用,磁盘容量500 G,启用chap 验证; DC1 上连接成功后,把磁盘格式化为NTFS 格式并挂载到卷标D …

【基于CentOS 7 的iscsi服务】

目录 一、概述 1.简述 2.作用 3. iscsi 4.相关名称 二、使用步骤 - 构建iscsi服务 1.使用targetcli工具进入到iscsi服务器端管理界面 2.实现步骤 2.1 服务器端 2.2 客户端 2.2.1 安装软件 2.2.2 在认证文件中生成iqn编号 2.2.3 开启客户端服务 2.2.4 查找可用的i…

ISCSI服务器搭建与配置

ISCSI服务简介 ISCSI简介&#xff1a; iSCSI( Internet Small Computer System Interface 互联网小型计算机系统接口) 技术是一种新存储技术&#xff0c;该技术是将现有的SCSI接口与以太网技术相结合&#xff0c;使服务器可与使用IP网络的存储装置互相交换资料。 iscsi 结构…

SCSI/ISCSI协议

SCSI即小型计算机接口&#xff08;Small Computer System Interface&#xff09;&#xff0c;指的是一个庞大协议体系&#xff0c;到目前为止经历了SCSI-1/SCSI-2/SCSI-3变迁。 SCSI协议定义了一套不同设备&#xff08;磁盘&#xff0c;磁带&#xff0c;处理器&#xff0c;光设…

iSCSI协议简介

本文综合了几篇参考文献的内容&#xff0c;做了删减与重组&#xff0c;但严格来说&#xff0c;不算原创。 笔者笔记如下&#xff1a; iSCSI initiator和target的核心功能都在内核中&#xff0c;无须人工干预&#xff1b;而要人工干预的大约是这么几件事&#xff1a; 1. 建立…

【存储】SCSI、iSCSI协议详解及对比

作 者&#xff1a; NGDCN 原文链接&#xff1a;【存储】SCSI、iSCSI协议详解及对比 - NGDCN 版 权&#xff1a; 本文由 NGDCN 于2022-11-11原创发布在 NGDCN&#xff0c;未经许可&#xff0c;禁止转载。 SCSI SCSI是小型计算机系统接口&#xff08;Small Compu…