Tuesday, March 17, 2015

ListView implement paging with css



The ListView display data in the database and implement paging



Abstract: ListView class with user-defined template to display the value of the data source. ListView control enables users to select, sort, delete, edit and insert records.
Code list:
  1. <%@ Page language="C#" %>  
  2.     "  
  3. <html  >  
  4.   <head id="Head1" runat="server">  
  5.     <title>ListView Example</title>  
  6.     <style type="text/css">  
  7.       .CurrentPage   
  8.       {  
  9.           padding: 2px 6px;  
  10.           border: solid 1px #ddd;   
  11.           background: #2E8B57;  
  12.           color:White;  
  13.       }  
  14.       .PrevNext,.PageNumber  
  15.       {  
  16.           padding: 2px 6px;  
  17.           border: solid 1px #ddd;  
  18.           text-decoration: none;  
  19.           color: #2E8B57;  
  20.       }  
  21.       .PageNumber:hover, .PrevNext:hover  
  22.       {  
  23.           background-color: #FFA500;  
  24.           color: White;  
  25.       }  
  26.       
  27.     </style>  
  28.   </head>  
  29.   <body>  
  30.     <form id="form1" runat="server">  
  31.       <h3>ListView Example</h3>  
  32.   
  33.       <asp:ListView ID="VendorsListView"  
  34.         DataSourceID="LinqDataSource1"  
  35.         DataKeyNames="CustomerID"  
  36.         runat="server">  
  37.         <LayoutTemplate>  
  38.         <%--? table?div  span ?? ItemTemplate    
  39.             GroupTemplate ?  DataPager ?  
  40.         --%>  
  41.           <table cellpadding="2" width="640px" border="1" ID="tbl1" runat="server">  
  42.             <tr id="Tr1" runat="server" style="background-color: #98FB98">  
  43.               <th id="Th1" runat="server">CustomerID</th>  
  44.               <th id="Th2" runat="server">NameStyle</th>  
  45.               <th id="Th3" runat="server">Title</th>  
  46.             </tr>  
  47.             <%-- ListView“VendorsListView”? ID “itemPlaceholder”?  
  48.              runat="server"--%>  
  49.             <tr runat="server" id="itemPlaceholder" />  
  50.           </table>  
  51.            <%--DataPager : IPageableItemContainer ? ListView ??--%>  
  52.           <asp:DataPager ID="DataPager1" runat="server">  
  53.              <%--  DataPagerField ? DataPager ?--%>  
  54.             <Fields>  
  55.            <%-- NumericPagerField  DataPager ?--%>  
  56.               <asp:NumericPagerField   
  57.               PreviousPageText="< Prev"  
  58.               NextPageText="Next >"  
  59.               ButtonCount="10"  
  60.               NextPreviousButtonCssClass="PrevNext"  
  61.               CurrentPageLabelCssClass="CurrentPage"  
  62.               NumericButtonCssClass="PageNumber" />  
  63.             </Fields>  
  64.           </asp:DataPager>  
  65.         </LayoutTemplate>  
  66.         <%--?--%>  
  67.         <ItemTemplate>  
  68.           <tr id="Tr2" runat="server">  
  69.             <td>  
  70.               <asp:Label ID="VendorIDLabel" runat="server" Text='<%# Eval("CustomerID") %>' />  
  71.             </td>  
  72.             <td>  
  73.               <asp:Label ID="AccountNumberLabel" runat="server" Text='<%# Eval("NameStyle") %>' />  
  74.             </td>  
  75.             <td>  
  76.               <asp:Label ID="NameLabel" runat="server" Text='<%# Eval("Title") %>' /></td>  
  77.           </tr>  
  78.         </ItemTemplate>  
  79.       </asp:ListView>  
  80.     <asp:LinqDataSource ID="LinqDataSource1" runat="server"   
  81.               ContextTypeName="WebApplication5.DataClasses1DataContext"   
  82.               Select="new (CustomerID, NameStyle, Title, FirstName)" TableName="Customer">  
  83.     </asp:LinqDataSource>      
  84.   
  85.     </form>  
  86.   </body>  
  87. </html>  

0 comments:

Popular Posts

Recent Posts

Unordered List

Text Widget

Blog Archive