Wrox Programmer Forums
|
BOOK: ASP.NET 3.5 Enterprise Application Development with Visual Studio 2008: Problem Design Solutio
This is the forum to discuss the Wrox book ASP.NET 3.5 Enterprise Application Development with Visual Studio 2008: Problem Design Solution by Vincent Varallo; ISBN: 9780470396865
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: ASP.NET 3.5 Enterprise Application Development with Visual Studio 2008: Problem Design Solutio section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old January 10th, 2010, 04:52 AM
Registered User
 
Join Date: Jan 2010
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default LoadMethodParameters lost when paging/sorting

With a customgridview using LoadMethodParameters, the gridview will load successfully the first time the page is loaded. But when using the paging or sorting links the following error occurs: System.MissingMethodException
...method not found.

This error does not happen for any method without parameters. It's as if these parameters are lost.

Here is the code:

Code:
if (!IsPostBack)
{
cgvKBArticles.ListClassName = typeof(KBArticleEOList).AssemblyQualifiedName;

cgvKBArticles.LoadMethodName = "LoadByTopic";
cgvKBArticles.LoadMethodParameters.Add(topicId);

cgvKBArticles.AddBoundField("", "Actions", "");
cgvKBArticles.AddBoundField("TopicName", "Topic", "TopicName");

cgvKBArticles.DataBind();
}
(topicId is an int from the querystring)

If I remove the IsPostBack if statement, the paging/sorting works on the above example but the gridview columns get duplicated.

I noticed that the methodparameters are not stored in viewstate in the CustomGridView class. Is this causing the problem or am I missing something else?

Thanks in advance.
 
Old January 17th, 2010, 12:37 AM
ocn ocn is offline
Authorized User
 
Join Date: Jun 2009
Posts: 15
Thanks: 5
Thanked 0 Times in 0 Posts
Default

I have the same problem. Does anyone have a solution for it?

Thanks!
 
Old January 18th, 2010, 05:27 PM
Registered User
 
Join Date: Jan 2010
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I've updated the CustomGridView class to save the methodParameters to viewstate. Now the paging and sorting works.

Code:
        public ArrayList LoadMethodParameters
        {
            get
            {
                if (ViewState["LoadMethodParameters"] == null)
                    return _methodParameters;
                else
                    return (ArrayList)ViewState["LoadMethodParameters"];
            }

            set { ViewState["LoadMethodParameters"] = value; }
        }

...

        private void BindGridView(string sortExpression, SortDirection sortDirection)
        {
            //Create an instance of the list object
            Type objectType = Type.GetType(ListClassName);
            object listObject = Activator.CreateInstance(objectType);

            //Call the method to load the object
            //objectType.InvokeMember(LoadMethodName, BindingFlags.InvokeMethod, null, listObject, new object[] { });
            objectType.InvokeMember(LoadMethodName, BindingFlags.InvokeMethod, null, listObject, LoadMethodParameters.ToArray());

            //Call the SortByPropertyName method.  This is in the ENTBaseBOList class.  The object must inherit
            //from this class.
            base.DataSource = objectType.InvokeMember("SortByPropertyName", BindingFlags.InvokeMethod, null, listObject, new object[] { sortExpression, sortDirection == SortDirection.Ascending });
            base.DataBind();

            //Save the sortExpression and sortDirection to the view state.
            SortExpressionLast = sortExpression;
            SortDirectionLast = sortDirection;
            LoadMethodParameters = LoadMethodParameters;

            objectType = null;
            listObject = null;
        }
Is there a more efficient way to do it or is this the best way?





Similar Threads
Thread Thread Starter Forum Replies Last Post
Sorting and Paging of gridview lily611 C# 2005 0 April 24th, 2008 03:09 AM
custom paging and sorting? asptwodev BOOK: ASP.NET 2.0 Instant Results ISBN: 978-0-471-74951-6 2 September 22nd, 2007 02:06 AM
Sorting and Paging GridView using Alphabets yukijocelyn ASP.NET 2.0 Basics 9 August 29th, 2007 04:05 PM
Sorting problem (Paging) pat123 XSLT 9 January 30th, 2007 01:00 PM
Sorting and Paging conflict comicghozt ASP.NET 1.0 and 1.1 Basics 0 June 8th, 2006 02:31 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.