gridview asp.net

时间:2017-07-13 08:59:38

标签: asp.net gridview page-index-changed

我有一个墙板应用程序,我必须在gridview中显示一些记录。由于记录数量很大所以我必须在gridview中实现分页。但由于是wallboard应用程序用户无法更改页面。所以在每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;
        }
    }
}

以上是我尝试使用自动收报机的代码。

如果我尝试使用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" />

2 个答案:

答案 0 :(得分: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);
}

答案 1 :(得分:0)

.Aspx代码:

docker network inspect -f '{{range .Containers}}{{println .Name .IPv4Address}}{{end}}' integration 放在GridView的{​​{1}}内。

ContentTemplate

.CS代码:

UpdatePanel可以是<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> PageIndex可以是0,因此它们不能相等。因此,您必须使用此代码:

PageCount