Step by step. Net three-layer architecture Analysis 8. UI design (the design of the gridview and its paging)

Source: Internet
Author: User

This time, we designed the employee operation list custom. aspx and department operation list departmant. aspx, and how to design the pagination function of the gridview.

Call the BLL design method to obtain the list of data, convert it to pageddatasource, and set the pageddatasource attribute to implement the paging function.

First look at the design of custom. aspx:

<Div style = "text-align: Center"> <asp: gridview id = "gvcustom" datakeynames = "ID" onrowdeleting = "gridview_rowdeleting" runat = "server" cellpadding = "4" forecolor = "#333333" gridlines = "NONE" horizontalalign =" center "width =" 98% "cellspacing =" 1 "autogeneratecolumns =" false "> <footerstyle backcolor =" #507cd1 "font-bold =" true "forecolor =" white "/> <rowstyle backcolor = "# eff3fb" horizontalalign = "center"/> <editr Owstyle backcolor = "# 2461bf" font-italic = "true" horizontalalign = "center" verticalalign = "Middle"/> <selectedrowstyle backcolor = "# d1ddf1" font-bold = "true ""forecolor =" #333333 "/> <pagerstyle backcolor =" # 2461bf "forecolor =" white "horizontalalign =" center "/> 

Now let's take a look at the design of custom. aspx. CS:

Note:

 
Using BLL; using model;

Then:

