CodeSmith Community
Your Code. Your Way. Faster!

Wrong PageCount displayed in EntityGridView with Custom SelectMethod

Latest post 07-03-2007 5:15 PM by mike123. 5 replies.
  • 07-02-2007 9:54 PM

    • dotnetbob
    • Not Ranked
    • Joined on 04-02-2007
    • Posts 5
    • Points 115

    Crying [:'(] Wrong PageCount displayed in EntityGridView with Custom SelectMethod

    I have a Custom Stored Procedure that is returning 26 records. The page size dropdown has the following choices "10, 20, 30".  If I change the Page Size to 30, I can see all of my results. However, the Page Count is always 1.  Sorting does not work either.  I tryed to turn off pageing, but it always shows 10.  I tryed changing the page size to 50, but that did not work either.  The only option in the page size dropdown was 50 and I only saw the first 10 records.

    Custom Stored Procedure:

    CREATE PROCEDURE [dbo].[_Elements_GetByEquipmentTypeIDCategoryID]

    (

    @EquipmentTypeID int,

    @CategoryID int

    )

    AS

    SET ANSI_NULLS OFF

     

    SELECT Elements.[ElementID], Elements.[ElementName], Elements.[SubGroupName], Elements.[Required], Elements.[ListID]

    FROM Elements INNER JOIN CategoryElements ON Elements.ElementID = CategoryElements.ElementID INNER JOINCategories ON CategoryElements.CategoryID = Categories.CategoryID

    WHERE (Categories.EquipmentTypeID = @EquipmentTypeID AND @CategoryID = 0)

    OR (CategoryElements.CategoryID = @CategoryID)

     

    Select @@ROWCOUNT as TotalRowCount

    SET ANSI_NULLS ON

     

    On my page I have the following:

    <data:EntityGridView id="GridView1" runat="server"
     OnDataBound="GridView1_DataBound" DataSourceID="edsElements" OnRowDataBound="GridView1_RowDataBound"
     AutoGenerateColumns="False" OnSelectedIndexChanged="GridView1_SelectedIndexChanged" DataKeyNames="ElementID"
     AllowMultiColumnSorting="false" DefaultSortColumnName="" DefaultSortDirection="Ascending"
     ExcelExportFileName="Export_Elements.xls" PageSelectorPageSizeInterval="10" AllowSorting="True" AllowPaging="True">
     <Columns>
      <asp:CommandField ShowSelectButton="True" ShowEditButton="True"></asp:CommandField>
      <asp:BoundField DataField="ElementName" SortExpression="ElementName" HeaderText="Element Name"></asp:BoundField>
      <asp:BoundField DataField="SubGroupName" SortExpression="SubGroupName" HeaderText="Sub Group Name"></asp:BoundField>
      <data:BoundRadioButtonField DataField="Required" SortExpression="[Required]" HeaderText="Required"></data:BoundRadioButtonField>
      <data:HyperLinkField HeaderText="List" DataTextField="ListName" DataNavigateUrlFields="ListID" DataNavigateUrlFormatString="ListsEdit.aspx?ListID={0}" DataContainer="ListIDSource"></data:HyperLinkField>
      <asp:TemplateField ShowHeader="False">
       <ItemTemplate>
               <asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="False"
         CommandName="Delete" OnClientClick='return confirm("Are you sure you want to delete this entry?");'
                           Text="Delete" />         
       </ItemTemplate>
      </asp:TemplateField>
     </Columns>
     <EmptyDataTemplate>
      <b>No Elements Found!</b> 
     </EmptyDataTemplate>
    </data:EntityGridView>

    <data:ElementsDataSource ID="edsElements" runat="server" SelectMethod="GetByEquipmentTypeIDCategoryID"
            EnablePaging="True" EnableSorting="True" EnableDeepLoad="True">
     <DeepLoadProperties Method="IncludeChildren" Recursive="False">
             <Types>
                     <data:ElementsProperty Name="Lists" />
      </Types>
     </DeepLoadProperties>
            <Parameters>
      <asp:ControlParameter ControlID="EquipmentTypesDropDownList" Name="EquipmentTypeID"
                     PropertyName="SelectedValue" Type="Int32" />
                 <asp:ControlParameter ControlID="CategoriesDropDownList" Name="CategoryID" PropertyName="SelectedValue"
                     Type="Int32" />
                 <asp:ControlParameter Name="PageIndex" ControlID="GridView1" PropertyName="PageIndex"
                     Type="Int32" />
                 <asp:ControlParameter Name="PageSize" ControlID="GridView1" PropertyName="PageSize"
                     Type="Int32" />
                 <data:CustomParameter Name="RecordCount" Value="0" Type="Int32" />
            </Parameters>
    </data:ElementsDataSource>

     

    • Post Points: 35
  • 07-03-2007 8:41 AM In reply to

    • mike123
    • Top 10 Contributor
    • Joined on 02-25-2005
    • Toronto, Ontario
    • Posts 726
    • Points 16,910

    Re: Wrong PageCount displayed in EntityGridView with Custom SelectMethod

    Custom stored procs are handled a little bit different. You'd have to expose output @totalrecords parameter:

     CREATE PROCEDURE [dbo].[_Elements_GetByEquipmentTypeIDCategoryID]

    (

    @EquipmentTypeID int,

    @CategoryID int

    @totalrecords int = null OUTPUT

    )

    Then use CustomMethodRecordCountParamName to make ObjectDataSource aware of that

    data:ElementsDataSource ID="edsElements" runat="server" SelectMethod="GetByEquipmentTypeIDCategoryID"
            EnablePaging="True" EnableSorting="True" EnableDeepLoad="True" CustomMethodRecordCountParamName="totalrecords">
     <DeepLoadProperties Method="IncludeChildren" Recursive="False">
             <Types>
                     <data:ElementsProperty Name="Lists" />
      </Types>
     </DeepLoadProperties>
            <Parameters>
      <asp:ControlParameter ControlID="EquipmentTypesDropDownList" Name="EquipmentTypeID"
                     PropertyName="SelectedValue" Type="Int32" />
                 <asp:ControlParameter ControlID="CategoriesDropDownList" Name="CategoryID" PropertyName="SelectedValue"
                     Type="Int32" />
                 <asp:ControlParameter Name="PageIndex" ControlID="GridView1" PropertyName="PageIndex"
                     Type="Int32" />
                 <asp:ControlParameter Name="PageSize" ControlID="GridView1" PropertyName="PageSize"
                     Type="Int32" />
                 <asp:Parameter Name="totalrecords" Type="Int32" Direction="InputOutput" />
            </Parameters>
    </data:ElementsDataSource>

    See it that helps

     

    Mike Shatny
    --------------------------------------------------------------
    Member of the .netTiers team http://www.nettiers.com
    --------------------------------------------------------------

    • Post Points: 35
  • 07-03-2007 1:35 PM In reply to

    • dotnetbob
    • Not Ranked
    • Joined on 04-02-2007
    • Posts 5
    • Points 115

    RE: Wrong PageCount displayed in EntityGridView with Custom SelectMethod

    That looks like a great property but it still only shows one page.

     

    PageCount Bug.bmp

    If I change the Records Per Page to 30, I see all records.

    I think I did what you said below.  Here is my SP:

     

    CREATE PROCEDURE [dbo].[_Elements_GetByEquipmentTypeIDCategoryID]

    (

          @EquipmentTypeID int,

          @CategoryID int,

          @TotalRecords int= null OUTPUT

    )

    AS

                            SETANSI_NULLS OFF

                            SET@TotalRecords = @@ROWCOUNT;

                            SETANSI_NULLS ON

     

    Here is my new code:

    <data:EntityGridView id="GridView1" runat="server" DataSourceID="edsElements"

        AllowPaging="True" AllowSorting="True" PageSelectorPageSizeInterval="10"

        ExcelExportFileName="Export_Elements.xls" DefaultSortDirection="Ascending"

        DefaultSortColumnName="" AllowMultiColumnSorting="false" DataKeyNames="ElementID"

        OnSelectedIndexChanged="GridView1_SelectedIndexChanged" AutoGenerateColumns="False"

        OnRowDataBound="GridView1_RowDataBound">

        <Columns>

            <asp:CommandField ShowSelectButton="True" ShowEditButton="True"></asp:CommandField>

            <asp:BoundField DataField="ElementName" SortExpression="ElementName" HeaderText="Element Name"></asp:BoundField>

        <data:ElementsDataSource id="edsElements" runat="server" SelectMethod="GetByEquipmentTypeIDCategoryID"

            EnableDeepLoad="True" EnableSorting="True" EnablePaging="True"

            CustomMethodRecordCountParamName="TotalRecords">

            <DeepLoadProperties Method="IncludeChildren" Recursive="False">

                <Types>

                    <data:ElementsProperty Name="Lists" />

                    <data:ElementsProperty Name="ControlTypes" />

                </Types>

            </DeepLoadProperties>

            <Parameters>

                <asp:ControlParameter ControlID="EquipmentTypesDropDownList" Name="EquipmentTypeID"

                    PropertyName="SelectedValue" Type="Int32" />

                <asp:ControlParameter ControlID="CategoriesDropDownList" Name="CategoryID"PropertyName="SelectedValue"

                    Type="Int32" />

                <asp:ControlParameter Name="PageIndex" ControlID="GridView1" PropertyName="PageIndex"

                    Type="Int32" />

                <asp:ControlParameter Name="PageSize" ControlID="GridView1" PropertyName="PageSize"

                    Type="Int32" />

                <asp:Parameter Name="TotalRecords" Type="Int32" Direction="InputOutput" />

            </Parameters>

       </data:ElementsDataSource>

     

     

    From: mike123[mailto:bounce-mike123@codesmithsupport.com]
    Sent: Tuesday, July 03, 2007 9:46 AM
    To: dotnetbob@gmail.com
    Subject: Re: [.netTiers Bug Reports] Wrong PageCount displayed inEntityGridView with Custom SelectMethod

     

    Custom stored procs are handled a little bit different. You'd have to exposeoutput @totalrecords parameter:

     CREATE PROCEDURE [dbo].[_Elements_GetByEquipmentTypeIDCategoryID]

    (

    @EquipmentTypeID int,

    @CategoryID int

    @totalrecords int = null OUTPUT

    )

    Then use CustomMethodRecordCountParamNameto make ObjectDataSource aware of that

    data:ElementsDataSourceID="edsElements" runat="server"SelectMethod="GetByEquipmentTypeIDCategoryID"
            EnablePaging="True"EnableSorting="True" EnableDeepLoad="True"
    CustomMethodRecordCountParamName="totalrecords">
     <DeepLoadProperties Method="IncludeChildren"Recursive="False">
             <Types>
                    <data:ElementsProperty Name="Lists" />
      </Types>
     </DeepLoadProperties>
            <Parameters>
      <asp:ControlParameterControlID="EquipmentTypesDropDownList"Name="EquipmentTypeID"
                    PropertyName="SelectedValue" Type="Int32" />
                <asp:ControlParameter ControlID="CategoriesDropDownList"Name="CategoryID" PropertyName="SelectedValue"
                    Type="Int32" />
                <asp:ControlParameter Name="PageIndex"ControlID="GridView1" PropertyName="PageIndex"
                    Type="Int32" />
                <asp:ControlParameter Name="PageSize"ControlID="GridView1" PropertyName="PageSize"
                    Type="Int32" />
                 <asp:Parameter Name="totalrecords"Type="Int32" Direction="InputOutput" />
            </Parameters>
    </data:ElementsDataSource>

    See it that helps

     




    • Post Points: 5
  • 07-03-2007 2:50 PM In reply to

    • dotnetbob
    • Not Ranked
    • Joined on 04-02-2007
    • Posts 5
    • Points 115

    RE: Wrong PageCount displayed in EntityGridView with Custom SelectMethod

    Thanks a LOT!  That did it.  Ignore my last email.  For somereason, I did not regenerate certain files…

    I regenerated the code a second time and ran the test again.  Itworks perfectly.

    WOW!  Thanks again.

     

    • Post Points: 5
  • 07-03-2007 3:20 PM In reply to

    • dotnetbob
    • Not Ranked
    • Joined on 04-02-2007
    • Posts 5
    • Points 115

    RE: Wrong PageCount displayed in EntityGridView with Custom SelectMethod

    Great!  That fixed the page count problem.  Is there somethingelse I have to do to get sorting to work too? I researched it and I am almostready to give up.

    I now a EntityDataSource has a sort property, however I see alot of comments that say it cannot be done for GetByXXX methods and custom sprocs. They suggest that if you want sorting supported, you have to do one of thefollowing:

    1)     Use GetPaged

    2)     Use Find

    3)     Build it into your own sproc.

    Is this true, or is there something else I can do?

    • Post Points: 35
  • 07-03-2007 5:15 PM In reply to

    • mike123
    • Top 10 Contributor
    • Joined on 02-25-2005
    • Toronto, Ontario
    • Posts 726
    • Points 16,910

    Re: Wrong PageCount displayed in EntityGridView with Custom SelectMethod

    You could eigther build the Sorting into sp or try the following:

        protected void Page_Load(object sender, EventArgs e)
       {
            GridView1.Sorting += new GridViewSortEventHandler(GridView1_Sorting);
            ProductsDataSource.Selected += new ObjectDataSourceStatusEventHandler(ProductsDataSource_Selected);    
        }

        void GridView1_Sorting(object sender, GridViewSortEventArgs e)
        {
            GridView1.DataBind();       
        }

        void ProductsDataSource_Selected(object sender, ObjectDataSourceStatusEventArgs e)
        {
            TList<Northwind.Entities.Products> tlist = e.ReturnValue as TList<Northwind.Entities.Products>;
            if (GridView1.SortDirection == SortDirection.Descending)
                tlist.Sort(string.Format("{0} {1}", GridView1.SortExpression, "ASC"));      
            else
                tlist.Sort(string.Format("{0} {1}", GridView1.SortExpression, "DESC"));      
        }  



     
    On 3 Jul 2007 15:21:24 -0500, dotnetbob <bounce-dotnetbob@codesmithsupport.com> wrote:

    Great!  That fixed the page count problem.  Is there somethingelse I have to do to get sorting to work too? I researched it and I am almostready to give up.

    I now a EntityDataSource has a sort property, however I see alot of comments that say it cannot be done for GetByXXX methods and custom sprocs. They suggest that if you want sorting supported, you have to do one of thefollowing:

    1)     Use GetPaged

    2)     Use Find

    3)     Build it into your own sproc.

    Is this true, or is there something else I can do?





    Mike Shatny
    --------------------------------------------------------------
    Member of the .netTiers team http://www.nettiers.com
    --------------------------------------------------------------

    • Post Points: 5
Page 1 of 1 (6 items) | RSS
Copyright © 2008 CodeSmith Tools, LLC
Powered by Community Server (Commercial Edition), by Telligent Systems