开发者

How to programmatically iterate through pages of a GridView

开发者 https://www.devze.com 2023-01-22 13:15 出处:网络
I\'ve created a wallboard application to display outstanding support calls for my ICT department. I\'ve bound a number of gridviews to sqldatasources which execute a stored procedure. This is automate

I've created a wallboard application to display outstanding support calls for my ICT department. I've bound a number of gridviews to sqldatasources which execute a stored procedure. This is automated via asp.net ajax controls and partially refreshes the page/data every 30 seconds.

At the moment, when the number of records in the gridview goes over 9, the gridview automatically pages and shows the number of pages in the bottom right hand corner. The helpdesk can then VNC to th开发者_如何转开发e box which controls the screen and manually click to see what's on the next page.

What I am after is a way to programmatically (using the c# code-behind file) changing the current displayed page after 10/15 seconds or so, obviously if this is possible in the scope of the gridview. I trailed using javascript (and failed at jquery) of scrolling the gridview within a div, however this didn't work as expected.

Can anyone point me in the right example? I can't find anyone else querying this functionality via a quick Google. Any help/advice of how to fix this issue would be greatly appreciated!!

Gridview Code:

<asp:GridView ID="GridView1" ShowHeader="False" runat="server" AutoGenerateColumns="False" DataSourceID="SqlDataSource1" 
GridLines="None" CellPadding="2" Font-Size="35pt" AllowPaging="True" PageSize="9">
<Columns>
<asp:BoundField DataField="ID" HeaderText="ID" SortExpression="ID">
<ItemStyle Width="15%" />
</asp:BoundField>
<asp:BoundField DataField="ASSIGNEES" HeaderText="ASSIGNEES" SortExpression="ASSIGNEES">
<ItemStyle Width="32%" Wrap="false"/>
</asp:BoundField>
<asp:BoundField DataField="title" HeaderText="title" SortExpression="title">
<ItemStyle Width="53%"  Wrap="false"/>
</asp:BoundField>
</Columns>
</asp:GridView>

SqlDataSource Code:

<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:FPConnectionString %>" SelectCommand="HDMonitoringOutstandingToday" SelectCommandType="StoredProcedure"></asp:SqlDataSource>

Printscreen of wallboard:

How to programmatically iterate through pages of a GridView


You can try something like this in a timer.

if(GridView1.PageIndex == GridView1.PageCount)
{
   GridView1.PageIndex = 0;
}
else
{
   GridView.PageIndex = GridView.PageIndex + 1;
}

I cant remember if you would need to add one to the PageIndex or not.

But anyway, the properties you need to work with are PageIndex and PageCount.


GridView.PageIndex 

You can change pages by setting the PageIndex, how you do it is up to you see here for some examples: http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview.pageindex.aspx

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号