This is a migrated thread and some comments may be shown as answers.

Ajaxify Timer For RadGrid DataItems

5 Answers 163 Views
Ajax
This is a migrated thread and some comments may be shown as answers.
Virgil Rodriguez
Top achievements
Rank 1
Virgil Rodriguez asked on 01 Apr 2010, 09:04 PM
Hello Telerik and Everyone Else!

I've tried very hard to look for a similar question that has already been answered but unfortunately I couldn't find one. So please bear with me.

As you know there is demo about ajaxifying the timer here: 
http://demos.telerik.com/aspnet-ajax/ajax/examples/common/ajaxifytimer/defaultvb.aspx

This demo updates the whole RadGrid every interval of the timer.

What if instead of updating the whole RadGrid every interval of the timer, each of the datagrid row gets updated at different times - say the 1st row get's updated every 5 seconds, the 2nd row at 10 seconds, the 3rd row at 8 seconds, the 4th row at 30 seconds, and so on and so forth.

I guess what I want is that each datagrid row will have its own separate dynamically created timer running at different intervals. How can RadAjaxManager handle that kind of a scenario? Below are some code snippets of my failed attempt:

Public Class TCSTimer  
    Inherits System.Timers.Timer  
 
    Private mstrTag As Object 
    Private mstrName As String 
 
    Public Property Tag() As Object 
        Get 
            Return mstrTag  
        End Get 
        Set(ByVal value As Object)  
            mstrTag = value  
        End Set 
    End Property 
 
    Public Property Name() As String 
        Get 
            Return mstrName  
        End Get 
        Set(ByVal value As String)  
            mstrName = value  
        End Set 
    End Property 
 
    Public Sub New()  
        MyBase.New()  
    End Sub 
 
    Public Sub New(ByRef sTag As ObjectByVal sName As String)  
        mstrTag = sTag  
        mstrName = sName  
    End Sub 
End Class 
 
