2011-10-22 24 views
0

我是新手和asp.net(C#)的新手。 我對GridView控件的綁定知之甚少。 但現在我面臨一些巨大的問題。 我的一些數據是重複的,我用代碼隱藏來控制它們。將我的代碼放在變量中,附加到div,而不是在GridView中。 我也希望爲此分頁。Asp.net(c#)分頁沒有任何控制

任何人都可以幫忙嗎?問我,如果你們需要更具體的東西。 我是初學者,所以我不知道要提供什麼代碼。

這裏的概述:
醫生有很多的指定地點
指定地點有幾天
幾天有好幾次移...

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 
+3

這將是更簡單和直接的,如果你只是使用網格視圖,特別是對尋呼 –

+0

根據您的意見下面,向我們展示你無法工作的SQL(分組等),我們將修復SQL。 – Hogan

+0

SELECT \t \t \t \t d.id doctorid, \t \t \t \t d.name DNAME, \t \t \t \t d.title dtitle, \t \t \t \t d.qualification dqua, \t \t \t \t dt.id dtid, \t \t \t \t dt.name dtname, \t \t \t \t tt.day_id, \t \t \t \t tt.start_time, \t \t \t \t tt.end_time, \t \t \t \t ROW_NUMBER()OVER(ORDER BY d。ID DESC)AS [ROWNUMBER] \t \t \t FROM醫生d \t \t \t INNER JOIN time_table TT \t \t \t ON d.id = tt.doctor_id \t \t \t INNER JOIN目錄DT \t \t \t \t ON DT。 id = tt.directory_id \t \t \t ORDER BY d.id DESC \t \t \t END – Gabriel

回答

0

您可以使用cursorsRequest.QueryString來實現分頁沒有使用ontrols。

例如:如果你的頁面的網址是一樣的東西http://localhost/MyApp/DoctorsList.aspx 那麼當你想看看接下來的10條記錄只需更改網址http://localhost/MyApp/DoctorsList.aspx?page=2

使用int pageNumber = Convert.ToInt32(Request.QueryString["page"])獲得請求的頁面背後,你的代碼,然後用數據庫遊標以基於pageNumber值獲取特定記錄,然後使用問題中提供的代碼重建表。總之,我所說的是,不是讓所有的醫生列表,而是使用光標獲得n位醫生,然後使用Request.QueryString來瀏覽剩餘的列表。

但哈桑穆克達德在他的評論中說,如果你用網格視圖嘗試倒不如

+0

感謝您的評論 – Gabriel

+0

其實,我已經做了分頁傳遞查詢字符串在URL中的URL。哦,順便說一句,我使用存儲過程DAL BLL,因爲我正在開發項目。我想讓它變得更簡單。但在GridView中的問題是當我使用JOIN從數據庫提取數據(我必須)時,我得到了probs。就像當我提取有兩個指定位置的醫生時,那個醫生在視圖中出現兩次。那個指定的地方有兩天與那個醫生有關。指定的地方出現更多。等等等等。 – Gabriel

+0

我的朋友建議通過分開醫生和時間表(天)來加載不同的實體。但是它會降低性能,因爲它必須訪問數據庫兩次以上。它會使連接過載。並在商店程序中使用GROUP BY。但是這個存儲過程不起作用,它會引發錯誤。我不能那樣做。 Sooooo ...這些是使用GridView的問題。如果你有更多的方法來解決。我很高興。 謝謝。 – Gabriel

相關問題