在asp.net中没有数据库进行分页 [英] Paging without database in asp.net

查看:62
本文介绍了在asp.net中没有数据库进行分页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hello Friends,我正在尝试在我的网站上实现分页功能,以便网页上只显示4个由管理员编写的博客。但问题是我没有数据库,所以

我必须使用文本文件,因为管理员在文本文件上写博客以将其上传到网站上。请帮我这样做。

先谢谢。

Akhilesh Pathak

Hello Friends,I am trying to implement paging functionality in my website so that only 4 blogs written by Admin may be shown on the web page.But the problem is that I have no database, so
I have to do it with the text files because Admin writes blogs on text file to upload it on the site.Please help me to do this.
Thanks in Advance.
Akhilesh Pathak

推荐答案

分页过程需要基于目录中的文件来实现。以下方法将根据特定目录中的pageIndex返回3(pagesize)FileInfo对象。

Paging process need to implement based on files in a directory. The following method will return 3(pagesize) FileInfo objects based on pageIndex from a specific directory.
private IList<FileInfo> GetFiles(string directory, int pageIndex)
{
    var fileInfoList = new List<FileInfo>();
    int pageSize = 3;//Assume that page size is 3
    string[] fileFullNames = Directory.GetFiles(directory);

    int start =  pageIndex * pageSize ;
    int loopCounter = 0;
    for (int index = start; index < fileFullNames.Count(); index++)
    {
        fileInfoList.Add(new FileInfo(fileFullNames[index]));
        loopCounter++;
        if (loopCounter == pageSize)
            break;
    }
    return fileInfoList;
}





客户代码如下



Client code as follows

IList<FileInfo> page1 = GetFiles("D:\\FileList", 0);
IList<FileInfo> page2 = GetFiles("D:\\FileList", 1);
IList<FileInfo> page3 = GetFiles("D:\\FileList", 2);
IList<FileInfo> page4 = GetFiles("D:\\FileList", 3);



根据您使用的控制,您的客户端代码可能会有所不同。像gridview /客户端表等只是你调整这些代码。我在这里展示如何使用不同的页面索引调用该调页方法3次;我通过创建目录来测试它并在那里保存10个不同的文件并逐页选择文件。


Your client code may be differ based on control you use for. Like gridview/client side table etc just you adjust these code. I show here how to call that paging method 3 times with different page index; I test it with create a directory and save 10 different files there and pick files page by page.


这篇关于在asp.net中没有数据库进行分页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