2012-02-23 36 views
0

我有一個簡單的asp.net日曆,它突出顯示並輸入用戶名稱,在他們請求假期的日子裏。但是,最新的請求將覆蓋舊請求的名稱而不是顯示多個名稱。代碼如下:ASP.net日曆DayRender每天顯示多個文本響應

Protected Sub Calendar1_DayRender(ByVal sender As Object, _ 
     ByVal e As System.Web.UI.WebControls.DayRenderEventArgs) _ 
     Handles Calendar1.DayRender 
    Dim nextDate As DateTime 
    Dim StartDate As DateTime 
    Dim Enddate As DateTime 
    Dim username As String 

    If Not dsHolidays Is Nothing Then 
     For Each dr As DataRow In dsHolidays.Tables(0).Rows 
      StartDate = CType(dr("StartDate"), DateTime) 
      Enddate = CType(dr("EndDate"), DateTime) 
      nextDate = CType(dr("startdate"), DateTime) 
      username = CType(dr("username"), String) 

      If e.Day.Date >= StartDate And e.Day.Date <= Enddate Then 

       e.Cell.Text = username 
       e.Cell.BackColor = System.Drawing.Color.Pink 
      End If 
     Next 
    End If 
End Sub 

有什麼建議嗎?

回答

1

您不會將用戶名追加到單元格文本中。要顯示用戶名稱列表,請將e.Cell.Text =用戶名更改爲e.Cell.Text + =用戶名

另一種方法是動態地將控件添加到單元格中(例如e.Cell.Controls.Add(new LiteralControl(username));),而不是簡單地顯示文本。

這應該讓你走上正確的軌道。

+0

謝謝... e.Cell.Text + =用戶名工作正常...無論如何,我可以讓他們顯示在單獨的行/段?它目前直接顯示一個 – user1055487 2012-02-23 16:31:38

+0

耶 - 只要將其更改爲e.Cell.Text + =用戶名+「
」,或者您希望它顯示。如果你想要看起來,你可以添加一個新的表格控件到單元格中,並將每個用戶名作爲單元格添加到該表格中。 – jmaglio 2012-02-23 16:49:19

相關問題