2014-04-22 4 views
0

나는 데이터 바인딩 된 열 중 하나에서 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"; 
     } 
    } 

도움이나 조언을 보내 주시면 감사하겠습니다.

답변

0

관심있는 사람이 있다면 주위에 해결 방법이 있습니다.

나는

내가 모든 GridCommand에 대한

다음
 foreach (GridDataItem item in RadGrid1.Items) 
     { 
      DateTime starttime = DateTime.ParseExact((item.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; 

      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 = "Complete"; 
      } 
     } 

에 Timer1_Tick의 뒤에 C# 코드를 변경 (타이머도 여전히 updatepanel에 포함) 전체 RadGrid를 캡슐화 할 수있는 updatepanel 이동 간단히 타이머를 사용 중지/사용 설정합니다.

InsertCommand: Timer1.enabled = false; 
    EditCommand: Timer1.enabled = false; 
    UpdateCommand: Timer1.enabled = True; 
    CancelCommand: Timer1.enabled = false; 

아마도 가장 웅장한 방식이 아닙니다. ould는 Item Template에 포스트 백 이벤트를 포함하고 싶었지만 작동합니다 ... 개선 및 제안은 언제나 환영합니다.

관련 문제