简体   繁体   English

ASP.NET(C#)分页没有任何控制

[英]Asp.net(c#) paging without any control

I am new and a novice to asp.net(C#). 我是新手,还是asp.net(C#)的新手。 I know little about binding to GridView Control. 我对绑定到GridView控件知之甚少。 But now I face some huge problems. 但是现在我面临一些巨大的问题。 Some of my data are repeated and I control them with code-behind. 我的一些数据是重复的,我使用代码隐藏控制它们。 Put my code in variable, append to div, not in GridView. 将我的代码放在变量中,追加到div,而不是GridView中。 I also want paging for this. 我也想为此进行分页。

Can anybody help? 有人可以帮忙吗? Ask me if you guys need something more specific. 问我你们是否需要更具体的东西。 I am a beginner, so I don't know what code to provide. 我是一个初学者,所以我不知道要提供什么代码。

Here's the overview: 这里是概述:
Doctors have many appointed place 医生有很多任命的地方
appointed places have several day 指定的地方有几天
several days have several times-shift ... 几天有几次班次...

public void BindList(int start, int pagesize)
{
    lblPageIndex.Text = page.ToString();
    roles = DoctorBLL.GetAllDoctor(page, recordPerPage);
    List<int> rIDs = ((from r in roles select r.doctorID).Distinct()).ToList();
    foreach(int rID in rIDs)
    {
        doctorList.InnerHtml += "<table width='100%' border=1 cellspacing=0 style='border-collapse:collapse;margin-top:10px;'><tr>";
        List<DoctorEntity> dlist = roles.Where(role => role.doctorID == rID).ToList();
        if (dlist.Count > 0)
        {
            doctorList.InnerHtml += "<td>";
            doctorList.InnerHtml += "<h2>" + dlist.First().title + "</h2>";
            doctorList.InnerHtml += "<h3>" + dlist.First().name + "</h3>";
            doctorList.InnerHtml += "</td>";
            doctorList.InnerHtml += "<td>";
            doctorList.InnerHtml += dlist.First().qualification;
            doctorList.InnerHtml += "</td>";
            doctorList.InnerHtml += "</tr>";
            doctorList.InnerHtml += "<tr>";
            doctorList.InnerHtml += "<td colspan='3'>";
        }
        List<int> dirIDS = ((from r in dlist select r.directoryID).Distinct()).ToList();

        foreach (int dirid in dirIDS)
        {
            doctorList.InnerHtml += "<ul style='width:200px;float:left;list-style:none;'>";
            List<DoctorEntity> dirlist = dlist.Where(dt => dt.directoryID == dirid).ToList();
            if (dirlist.Count > 0)
            {
                doctorList.InnerHtml += "   <li><h4>" + dlist.First().directoryName + "</h4></li>";
            }
            foreach (DoctorEntity dir in dirlist)
            {
                doctorList.InnerHtml += "<li>" + dir.dayStr + " ( " + dir.startTime + " : " + dir.endTime + " ) </li>";
            }

            doctorList.InnerHtml += "</ul>";
        }
        doctorList.InnerHtml += "</td>";
        doctorList.InnerHtml += "</tr>";
        doctorList.InnerHtml += "</table>";
    }
    foreach (DoctorEntity entity in roles)
    {
        recordCount = entity.recordCount;
        break;
    }
    int flag = recordCount % recordPerPage;
    if (flag != 0)
    {
        flag = (recordCount / recordPerPage) + 1;
    }
    else
    {
        flag = recordCount / recordPerPage;
    }

    lblTotalPage.Text = flag.ToString();
    lblTotal.Text = recordCount.ToString();

    doctorList.DataBind();
}
#endregion

You can use cursors and Request.QueryString to achieve paging without using ontrols. 您可以使用游标Request.QueryString来实现分页,而无需使用ontrol。

Example : If your page url is something like http://localhost/MyApp/DoctorsList.aspx then when you want to see the next 10 records just change the url to http://localhost/MyApp/DoctorsList.aspx?page=2 示例:如果您的页面URL类似于http://localhost/MyApp/DoctorsList.aspx,那么当您要查看接下来的10条记录时,只需将URL更改为http://localhost/MyApp/DoctorsList.aspx?page = 2

in you code behind use int pageNumber = Convert.ToInt32(Request.QueryString["page"]) to get the requested page, then use a database cursor to fetch the particular records based on the pageNumber value and then rebuild the table with code provided in the question. 在您后面的代码中,使用int pageNumber = Convert.ToInt32(Request.QueryString["page"])获取请求的页面,然后使用数据库游标根据pageNumber值获取特定记录,然后使用提供的代码重建表在这个问题上。 In short what i am saying is that instead of getting all the list of doctors, get n number of doctors using a cursor, and then use the Request.QueryString to browse through the remaining list. 简而言之,我要说的是,不是获取所有医生列表,而是使用光标获取n个医生,然后使用Request.QueryString浏览其余列表。

But as Hassan Mokdad said in his comment, it would be better if you try with the grid view 但是正如哈桑·莫克达(Hassan Mokdad)在评论中说的那样,如果尝试使用网格视图会更好

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM