• ASP.net / vb – update label text

    Adan Member

    I’m having problems getting my label to update, it is a asp:label known as Label FMI – what I am doing is when the user changes the value of certain things update it by either taking away or adding the difference. I’ve managed to get this to work by having to refresh the page and moving it to default.aspx Page_load sub..

    However I was hoping to not have to refresh to have it update? is there anyway to achieve this?

    this is the code i’m 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
    
  • GloriaFine Member

    Yes you can. it’s very simple to do it. try search “Timer vb .net” and it may run on “tick” event

Viewing 1 reply thread
  • You must be logged in to reply to this topic.