ASP.net日历DayRender每天显示多个文本回复

时间:2012-02-23 16:14:33

标签: asp.net vb.net calendar

我有一个简单的asp.net日历,它会在请求假期的日子里突出显示并输入用户名。但是,最新请求会覆盖旧请求的名称,而不是显示多个名称。代码如下:

  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 个答案:

答案 0 :(得分:1)

您没有将用户名附加到单元格文本。要显示用户名列表,请将 e.Cell.Text = username 行更改为 e.Cell.Text + =用户名

一种替代方法是动态地向细胞添加控制(例如 e.Cell.Controls.Add(new LiteralControl(username ));)而不是简单地显示文本。

这可以让你走上正轨。