asp.net / vb - 更新标签文本

时间:2014-07-24 15:50:37

标签: asp.net vb.net label

我在更新标签时遇到问题,这是我正在使用的代码..

Private Sub UpdateLabels(ByVal start As Date, ByVal [end] As Date, ByVal value As Double)

    Dim da As New SqlDataAdapter("SELECT * FROM [event] WHERE NOT (([eventend] <= @start) OR ([eventstart] >= @end))", ConfigurationManager.ConnectionStrings("daypilot").ConnectionString)
    da.SelectCommand.Parameters.AddWithValue("start", start)
    da.SelectCommand.Parameters.AddWithValue("end", [end])
    da.SelectCommand.Parameters.AddWithValue("value", value)
    Dim dt As New DataTable()
    da.Fill(dt)

    Dim original As DateTime = DateTime.Now ' The date you want to get the last day of the month for
    Dim lastOfMonth As DateTime = original.Date.AddDays(-(original.Day - 1)).AddMonths(1).AddDays(-1)

    If dt.Rows.Count > 0 Then
        For i As Integer = 0 To dt.Rows.Count - 1
            Dim startdate As Date = dt.Rows(i).Item("eventstart").ToString
            Dim enddate As Date = dt.Rows(i).Item("eventend").ToString
            Dim today As Date = Now()
            If startdate < today And enddate > today Then
                Dim add = dt.Rows(i).Item("value").ToString
                value = value + add
            ElseIf enddate <= lastOfMonth Then
                Dim add = dt.Rows(i).Item("value").ToString
                value = value + add
            End If
        Next
    End If

    If IsPostBack() Then

        LabelFMI.Text = value

        If LabelFMI.Text >= 800 = True Then
            LabelFMI.ForeColor = System.Drawing.Color.Red
        Else
            LabelFMI.ForeColor = System.Drawing.Color.Green
        End If

        If LabelSFA.Text >= 1000 = True Then
            LabelSFA.ForeColor = System.Drawing.Color.Red
        Else
            LabelSFA.ForeColor = System.Drawing.Color.Green
        End If
    End If

End Sub

这是一个asp:标签在default.aspx中声明 基本上我试图在每次更改日历时尝试更新 - 到目前为止它工作正常 - 但是网页上显示的标签永远不会更新,直到我关闭网页并重新打开 - 我怎么能在更改时更新是吗?

1 个答案:

答案 0 :(得分:0)

在您的公开默认课程中:

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    If Not Page.IsPostBack Then
        'Put here what you want to be made once
    End If

    'Put here what you what to be repeted at every postback.

End Sub