Asp.net(c#)分页没有任何控制

时间:2011-10-22 05:41:57

标签: c# asp.net paging

我是新手,也是asp.net(C#)的新手。 我对GridView Control的绑定知之甚少。 但现在我面临一些巨大的问题。 我的一些数据被重复,我用代码隐藏控制它们。将我的代码放在变量中,附加到div,而不是GridView。 我也想要分页。

有人可以帮忙吗?问我你们是否需要更具体的东西。 我是初学者,所以我不知道要提供什么代码。

以下是概述:
医生有很多指定的地方 指定的地方有几天 好几天有好几次......

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

1 个答案:

答案 0 :(得分:0)

您可以使用cursorsRequest.QueryString来实现分页,而无需使用ontrol。

示例:如果您的网页网址类似于http://localhost/MyApp/DoctorsList.aspx 然后,当您想要查看接下来的10条记录时,只需将网址更改为http://localhost/MyApp/DoctorsList.aspx?page=2

在使用int pageNumber = Convert.ToInt32(Request.QueryString["page"])后面的代码中获取请求的页面,然后使用数据库游标根据pageNumber值获取特定记录,然后使用问题中提供的代码重建表。简而言之,我所说的是,不是获取所有医生列表,而是使用光标获得n位医生,然后使用Request.QueryString浏览剩余的列表。

但正如Hassan Mokdad在评论中所说,如果你尝试使用网格视图会更好