当前位置:网站首页>An improvement of the code in the article "Walkthrough: creating paged data access using web form pages" in MSDN
An improvement of the code in the article "Walkthrough: creating paged data access using web form pages" in MSDN
2022-06-21 07:41:00 【Shifeng 13】
If you install it MSDN, Learning to use .NET Make a website , You may encounter such a sample document :
Visual Basic and Visual C# Concept
rehearse : Use Web Form pages create paged data access
ms-help://MS.VSCC.2003/MS.MSDNQTR.2003FEB.2052/vbcon/html/vbwlkwalkthroughdisplayingdatainlistboxesonwebformspage.htm
This article describes how to create a data list with custom paging , The feature is that only the corresponding number of pieces of data are extracted from the database each time , This method is very good for the list display of large data tables , It is better than another scheme that takes out all the data at once and then caches the pages .
When I adopted this scheme, I found several small BUG, as follows :
- stay “ Go to the next page ” In the program code of ,
private void btnNext_Click(object sender, System.EventArgs e)
{
// Get the page number of the page most recently displayed
CurrentPage = (int)(ViewState["CurrentPage"]);
CurrentPage++;
// Gets the id on current page
string lastid = DataGrid1.Items[9].Cells[0].Text;
cmdNext.Parameters["@customerid"].Value = lastid;
FillGrid(cmdNext);
}
The scarlet letter should read “string lastid = DataGrid1.Items[DataGrid1.PageSize-1].Cells[0].Text;”, Otherwise, when the number of (PageSize) Not the default 10 Stripe time , May cause errors . - In addition to “ Show data in Grid ” In this part , You will see that some codes judge when the number of entries taken on this page is less than PageSize when , That is, when it is regarded as the last page of the data table , Set up “ The next page ” Button failure , You should also add the judgment that the current page is 0 Or less than 0 when , That is, when it is regarded as the first page of the data sheet , Set up “ The previous page ” Button failure code , as follows :
if (DataGrid1.Items.Count < DataGrid1.PageSize)
{
btnNext.Enabled = false;
}
if (CurrentPage <= 0)
{
btnPrevious.Enabled = false;
} - Steps in 2 At the same time , stay btnNext_Click This sentence should also be added to the method “this.btnPrevious.Enabled = true;”, So that after page change “ The previous page ” Button activated first , Then follow the steps 2 To judge whether the setting button is invalid .
- Add : A new problem has just been found in the inspection , When the number of entries on the last page is just the number of entries on the page ,“ The next page ” The button is still active , Click to make an error , Because there is no corresponding record to display . Therefore, the following supplementary amendments are made :( Pay attention to the red marking )
if(dr.HasRows==true)
{
DataGrid1.DataSource = dr;
DataGrid1.DataBind();
dr.Close();
sqlConnection1.Close();
ViewState["CurrentPage"] = CurrentPage;
ViewState[CurrentPage.ToString()] = DataGrid1.Items[0].Cells[0].Text;
if (DataGrid1.Items.Count < DataGrid1.PageSize)
{
btnNext.Enabled = false;
}
if (CurrentPage <= 0)
{
btnPrevious.Enabled = false;
}
}
else
{
btnNext.Enabled = false;
}
thus , After my test, such a paging list is more perfect , You can adapt to different page numbers .
边栏推荐
- Digital twin smart server: information security monitoring platform
- [telnet] telnet installation and configuration
- . Net 4.5 asynchronous programming pilot (async and await)
- How do I install the visual studio code editor?
- Type de contrôle qml: Drawer
- Rdkit | compound library based on murcko skeleton clustering
- Rdkit | fragment decomposition of drug molecules
- unity里现实摄像头运镜并LookAt到物体前方 基于Dotween
- mysql的安装路径如何查看
- 根因解析 | Kubernetes Pod状态异常九大场景盘点
猜你喜欢

MATLAB 三维图(非常规)

How to start wireless network service after win10 system installation

17 statistics and their sampling distribution statistics and distribution

Definition and declaration problems in stm32

22 parameter estimation - maximum likelihood estimation method

mysql如何关闭事务

How to write the statement of executing stored procedure in MySQL

Parameter estimation -- a general problem of parameter estimation

Kubernetes pod的生命周期

Horizontal slot, one line of code can directly convert the web page to PDF and save it (pdfkit)
随机推荐
Talk about MySQL's locking rule "hard hitting MySQL series 15"
AutoCAD - drawing units and drawing boundaries
2021-06-16 STM32F103 EXTI 中断识别 使用固件库
[regular expression daily skill] escape characters with special meanings in regular expressions
Why do smart cities need digital twins?
Postman publishing API documentation
app安全滲透測試詳細方法流程
. Net 4.5 asynchronous programming pilot (async and await)
Market trend report, technical innovation and market forecast of scaffold free 3D cell culture plate in China
根因解析 | Kubernetes Pod状态异常九大场景盘点
CUDA or FPGA for special purpose 3D graphics computations? [closed]
Enterprise level development and use POI stepping on pit inventory
Open up the connection between production and marketing and build a new digital supply chain of agricultural and sideline products
MATLAB快速入门
Ansa secondary development - external programs use socket to communicate with ansa
企业级开发使用POI踩坑盘点
RPA(影刀)无需写代码抓取某东的商品信息
App Safety Penetration Test detailed Method Flow
RDKit | 拓扑极性表面积(TPSA)
Research Report on market supply and demand and strategy of shuttleless loom industry in China