Partial Class _Default  
    Inherits System.Web.UI.Page  
 
    Protected Sub RadGrid1_ItemDataBound(ByVal sender As ObjectByVal e As GridItemEventArgs) Handles RadGrid1.ItemDataBound  
        If TypeOf e.Item Is GridDataItem Then 
            Dim dataItem As GridDataItem = CType(e.Item, GridDataItem)  
            Dim item As GridDataItem = TryCast(e.Item, GridDataItem)  
            Dim hlLink As HyperLink = item.FindControl("hlFPP")  
            hlLink.NavigateUrl = "Default.aspx?panel=SubGrid&f=" & dataItem("FPP").Text.Split("-")(0).Trim & "&prog=" & dataItem("FPP").Text.Split("-")(1).Trim & _  
                                 "&prod=" & dataItem("FPP").Text.Split("-")(2).Trim & "&status=" & dataItem("Status").Text & _  
                                 "&message=" & dataItem("Message").Text  
            hlLink.Text = dataItem("FPP").Text  
            Dim lblTC As Label = item.FindControl("lblTC")  
            lblTC.Text = Now().ToLongTimeString  
            Dim lblCtr As Label = item.FindControl("lblCtr")  
            lblCtr.Text = Now().ToLongTimeString  
 
            If "/WP/".Contains("/" & dataItem("Status").Text.Trim.ToUpper & "/"Then 
                item.BackColor = Color.DarkRed  
                item.ForeColor = Color.Yellow  
                hlLink.ForeColor = Color.White  
            End If 
            If "/B/M/".Contains("/" & dataItem("Status").Text.Trim.ToUpper & "/"Then 
                item.BackColor = Color.Yellow  
                item.ForeColor = Color.Blue  
            End If 
 
 
            Dim tmrGridTimer As TCSTimer = New TCSTimer(dataItem, hlLink.Text)  
            tmrGridTimer.Interval = 1000  
            AddHandler tmrGridTimer.Elapsed, AddressOf tmrGridTimer_Elapsed  
            Dim rajaxs As Telerik.Web.UI.AjaxSetting = New Telerik.Web.UI.AjaxSetting  
            rajaxs.AjaxControlID = tmrGridTimer.Name  
            Dim rajaxsupdctrl As Telerik.Web.UI.AjaxUpdatedControl = New Telerik.Web.UI.AjaxUpdatedControl  
            rajaxsupdctrl.ControlID = "RadGrid1" 
            rajaxs.UpdatedControls.Add(rajaxsupdctrl)  
            rajaxsupdctrl.ControlID = lblTaktClock.ID  
            rajaxs.UpdatedControls.Add(rajaxsupdctrl)  
            rajaxsupdctrl.ControlID = lblCounter.ID  
            rajaxs.UpdatedControls.Add(rajaxsupdctrl)  
            rajaxsupdctrl.LoadingPanelID = "LoadingPanel1" 
            rajaxs.UpdatedControls.Add(rajaxsupdctrl)  
            RadAjaxManager1.AjaxSettings.Add(rajaxs)  
            tmrGridTimer.Start()  
 
        End If 
    End Sub 
 
    Public Sub tmrGridTimer_Elapsed(ByVal sender As ObjectByVal e As System.Timers.ElapsedEventArgs)  
        Dim itmTC As Label = CType(CType(sender, TCSTimer).Tag, GridDataItem).FindControl("lblTC")  
        Dim itmCtr As Label = CType(CType(sender, TCSTimer).Tag, GridDataItem).FindControl("lblCtr")  
 
        Dim r As New Random()  
        Dim t1, a1 As Integer 
 
        t1 = r.Next(1, 100)  
        a1 = r.Next(1, 100)  
 
        itmTC.Text = t1  
        itmCtr.Text = a1  
 
        t1 = Nothing 
        a1 = Nothing 
    End Sub 
 
End Class 


Thanks in advance!

5 Answers, 1 is accepted

Sort by
0
wk
Top achievements
Rank 1
answered on 03 Apr 2010, 02:11 PM
Hi Virgil,

You may add into GridTemplateColumn.
 <asp:Timer ID="tmrGridTimer" runat="server"/>  

In RadGrid1_ItemDataBound, you may refer to the code as below
Dim tmrGridTimer As Timer = CType(e.item.FindControl("tmrGridTimer"),Timer) 
Dim lblTimerInterval as Label = CType(e.item.FindControl("lblTimerInterval"),Label) 'different timer interval for each row 
 
RadAjaxManager1.AjaxSettings.add(tmrGridTimer, RadGrid1,Nothing
tmrGridTimer.Interval = CInt(lblTimerInterval.Text) 
tmrGridTimer.Start() 

Of course don't forget to add your RadAjaxLoadingPanel in aspx page too.



0
Virgil Rodriguez
Top achievements
Rank 1
answered on 05 Apr 2010, 02:51 PM
Hi Wk,

Thanks for responding. I tried your suggestion but I'm still unable to make it work.

I forgot to mention I'm using Telerik Version 2008.2.826.20 which is probably why your proposed statement:

RadAjaxManager1.AjaxSettings.add(tmrGridTimer, RadGrid1,Nothing

does not work for me.

What AjaxControlID do I give the RADAjaxSettings for each unique grid row timer? My Timer_Tick (or TimerElapsed event) does  not even trigger. And even if I can make it so, how do I determine, for which row is it ticking?

A working sample would be very helpful.

Thanks in advance again!
0
Mira
Telerik team
answered on 08 Apr 2010, 11:09 AM
Hello Virgil,

Please note that one cannot add the Timer control directly to the AJAX settings as updated control. Instead, just wrap the timer in a container like ASP:Panel and set the container as updated control:
<telerik:GridTemplateColumn UniqueName="TemplateColumn">
    <ItemTemplate>
        <asp:Panel ID="Panel1" runat="server">
            <asp:Timer ID="Timer1" runat="server" Interval="3000" OnTick="Timer1_Tick" />
        </asp:Panel>
    </ItemTemplate>
</telerik:GridTemplateColumn>
For more information, please take a look at the Ajaxify Timer demo.

To get the row containing the timer, please use the following code:
public void Timer1_Tick(object sender, EventArgs e)
{
    GridDataItem item = (sender as System.Web.UI.Timer).Parent.Parent.Parent as GridDataItem;       
    //...
 
}

I hope this helps.

Sincerely yours,
Mira
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Virgil Rodriguez
Top achievements
Rank 1
answered on 13 Apr 2010, 07:18 PM
Hi Mira,

If I wrap the timer within a panel, how do I dynamically add the panel to my AJAX settings? What control triggers the update of this panel?

It would really help if you can show me a running example.

Thanks.
0
Mira
Telerik team
answered on 16 Apr 2010, 09:03 AM
Hello Virgil,

I have followed your scenario and prepared a sample project for you. In it the timer from one template column updates the label in another template column.
If you want to update the whole row, I recommend that you either display all data in template columns and use the approach from my demo, or use only one ItemTemplate for the corresponding table view and place the whole content in a AJAX Panel.

I hope this helps.

All the best,
Mira
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
Tags
Ajax
Asked by
Virgil Rodriguez
Top achievements
Rank 1
Answers by
wk
Top achievements
Rank 1
Virgil Rodriguez
Top achievements
Rank 1
Mira
Telerik team
Share this question
or