Phân trang dữ liệu dùng CollectionPager

Phân trang dữ liệu dùng CollectionPager

Khi thiết kế một website, công việc phân dữ liệu thành nhiều trang hiển thị là bắt buộc khi dữ liệu lớn. Trong các control của Visual Studio thì Gridview đã có sẵn chức năng phân trang nhưng còn nhiều hạn chế. WEBXAULA sẽ giới thiệu với các bạn cách phân trang dùng CollectionPager để các bạn có nhiều lựa chọn hơn trong công việc của mình

Phân trang dữ liệu dùng CollectionPager

Trong bài viết này, tôi sẽ minh hoạ cách phân trang cho Datalist, đối với Gridview và Repeater bạn làm tương tự. Đầu tiên bạn cần download thư viện CollectionPager tại đây.

Bạn add file .dll vào thư mục BIN của website. Sau đó khai báo trong trang mà bạn muốn sử dụng CollectioPager

<%@ Register assembly="CollectionPager" namespace="SiteUtils" tagprefix="cc1" %>

Trong code html tôi tạo một datalist minh hoạ như sau:

<asp:DataList ID="DS_Phim" runat="server">
        <ItemTemplate>
            <img src="hinh/sanpham/" + <%# Eval("hinh") %> />
            <br /><br />
            <strong><%# Eval("sanphamName") %></strong>
        </ItemTemplate>
        </asp:DataList>

Bạn có thể tuỳ biến các trường dữ liệu và thiết kế lại cho thích hợp với website. Sau đó bạn tạo một collectioPager như sau:

<cc1:CollectionPager ID="CollectionPager1"
    FirstText="Đầu"
    BackText="« Trước &amp;nbsp;"
    LabelText=""
    LastText="Cuối"
    NextText="&amp;nbsp; Sau  »"
    ShowFirstLast="True"
    SliderSize="5" PagingMode="PostBack"
    runat="server" BackNextLinkSeparator="" BackNextLocation="Split"
    PageNumbersDisplay="Numbers" ResultsLocation="None"
    BackNextDisplay="Buttons">
</cc1:CollectionPager>

Code C# bạn viết như sau:

string pSQL = "SELECT * FROM SANPHAM";
            clsConnection pBang = new clsConnection(pSQL);
 
CollectionPager1.PageSize = 10; //Số sản phẩm hiển thị trên một trang
            CollectionPager1.DataSource = pBang.DefaultView;
            CollectionPager1.BindToControl = DS_Phim;
            DS_Phim.DataSource = CollectionPager1.DataSourcePaged;
 
 
Bạn thấy bài viết này như thế nào?: 
No votes yet
Ảnh của Tommy Tran

Tommy owner Express Magazine

Drupal Developer having 9+ year experience, implementation and having strong knowledge of technical specifications, workflow development. Ability to perform effectively and efficiently in team and individually. Always enthusiastic and interseted to study new technologies

  • Skype ID: tthanhthuy

Advertisement

 

jobsora

Dich vu khu trung tphcm

Dich vu diet chuot tphcm

Dich vu diet con trung

Quảng Cáo Bài Viết

 
Drupal 7

Giới thiệu về công nghệ mã nguồn mở Drupal 7

Drupal đã phát triển thành một nền tảng được coi là mạnh mẽ nhất để xây dựng các trang web xã hội và ngữ nghĩa, đồng thời trở nên dễ sử dụng hơn bao giờ hết.

Cấu hình để debugging Drush commands với Xdebug và PHPStorm

Cấu hình để debugging Drush commands với Xdebug và PHPStorm

Oftentimes, I run into issues with drush commands that needed more debugging power than dpm() provides. In search for a way to debug PHP scripts from the CLI, or drush commands more specifically,

Using CSS3 transformations and transitions to spice up your web design!

Using CSS3 transformations and transitions to spice up your web design!

Quite often web designers have to come up with a design for a page that needs to be easy to use, without being overly boring. Keeping a minimal and clean design that gives content the prominence it needs

Công ty diệt chuột T&C

 

Diet con trung