错误:“容量小于当前大小”使用 ASP.NET DataPager 控件

发布于 2024-12-29 21:14:33 字数 9267 浏览 0 评论 0原文

我有一个带有 DataPager 的 ASP.NET ListView,按照以下代码:

        <asp:ListView ID="TicketsPerPersonListView" runat="server" DataSourceID="ObjectDataSource1">
        <EmptyDataTemplate>
            -- No Records Found --
        </EmptyDataTemplate>
        <ItemTemplate>
            <tr style="display: table-row;">
                <td>
                    <a href="viewticket.aspx?id=<%#Eval("ticket_id")%>">#<%# Eval("TicketID")%>-
                        <%# Eval("ShortDesc")%></a>
                </td>
                <td>
                    <%# Eval("StatusName")%>
                </td>
                <td style="text-align: right; padding-right: 60px;">
                    <%# Eval("StatusDescription")%>
                </td>
                <td style="text-align: right; padding-right: 60px;">
                    <%# Eval("TimeLastAction")%>
                </td>
            </tr>
        </ItemTemplate>
        <LayoutTemplate>
            <table>
                <thead>
                    <tr>
                        <th>
                            Title
                        </th>
                        <th style="text-align: right; padding-right: 60px;">
                            Current Status
                        </th>
                        <th style="text-align: right; padding-right: 60px;">
                            Latest Action
                        </th>
                        <th style="text-align: right; padding-right: 60px;">
                            Last Viewed
                        </th>
                    </tr>
                </thead>
                <tfoot>
                    <tr>
                        <td colspan="5">
                            <div class="pagination">
                                <asp:DataPager ID="TicketsPerPersonDataPager" runat="server" PagedControlID="TicketsPerPersonListView"
                                    PageSize="10">
                                    <Fields>
                                        <asp:NextPreviousPagerField FirstPageText="&lt;&lt;" ShowFirstPageButton="True" ShowNextPageButton="False"
                                            ShowPreviousPageButton="False" />
                                        <asp:NumericPagerField CurrentPageLabelCssClass="graybutton pagelink active" NumericButtonCssClass="graybutton pagelink" />
                                        <asp:NextPreviousPagerField LastPageText="&gt;&gt;" ShowLastPageButton="True" ShowNextPageButton="False"
                                            ShowPreviousPageButton="False" />
                                    </Fields>
                                </asp:DataPager>
                            </div>
                        </td>
                    </tr>
                </tfoot>
                <tbody>
                    <asp:PlaceHolder runat="server" ID="itemPlaceholder"></asp:PlaceHolder>
                    <tr style="display: table-row;">
                    </tr>
                </tbody>
            </table>
        </LayoutTemplate>
    </asp:ListView>
    <asp:ObjectDataSource ID="ObjectDataSource1" runat="server" EnablePaging="True" SelectMethod="FindByUserID"
        TypeName="Xyratex.XCS.Services.TicketService" StartRowIndexParameterName="startRowIndex"
        MaximumRowsParameterName="maximumRows" SelectCountMethod="CountByUserID">
        <SelectParameters>
            <asp:Parameter Name="userID" DbType="Int64" DefaultValue="79" />
            <asp:ControlParameter Name="custID" ControlID="DDCaller" ConvertEmptyStringToNull="True"
                DefaultValue="" />
            <asp:ControlParameter Name="company" ControlID="DDCompany" ConvertEmptyStringToNull="True"
                DefaultValue="" />
            <asp:ControlParameter Name="owner" ControlID="DDOwner" ConvertEmptyStringToNull="True"
                DefaultValue="" />
            <asp:ControlParameter Name="action" ControlID="DDAction" ConvertEmptyStringToNull="True"
                DefaultValue="" />
            <asp:ControlParameter Name="status" ControlID="DDCurrentStatus" ConvertEmptyStringToNull="True"
                DefaultValue="" />
        </SelectParameters>
    </asp:ObjectDataSource>

