2017-07-13 26 views
1

私はグリッドビューにいくつかのレコードを表示する必要があるウォールボードアプリケーションを1つ持っています。レコードの数が多いので、私はgridviewでページングを実装する必要があります。ウォールボードのアプリケーションユーザーはページを変更できません。 10秒ごとに次のページを表示する必要があります。上記グリッドビューの自動変更ページインデックス

CSファイル

protected void Timer1_Tick1(object sender, EventArgs e) 
{ 
    if (GV_ExtCallSummary.PageCount == GV_ExtCallSummary.PageIndex) 
    { 
    // timer1.Enabled = false; 
    // GV_ExtCallSummary.PageIndex = 1; 

    } 
    else 
    { 
     try 
     { 
      // GV_ExtCallSummary.PageIndex++; 
      GV_ExtCallSummary.SetPageIndex(1); 
      // GV_ExtCallSummary.DataSource = dt; 
      GV_ExtCallSummary.DataBind(); 
     } 
     catch(Exception ex) 
     { 
      string exv = ex.Message; 
     } 
    } 
} 

iがティッカーと試みたコードです。

GV_ExtCallSummary.PageIndex++を使用しようとすると何も起こりません。 pageindexに増やすだけです。

と私はsetpageindex(1)を使用する場合それは例外スロー:

処理されなかったGridViewの「GV_ExtCallSummary」解雇イベントPageIndexChangingを。

でも機能があると思われます。

protected void GV_ExtCallSummary_PageIndexChanging(object sender, GridViewPageEventArgs e) 
{ 
    GV_ExtCallSummary.PageIndex = e.NewPageIndex; 
    GV_ExtCallSummary.DataSource = dt; 
    GV_ExtCallSummary.DataBind(); 
} 

この機能は、ページ番号をクリックすると正常に機能します。

HTML いずれかのHTMLコード

<asp:GridView ID="GV_ExtCallSummary" runat="server" AutoGenerateColumns="false" 
Width="100%" Visible="true" OnRowDataBound="GV_ExtCallSummary_RowDataBound" OnPageIndexChanging="GV_ExtCallSummary_PageIndexChanging" 
EmptyDataText="No data exist." AllowPaging="True" CssClass="table" HeaderStyle-BackColor="#669999" 
AlternatingRowStyle-CssClass="success" PageSize="10"> 
<Columns> 
    <asp:TemplateField HeaderText="Extention"> 
     <ItemTemplate> 
      <asp:Label ID="lblExt" runat="server" Text='<%# Bind("Extension") %>' /> 
     </ItemTemplate> 
    </asp:TemplateField> 


    <asp:TemplateField HeaderText="Name"> 
     <ItemTemplate> 
      <asp:Label ID="lblExtName" runat="server" Text='<%# Bind("ExtnName") %>' /> 
     </ItemTemplate> 
    </asp:TemplateField> 

    <asp:TemplateField HeaderText="Abandon"> 
     <ItemTemplate> 
      <asp:Label ID="lblAdandon" runat="server" Text='<%# Bind("Abandon") %>' /> 
     </ItemTemplate> 
    </asp:TemplateField> 

    <asp:TemplateField HeaderText="Incoming"> 
     <ItemTemplate> 
      <asp:Label ID="lblIncoming" runat="server" Text='<%# Bind("Incoming") %>' /> 
     </ItemTemplate> 
    </asp:TemplateField> 

    <asp:TemplateField HeaderText="Outgoing"> 
     <ItemTemplate> 
      <asp:Label ID="lblOutgoing" runat="server" Text='<%# Bind("Outgoing") %>' /> 
     </ItemTemplate> 
    </asp:TemplateField> 
    <asp:TemplateField HeaderText="Intercom"> 
     <ItemTemplate > 
      <asp:Label ID="lbl_Intercom" runat="server" Text='<%# Bind("Intercom") %>' /> 
     </ItemTemplate> 
    </asp:TemplateField> 
</Columns> 
<SelectedRowStyle BackColor="#8AC5FF" Font-Bold="True" ForeColor="White" /> 

答えて

0

.aspxのコード:

あなたGridViewUpdatePanelContentTemplate内を置きます。

<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional"> 
    <Triggers> 
     <asp:AsyncPostBackTrigger ControlID="Timer1" EventName="Tick" /> 
    </Triggers> 
    <ContentTemplate> 
     <!-- Here will be your Gridview Code --> 
    </ContentTemplate> 
</asp:UpdatePanel> 

<!-- Timer will tick after 10 seconds --> 
<asp:Timer ID="Timer1" runat="server" Interval="10000" OnTick="Timer1_Tick"> 
</asp:Timer> 

.CSコード:

PageIndex0PageCountであってもよいことができ、それらが等しくなることができないように、1です。したがって、このコードを使用する必要があります:

protect void Timer1_Tick(object sender, EventArgs e) 
{ 
    if(GV_ExtCallSummary.PageIndex == (GV_ExtCallSummary.PageCount -1)) 
    { 
     GV_ExtCallSummary.PageIndex = 0; 
    } 
    else 
    { 
     GV_ExtCallSummary.PageIndex = GV_ExtCallSummary.PageIndex + 1; 
    } 

    GV_ExtCallSummary.DataSource = dt; // e.g. dt can be your be your data to set 
    GV_ExtCallSummary.DataBind(); 
} 
+1

よろしくお願い致します。わたしにはできる。再度、感謝します。 –

0

を見たい場合は、最初のPageIndexChangingイベントが処理されていることを確認する必要があります。

protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e) 
{ 
    int pageIndex = GridView1.PageIndex + 1; 

    //if you want the autmatic page change to stop at the end 
    if (pageIndex == GridView1.PageCount) 
    { 
     Timer1.Enabled = false; 
     return; 
    } 

    //or loop continuously by going back to the first page 
    if (pageIndex == GridView1.PageCount) 
    { 
     pageIndex = 0; 
    } 

    //set the new pageindex and rebind the gridview 
    GridView1.PageIndex = pageIndex; 
    GridView1.DataSource = mySource; 
    GridView1.DataBind(); 
} 

Tickでは、メソッドを呼び出します。

protected void Timer1_Tick(object sender, EventArgs e) 
{ 
    GridView1_PageIndexChanging(null, null); 
} 
関連する問題