Public partial class custom: pagebase {protected void page_load (Object sender, eventargs e) {If (! Page. ispostback) {// verify the permission isadmin (); bindata () ;}/// <summary> // bind data /// </Summary> private void bindata () {customsystem = new customsystem (); List <custom> customlist = new list <custom> (); // call The bll method to obtain the list customlist = customsystem. getcustom (); int curpage = convert. toint32 (this. labpage. text); // design pageddatasource PS = new pageddatasource (); PS. datasource = customlist; PS. allowpaging = true; // set the number of pages ps. pagesize = 16; PS. currentpageindex = curpage-1; this. lnkbtnup. enabled = true; this. lnkbtnnext. enabled = true; this. lnkbtnback. enabled = true; this. lnkbtnone. enabled = true; If (curpage = 1) {This. lnkbtnone. enabled = false; this. lnkbtnup. enabled = false;} If (curpage = ps. pagecount) {This. lnkbtnnext. enabled = false; this. lnkbtnback. enabled = false;} This. labbackpage. TEXT = convert. tostring (PS. pagecount); // bind the data source gvcustom. datasource = Ps; gvcustom. databind ();} /// <summary> /// delete a piece of data /// </Summary> /// <Param name = "sender"> </param> /// <Param name = "E"> </param> protected void gridview_rowdeleting (Object sender, gridviewdeleteeventargs e) {int nid = int32.parse (gvcustom. datakeys [E. rowindex]. value. tostring (); customsystem = new customsystem (); customsystem. deletecustom (NID); bindata ();} /// <summary> /// page 1 /// </Summary> /// <Param name = "sender"> </param> /// <Param name = "E"> </param> protected void lnkbtnone_click (Object sender, eventargs e) {This. labpage. TEXT = "1"; bindata ();} /// <summary> // Previous Page // </Summary> /// <Param name = "sender"> </param> /// <Param name =" E "> </param> protected void lnkbtnup_click (Object sender, eventargs e) {This. labpage. TEXT = convert. tostring (convert. toint32 (this. labpage. text)-1); bindata ();} /// <summary> /// next page // </Summary> /// <Param name = "sender"> </param> /// <Param name =" E "> </param> protected void lnkbtnnext_click (Object sender, eventargs e) {This. labpage. TEXT = convert. tostring (convert. toint32 (this. labpage. text) + 1); bindata ();} /// <summary> /// last page /// </Summary> /// <Param name = "sender"> </param> /// <Param name = "E"> </param> protected void lnkbtnback_click (Object sender, eventargs e) {This. labpage. TEXT = This. labbackpage. text; bindata ();} /// <summary> /// jump to the add page /// </Summary> /// <Param name = "sender"> </param> /// <Param name = "E"> </param> protected void btnadduser_click (Object sender, eventargs e) {response. redirect ("register. aspx ");}}
Let's take a look at the design of pipeline mant. aspx:
<Div style = "text-align: Center"> <asp: gridview id = "gridview1" runat = "server" autogeneratecolumns = "false" cellpadding = "4" cellspacing = "1" datakeynames = "ID" forecolor = "#333333" gridlines =" none "horizontalalign =" center "onrowdeleting =" gridview_rowdeleting "width =" 98% "> <footerstyle backcolor =" #507cd1 "font-bold =" true "forecolor =" white "/> <rowstyle backcolor = "# eff3fb" horizontalalign = "center"/> <Edit Rowstyle backcolor = "# 2461bf" font-italic = "true" horizontalalign = "center" verticalalign = "Middle"/> <selectedrowstyle backcolor = "# d1ddf1" font-bold = "true ""forecolor =" #333333 "/> <pagerstyle backcolor =" # 2461bf "forecolor =" white "horizontalalign =" center "/> 

Then let's look at the design of mongomant. aspx. CS:

Also, add:

 
Using BLL; using model;

Then:

Public partial class upload mant: pagebase {protected void page_load (Object sender, eventargs e) {If (! Page. ispostback) {// verify the permission isadmin (); bindata () ;}/// <summary> // bind data /// </Summary> private void bindata () {departmentsystem = new departmentsystem (); List <Department> departmentlist = new list <Department> (); // call The bll method to obtain the list departmentlist = departmentsystem. getdepartment (); int curpage = convert. toint32 (this. labpage. text); // design pageddatasource PS = new pageddatasource (); PS. datasource = departmentlist; PS. allowpaging = true; // set the number of pages ps. pagesize = 16; PS. currentpageindex = curpage-1; this. lnkbtnup. enabled = true; this. lnkbtnnext. enabled = true; this. lnkbtnback. enabled = true; this. lnkbtnone. enabled = true; If (curpage = 1) {This. lnkbtnone. enabled = false; this. lnkbtnup. enabled = false;} If (curpage = ps. pagecount) {This. lnkbtnnext. enabled = false; this. lnkbtnback. enabled = false;} This. labbackpage. TEXT = convert. tostring (PS. pagecount); // bind the data source gridview1.datasource = Ps; gridview1.databind ();} /// <summary> /// delete a piece of data /// </Summary> /// <Param name = "sender"> </param> /// <Param name = "E"> </param> protected void gridview_rowdeleting (Object sender, gridviewdeleteeventargs e) {int nid = int32.parse (gridview1.datakeys [E. rowindex]. value. tostring (); departmentsystem = new departmentsystem (); departmentsystem. deletedepart (NID); bindata ();} /// <summary> /// page 1 /// </Summary> /// <Param name = "sender"> </param> /// <Param name = "E"> </param> protected void lnkbtnone_click (Object sender, eventargs e) {This. labpage. TEXT = "1"; bindata ();} /// <summary> // Previous Page // </Summary> /// <Param name = "sender"> </param> /// <Param name =" E "> </param> protected void lnkbtnup_click (Object sender, eventargs e) {This. labpage. TEXT = convert. tostring (convert. toint32 (this. labpage. text)-1); bindata ();} /// <summary> /// next page // </Summary> /// <Param name = "sender"> </param> /// <Param name =" E "> </param> protected void lnkbtnnext_click (Object sender, eventargs e) {This. labpage. TEXT = convert. tostring (convert. toint32 (this. labpage. text) + 1); bindata ();} /// <summary> /// last page /// </Summary> /// <Param name = "sender"> </param> /// <Param name = "E"> </param> protected void lnkbtnback_click (Object sender, eventargs e) {This. labpage. TEXT = This. labbackpage. text; bindata ();} /// <summary> /// jump to the add page /// </Summary> /// <Param name = "sender"> </param> /// <Param name = "E"> </param> protected void btnadddepartment_click (Object sender, eventargs e) {response. redirect ("adddepart. aspx ");}}
Here, a simple three-tier architecture application is designed, and the permission design may be a little weak. I will explain the permission design in another day, I would like to thank you for your constant attention and support, and for your contribution.

Next time, I will navigate this series and publish the source code. Welcome to continue.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.