The Repeater control is a data-bound container control that generates a list of items and can use templates to define the layout of individual items on a Web page. When the page runs, the control repeats this layout for each item in the data source.
Working with templates using repeater controls
To use the Repeater control, you create a template that defines the layout of the control's content. A template can contain any combination of tags and controls. If no template is defined, or the template does not contain elements, the control does not appear on the page when the application is run.
ItemTemplate: Contains HTML elements and controls to be rendered once for each data item in the data source.
AlternatingItemTemplate: Formats alternating data items that contain HTML elements and controls to be rendered once for each data item in the data source. Typically, you can use this template to create different skins for alternating items, such as specifying a background color that differs from the color specified in ItemTemplate.
SeparatorTemplate: The delimiter is formatted (contains elements that are rendered between each item). )。
HeaderTemplate: Formats the header containing the text and controls that are rendered separately at the beginning of the list. )。
FooterTemplate: Formatting The footer (contains text and controls that are rendered separately at the end of the list). )。
The repeater pagination effect is as follows:
Front Code:
<body> <asp:repeater id= "Repeater1" runat= "Server" > <HeaderTemplate> <p style= "Background-color : #988c6e; width:400px;padding-top:5px;padding-bottom:5px;margin-left:30px;margin-top:30px;border-radius:5px; Color: #fff; font-weight:bold; " ><span style= "padding-left:30px;" > User name </span><span style= "padding-left:100px;" > Registration Time </span><span style= "padding-left:90px;" > Visits </span></p> <table style= "margin-left:30px;margin-top:30px;" > </HeaderTemplate> <ItemTemplate> <tr> <td style= "width:120px;text-align:left; padding-left:20px; " ><% #Eval ("Username")%></td> <td style= "width:170px;text-align:left; "><% #Eval (" Registrationtime ")%></td> <td style=" width:50px;text-align:left; "><% #Eval (" Accessamount ")%></td> </tr> <tr> <td colspan=" 3 "style=" border-bottom:1px I Nset #C0D9D9;p adding-top:7px; " ></td> </tr> </itemtemplate> <FooterTemplate> </table> </FooterTemplate> </asp:Repeater> <div style= "Margin-left : 50px; " > <div style= "margin:0 auto; margin-top:50px;border:1px solid #fff; font-size:16px;font-family: "Microsoft Yahei", "Song Body"; " > <a><div style= "border:1px solid #000; width:60px; Float:left; Margin:5px;text-align:center; " ><a style= "color: #000" > Total <asp:label runat = "server" id= "zong" > </asp:Label> page </a></div ></a> <a><div style= "border:1px solid #000; width:60px; Float:left;margin:5px;text-align:center; " ><a style= "color: #000" > <asp:label runat = "server" id= "Dangqian" > </asp:Label> page </a></ div></a> <a><div style= "border:1px solid #000; width:40px; Float:left;margin:5px;text-align:center; " > <a style= "color: #000" ><asp:hyperlink id= "First" runat= "Server" style= "color: #000" > Home </asp: Hyperlink></a></div></a> <a><div StylE= "border:1px solid #000; width:60px; Float:left;margin:5px;text-align:center; " ><a style= "color: #000" ><asp:hyperlink id= "Lnkprev" runat= "server" style= "color: #000" > Previous </asp: hyperlink></a></div></a> <a><div style= "border:1px solid #000; width:60px; Float:left;margin:5px;text-align:center; " ><a style= "color: #000" ><asp:hyperlink id= "Lnknext" runat= "server" style= "color: #000" > Next </asp: hyperlink></a></div></a> <a><div style= "border:1px solid #000; width:40px; Float:left;margin:5px;text-align:center; " > <a style= "color: #000" ><asp:hyperlink id= "End" runat= "server" style= "color: #000" > Last </asp: hyperlink></a></div></a> </div> </div> </body>
Background code:
protected void Page_Load (object sender, EventArgs e) {if (! Page.IsPostBack) {getusers (); }} private void Getusers () {list<users1> List = new Adminmanager (). Queryusers (); PagedDataSource pag = new PagedDataSource (); Pag. AllowPaging = true;//setting allows paging pag. PageSize = 10; Each page is displayed as a 3-line pag. DataSource = list; The template binds the data source Zong. Text = pag. Pagecount.tostring (); Displays the total number of pages int currentpage; The request page number is not set to NULL for the current page, otherwise the first page if (request.querystring["page"]! = null) {currentpage = Convert.ToInt32 (Request.querystrin g["page"]); } else {currentpage = 1; } if (request.querystring["PageSize"]! = null) {pag. PageSize = Convert.ToInt32 (request.querystring["PageSize"]); } else {pag. PageSize = 10; } pag. CurrentPageIndex = CurrentPage-1; The current page is cited as page number-1 Dangqian. Text = Currentpage.tostring (); The current page if (!pag. Isfirstpage) {//Request.currentexecutionfilepath for the current request virtual path Lnkprev.navigateurl = Request.currentexecutionfilepath + " ? Page= "+ convert.tostring (CurrentPage-1); }//If it is not the last page, set the next page by the parameter page to the current page +1, otherwise the connection if (!PAG) is not displayed. Islastpage) {//Request.currentexecutionfilepath for the current request virtual path Lnknext.navigateurl = Request.currentexecutionfilepath + "? Page= "+ convert.tostring (currentpage + 1); }//Home first. NAVIGATEURL = Request.currentexecutionfilepath + "? Page= "+ convert.tostring (1); End end. NAVIGATEURL = Request.currentexecutionfilepath + "? page=" + Pag. Pagecount.tostring (); if (Convert.ToInt32 (httpcontext.current.request["page"]) > Pag. PageCount) {first. NAVIGATEURL = Request.currentexecutionfilepath + "? Page= "+ convert.tostring (1); } this. Repeater1.datasource = Pag; This. Repeater1.databind (); }
If paging is not required, the following code can be executed:
protected void Page_Load (object sender, EventArgs e) {if (! Page.IsPostBack) {getusers ();}} private void Getusers () {list<users1> List = new Adminmanager (). Queryusers (); This. Repeater1.datasource = list; This. Repeater1.databind ();}
The above is the whole content of this article, I hope that the content of this article on everyone's study or work can bring some help, but also hope to support topic.alibabacloud.com!