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

问题描述 投票:0回答:1

我是asp.net(C#)的新手。 我对绑定到 GridView 控件知之甚少。 但现在我面临一些巨大的问题。 我的一些数据是重复的,我用代码隐藏来控制它们。将我的代码放在变量中,附加到 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
c# asp.net pagination
1个回答
0
投票

您可以使用光标

Request.QueryString
来实现分页,而无需使用控件。

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

在后面的代码中,使用

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

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

© www.soinside.com 2019 - 2024. All rights reserved.