2012-02-23 53 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

相关问题