나는 데이터 바인딩 된 열 중 하나에서 DateTime
형식의 값이 H:mm:ss {0:H:mm:ss}
인 SQLDatasource (항목이 데이터 바인딩 됨)에 바인딩 된 Telerik Radgrid가 있습니다. 그때템플릿 격자의 RadGrid 카운트 다운 시계
그래서 "시간이 남아"표시하는 템플릿 열 추가 : - 이제
Time Left
내가 그래서이 Ajaxified 싶어 내가 타이머 및 템플릿 열에서 updatepanel 내부 레이블을 추가 = - 시작 시간마다에 대한 tick (1000ms) time left
을 다시 계산합니다.
이 작동하는 것 같다하지만 여기에 RadGrid
의 첫 번째 행에 대한 코드가 ASP를
니펫 있습니다
<telerik:GridTemplateColumn FilterControlAltText="Filter TemplateColumn column" UniqueName="TemplateColumn"
HeaderText="Starting in">
<ItemTemplate>
<contenttemplate>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:Label ID="lbltime" runat="server" Text="00:00:00"></asp:Label>
<asp:Timer ID="Timer1" runat="server" Interval="1000" ontick="Timer1_Tick"></asp:Timer>
</ContentTemplate>
</asp:UpdatePanel>
</contenttemplate>
</ItemTemplate>
</telerik:GridTemplateColumn>
C#
protected void Timer1_Tick(object sender, EventArgs e)
{
GridDataItem viewitem = (sender as System.Web.UI.Timer).Parent.Parent.Parent.Parent as GridDataItem;
DateTime starttime = DateTime.ParseExact((viewitem.FindControl("Strat_TimeLabel") as Label).Text, "H:mm:ss", System.Globalization.CultureInfo.CurrentCulture);
DateTime nowtime = System.DateTime.Now;
TimeSpan ts = new TimeSpan();
ts = starttime - nowtime;
GridDataItem item = (sender as System.Web.UI.Timer).Parent.Parent.Parent.Parent as GridDataItem;
if (ts.Seconds >= 0 && ts.Minutes > 0)
{
DateTime d = new DateTime(2000, 01, 01, ts.Hours, ts.Minutes, ts.Seconds);
(item.FindControl("lbltime") as Label).Text = d.ToString("H:mm:ss");
}
else
{
(item.FindControl("lbltime") as Label).Text = "00:00:00";
}
}
도움이나 조언을 보내 주시면 감사하겠습니다.