Gridview分页错误:指定的参数超出了有效值的范围

时间:2017-08-28 13:13:36

标签: c# asp.net gridview paging

我正在尝试为gridview启用分页,但是我总是收到错误:

  

“指定的参数超出了有效值的范围。参数名称:index”   如果我忽略错误gridview创建分页并正常工作,但忽略错误...   这是我的网格:

<asp:GridView ID="gvDeslocFinal" runat="server" Height="181px" Width="1042px" OnRowDataBound="gvDeslocFinal_RowDataBound" AutoGenerateColumns="false" AllowSorting="true" OnSorting="gvDeslocFinal_Sorting" OnPageIndexChanging="gvDeslocFinal_PageIndexChanging" OnSorted="gvDeslocFinal_Sorted" AllowPaging="True" OnRowCreated="gvDeslocFinal_RowCreated" PageIndex="1">
    <Columns>
        <asp:BoundField DataField="Utilizador" HeaderText="Utilizador" />
        <asp:BoundField DataField="Carro" HeaderText="Carro" />...
            <ItemStyle CssClass="hidden-field" />
        </asp:BoundField>
        <asp:TemplateField HeaderText="Detalhes">
            <ItemTemplate>
                <asp:LinkButton ID="lnkEdit" Text="ver detalhes" OnClick="lnkEdit_Click" runat="server"></asp:LinkButton>
            </ItemTemplate>
        </asp:TemplateField>
    </Columns>
    <EditRowStyle HorizontalAlign="Center" />
    <HeaderStyle VerticalAlign="Middle" HorizontalAlign="Center" Font-Bold="False" Height="30px" />

    <RowStyle HorizontalAlign="Center" VerticalAlign="Middle" Height="20px" />
</asp:GridView>


protected void gvDeslocFinal_Sorted(object sender, EventArgs e)
{
    if (gvDeslocFinal.EditIndex >= 0)
        return;
    BindGrid();
}

BindGrid功能:

private void BindGrid()
{
    try
    {

        for (int i = 0; i < GlobalOffline.DesTerm.Length; i++)
        {


            string sDataIn = smtgh;
...


            string sCodigo = GlobalOffline.DesTerm[i].Codigo;

            string[] sRow = new string[] { sCarro, ..., sCodigo };
            GlobalOffline.dtResult.Rows.Add(sRow);
        }

        gvDeslocFinal.DataSource = GlobalOffline.dtResult;
        gvDeslocFinal.VirtualItemCount = GlobalOffline.dtResult.Rows.Count;
        GlobalOffline.bDetails = false;
        gvDeslocFinal.DataBind();
}

0 个答案:

没有答案