[英]asp.net / vb - update label text
I'm having problems getting my label to update, this is the code im using.. 我在更新标签时遇到问题,这是我正在使用的代码。
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
It is an asp:Label declard in default.aspx Basically im trying to have this update whenever changes are made to the calendar im using - so far it works right - however the label displayed on the webpage is never updated until i close the webpage and reopen - how could i get this to update whenever changes are made? 这是在default.aspx中声明的asp:Label。基本上,即时消息是在尝试使用日历即时消息进行更改时立即进行此更新-到目前为止,它可以正常工作-但是,直到我关闭该网页并重新打开-每当进行更改时,如何更新此内容?
In your public default class : 在您的公共默认类中:
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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.