2014-07-24 90 views
0
我有問題,讓我的標籤更新

,這是使用代碼IM ..asp.net/VB - 更新標籤文本

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中 標籤declard基本上即時通訊嘗試進行此更新,只要對日曆進行更改即可使用 - 至目前爲止它的工作原理正確 - 但是,網頁上顯示的標籤從未更新,直到我關閉網頁並重新打開時 - 我如何在更改時更新此更新被製造?

回答

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 
+0

不,仍然沒有工作= /。 – Andy

+0

@Andy按F5是否修正顏色(無需關閉/重新打開瀏覽器)? – Sifu

+0

不,頁面會加載thr文本,生病改變應該改變文本標籤和顏色的東西,刷新 – Andy