为 ObjectDataSource 提供数据的 VB.NET 代码如下:

    ''' <summary>
''' Finds all the <see cref="Xyratex.XCS.Model.Tickets.Ticket" /> objects belonging to the specified user ID
''' </summary>
''' <param name="userID">The id of the user to find tickets for</param>
''' <param name="startRowIndex">The starting index of the portion of the recordset</param>
''' <param name="maximumRows">The maximum amount of rows to return</param>
''' <param name="custID">The id of the customer to find tickets for</param>
''' <param name="company">The company name to find tickets for</param>
''' <param name="owner">The owner to find tickets for</param>
''' <param name="action">The action to find tickets for</param>
''' <param name="status">The status of tickets to find.</param>
''' <returns>A <see cref="System.Collections.Generic.IList(Of Xyratex.XCS.Model.Tickets.Ticket)" /> object</returns>
''' <remarks>XY01\rpenfold 30 January 2012</remarks>
Public Function FindByUserID(ByVal userID As Long,
                             ByVal startRowIndex As Long,
                             ByVal maximumRows As Long,
                             ByVal custID As Long?,
                             ByVal company As String,
                             ByVal owner As Integer?,
                             ByVal action As Char?,
                             ByVal status As Long?) As List(Of LightWeightTicket) Implements ITicketRepository.FindByUserID
    'Start a new session and run the query
    Using session As NHibernate.ISession = SessionFactory.GetNewSession()
        Dim query As NHibernate.IQuery = session.GetNamedQuery("Select_AllTickets_ByUserID_RyanTest")
        query.SetInt64("user_id", userID)
        Select Case custID.HasValue
            Case True
                query.SetInt64("cust_id", custID.Value)
            Case False
                query.SetString("cust_id", Nothing) 'SetString makes it NULL
        End Select
        Select Case String.IsNullOrWhiteSpace(company)
            Case True
                query.SetString("company", Nothing)
            Case False
                query.SetString("company", company) 'SetString makes it NULL
        End Select
        Select Case owner.HasValue
            Case True
                query.SetInt32("owner", owner.Value)
            Case False
                query.SetString("owner", Nothing) 'SetString makes it NULL
        End Select
        Select Case action.HasValue
            Case True
                query.SetCharacter("action", action.Value)
            Case False
                query.SetString("action", Nothing) 'SetString makes it NULL
        End Select
        Select Case status.HasValue
            Case True
                query.SetInt64("status", status.Value)
            Case False
                query.SetString("status", Nothing) 'SetString makes it NULL
        End Select
        query.SetInt64("startRowIndex", startRowIndex)
        query.SetInt64("maximumRows", maximumRows)
        Return New List(Of LightWeightTicket)(query.List(Of LightWeightTicket)())
    End Using
End Function

当我加载页面时,我收到错误“容量小于当前大小” 。堆栈跟踪如下:

[ArgumentOutOfRangeException: capacity was less than the current size.

参数名称:值] System.Collections.ArrayList.set_Capacity(Int32值)+9360651 System.Web.UI.WebControls.ListView.CreateChildControls(IEnumerable dataSource,布尔数据绑定)+712 System.Web.UI.WebControls.ListView.PerformDataBinding(IEnumerable 数据) +35 System.Web.UI.WebControls.DataBoundControl.OnDataSourceViewSelectCallback(IEnumerable 数据)+128 System.Web.UI.DataSourceView.Select(DataSourceSelectArguments 参数,DataSourceViewSelectCallback 回调)+33 System.Web.UI.WebControls.DataBoundControl.PerformSelect() +143 System.Web.UI.WebControls.ListView.PerformSelect() +113 System.Web.UI.WebControls.BaseDataBoundControl.DataBind() +74 System.Web.UI.WebControls.BaseDataBoundControl.EnsureDataBound() +66 System.Web.UI.WebControls.ListView.CreateChildControls() +55 System.Web.UI.Control.EnsureChildControls() +102 System.Web.UI.Control.PreRenderRecursiveInternal() +42 System.Web.UI.Control.PreRenderRecursiveInternal() +175 System.Web.UI.Control.PreRenderRecursiveInternal() +175 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2496

有谁知道该怎么办?

预先感谢,

瑞安

I've got an ASP.NET ListView with a DataPager as per this code:

        <asp:ListView ID="TicketsPerPersonListView" runat="server" DataSourceID="ObjectDataSource1">
        <EmptyDataTemplate>
            -- No Records Found --
        </EmptyDataTemplate>
        <ItemTemplate>
            <tr style="display: table-row;">
                <td>
                    <a href="viewticket.aspx?id=<%#Eval("ticket_id")%>">#<%# Eval("TicketID")%>-
                        <%# Eval("ShortDesc")%></a>
                </td>
                <td>
                    <%# Eval("StatusName")%>
                </td>
                <td style="text-align: right; padding-right: 60px;">
                    <%# Eval("StatusDescription")%>
                </td>
                <td style="text-align: right; padding-right: 60px;">
                    <%# Eval("TimeLastAction")%>
                </td>
            </tr>
        </ItemTemplate>
        <LayoutTemplate>
            <table>
                <thead>
                    <tr>
                        <th>
                            Title
                        </th>
                        <th style="text-align: right; padding-right: 60px;">
                            Current Status
                        </th>
                        <th style="text-align: right; padding-right: 60px;">
                            Latest Action
                        </th>
                        <th style="text-align: right; padding-right: 60px;">
                            Last Viewed
                        </th>
                    </tr>
                </thead>
                <tfoot>
                    <tr>
                        <td colspan="5">
                            <div class="pagination">
                                <asp:DataPager ID="TicketsPerPersonDataPager" runat="server" PagedControlID="TicketsPerPersonListView"
                                    PageSize="10">
                                    <Fields>
                                        <asp:NextPreviousPagerField FirstPageText="<<" ShowFirstPageButton="True" ShowNextPageButton="False"
                                            ShowPreviousPageButton="False" />
                                        <asp:NumericPagerField CurrentPageLabelCssClass="graybutton pagelink active" NumericButtonCssClass="graybutton pagelink" />
                                        <asp:NextPreviousPagerField LastPageText=">>" ShowLastPageButton="True" ShowNextPageButton="False"
                                            ShowPreviousPageButton="False" />
                                    </Fields>
                                </asp:DataPager>
                            </div>
                        </td>
                    </tr>
                </tfoot>
                <tbody>
                    <asp:PlaceHolder runat="server" ID="itemPlaceholder"></asp:PlaceHolder>
                    <tr style="display: table-row;">
                    </tr>
                </tbody>
            </table>
        </LayoutTemplate>
    </asp:ListView>
    <asp:ObjectDataSource ID="ObjectDataSource1" runat="server" EnablePaging="True" SelectMethod="FindByUserID"
        TypeName="Xyratex.XCS.Services.TicketService" StartRowIndexParameterName="startRowIndex"
        MaximumRowsParameterName="maximumRows" SelectCountMethod="CountByUserID">
        <SelectParameters>
            <asp:Parameter Name="userID" DbType="Int64" DefaultValue="79" />
            <asp:ControlParameter Name="custID" ControlID="DDCaller" ConvertEmptyStringToNull="True"
                DefaultValue="" />
            <asp:ControlParameter Name="company" ControlID="DDCompany" ConvertEmptyStringToNull="True"
                DefaultValue="" />
            <asp:ControlParameter Name="owner" ControlID="DDOwner" ConvertEmptyStringToNull="True"
                DefaultValue="" />
            <asp:ControlParameter Name="action" ControlID="DDAction" ConvertEmptyStringToNull="True"
                DefaultValue="" />
            <asp:ControlParameter Name="status" ControlID="DDCurrentStatus" ConvertEmptyStringToNull="True"
                DefaultValue="" />
        </SelectParameters>
    </asp:ObjectDataSource>

The VB.NET code that provides the ObjectDataSource with data is thus:

    ''' <summary>
''' Finds all the <see cref="Xyratex.XCS.Model.Tickets.Ticket" /> objects belonging to the specified user ID
''' </summary>
''' <param name="userID">The id of the user to find tickets for</param>
''' <param name="startRowIndex">The starting index of the portion of the recordset</param>
''' <param name="maximumRows">The maximum amount of rows to return</param>
''' <param name="custID">The id of the customer to find tickets for</param>
''' <param name="company">The company name to find tickets for</param>
''' <param name="owner">The owner to find tickets for</param>
''' <param name="action">The action to find tickets for</param>
''' <param name="status">The status of tickets to find.</param>
''' <returns>A <see cref="System.Collections.Generic.IList(Of Xyratex.XCS.Model.Tickets.Ticket)" /> object</returns>
''' <remarks>XY01\rpenfold 30 January 2012</remarks>
Public Function FindByUserID(ByVal userID As Long,
                             ByVal startRowIndex As Long,
                             ByVal maximumRows As Long,
                             ByVal custID As Long?,
                             ByVal company As String,
                             ByVal owner As Integer?,
                             ByVal action As Char?,
                             ByVal status As Long?) As List(Of LightWeightTicket) Implements ITicketRepository.FindByUserID
    'Start a new session and run the query
    Using session As NHibernate.ISession = SessionFactory.GetNewSession()
        Dim query As NHibernate.IQuery = session.GetNamedQuery("Select_AllTickets_ByUserID_RyanTest")
        query.SetInt64("user_id", userID)
        Select Case custID.HasValue
            Case True
                query.SetInt64("cust_id", custID.Value)
            Case False
                query.SetString("cust_id", Nothing) 'SetString makes it NULL
        End Select
        Select Case String.IsNullOrWhiteSpace(company)
            Case True
                query.SetString("company", Nothing)
            Case False
                query.SetString("company", company) 'SetString makes it NULL
        End Select
        Select Case owner.HasValue
            Case True
                query.SetInt32("owner", owner.Value)
            Case False
                query.SetString("owner", Nothing) 'SetString makes it NULL
        End Select
        Select Case action.HasValue
            Case True
                query.SetCharacter("action", action.Value)
            Case False
                query.SetString("action", Nothing) 'SetString makes it NULL
        End Select
        Select Case status.HasValue
            Case True
                query.SetInt64("status", status.Value)
            Case False
                query.SetString("status", Nothing) 'SetString makes it NULL
        End Select
        query.SetInt64("startRowIndex", startRowIndex)
        query.SetInt64("maximumRows", maximumRows)
        Return New List(Of LightWeightTicket)(query.List(Of LightWeightTicket)())
    End Using
End Function

When I load the page, I receive the error "Capacity was less than the current size". The stack trace is per thus:

[ArgumentOutOfRangeException: capacity was less than the current size.

Parameter name: value]
System.Collections.ArrayList.set_Capacity(Int32 value) +9360651
System.Web.UI.WebControls.ListView.CreateChildControls(IEnumerable dataSource, Boolean dataBinding) +712
System.Web.UI.WebControls.ListView.PerformDataBinding(IEnumerable data) +35
System.Web.UI.WebControls.DataBoundControl.OnDataSourceViewSelectCallback(IEnumerable data) +128
System.Web.UI.DataSourceView.Select(DataSourceSelectArguments arguments, DataSourceViewSelectCallback callback) +33
System.Web.UI.WebControls.DataBoundControl.PerformSelect() +143
System.Web.UI.WebControls.ListView.PerformSelect() +113
System.Web.UI.WebControls.BaseDataBoundControl.DataBind() +74
System.Web.UI.WebControls.BaseDataBoundControl.EnsureDataBound() +66
System.Web.UI.WebControls.ListView.CreateChildControls() +55
System.Web.UI.Control.EnsureChildControls() +102
System.Web.UI.Control.PreRenderRecursiveInternal() +42
System.Web.UI.Control.PreRenderRecursiveInternal() +175
System.Web.UI.Control.PreRenderRecursiveInternal() +175
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2496

Does anyone know what to do about this?

Thanks in advance,

Ryan

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

痴者 2025-01-05 21:14:33

我解决了!

count 方法返回 System.Int64。当它被修改为 System.Int32 时,它起作用了!

I solved it!

The count method was returning a System.Int64. When this was amended to a System.Int32, it worked!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文