| Join | Help
in

Strong Coders Community

Where the extreme coders hang out.

GridView issue - paging/sorting - any ideas would be appreciated

Last post 07-24-2007 12:37 PM by rvarcher . 1 replies.
Page 1 of 1 (2 items)
Sort Posts: Previous Next
  • 04-26-2007 6:09 AM
    • mcs130
    • Top 100 Contributor
    • Joined on 04-26-2007
    • Posts 1
    • Points 20

    GridView issue - paging/sorting - any ideas would be appreciated

    Reply Contact

    I would sincerely appreciate it if someone could explain the following issue experienced w/ 2 different methods of GridView creation for an ASP.NET 2.0 page.  In the following code snippet taking from one of my .aspx files I create a GridView bound to the ObjectDataSource shown.  That ObjectDataSource is bound to a BL layer class and method that simply returns a DataTable object (SelectMethod="getSysDataTable").  Paging and Sorting are set to True and each of those functions works perfectly.  In the code-behind file for this .aspx file there is no code or events written for the GridView (no paging or sorting event handlers), just a few button and text box handlers on that page that are needed.  The paging and sorting of the presented data works w/o any issue. 

       BorderStyle="Solid" BorderWidth="1px" CellPadding="3" ForeColor="Black" GridLines="Vertical" AllowPaging="True" AllowSorting="True" EmptyDataText="No records found"
     PageSize="5" >
     
           DataTextFormatString="Select" HeaderText="Edit" />
        
        
      

     

     

    On another .aspx page however, I am doing a similar GridView w/ an ObjectDataSource only it is done in a slightly different manner

       BorderStyle="Solid" BorderWidth="1px" CellPadding="3" ForeColor="Black" GridLines="Vertical" AllowPaging="True" AllowSorting="True" EmptyDataText="No records found" PageSize="5">
     
           DataTextFormatString="Select" HeaderText="Edit" />
        
        
        
        
        
        
     

     
    .

    Note the main difference (aside from the bound columns) - no ObjectDataSource is specified on the .aspx page hence the DataSourceID property of the GridView is not set yet.  However, now in the .aspx.cs code-behind for this page, I do the following:


     protected void Page_Load(object sender, EventArgs e)
     {
      if (!Page.IsPostBack)
      {
          BindData();
      }
     }   

     private void BindData()
     {

      ObjectDataSource obds = new ObjectDataSource();
      obds.TypeName = "BatchSummaryVwDAO";  // again a simple BL class that calls an external API that returns a typed Array[] of objects.
      obds.SelectMethod = "getBatchSummaryDataTable"; // a method on that class that then returns a DataTable object created from the typed Array[] of objects.
      obds.DataBind();
      GridViewMonitor.DataSource = obds;
      GridViewMonitor.DataBind();
     }

     The page renders fine initially w/ the GridView data displayed - but if I attempt to "page" by clicking the paging control or "sort" by clicking one of the column header titles, I get unhandled Exceptions thrown stating either:

     GridViewMonitor fired event PageIndexChanging which wasn't handled

     or

     GridViewMonitor fired event Sorting which wasn't handled.

    The BIG QUESTION - why in the first scenario does paging and sorting work w/o having to write handler logic for each yet in the second scenario, you get these exceptions.  It seems that I am wiring everything together and binding to DataTables the same way...in one case "declaratively" in the aspx page and in the other programmatically in the .aspx.cs code-behind.  Any advice would be really appreciated.

    Thanks in advance

    • Post Points: 20
  • 07-24-2007 12:37 PM In reply to
    • rvarcher
    • Top 100 Contributor
    • Joined on 07-24-2007
    • Posts 1
    • Points 5

    Re: GridView issue - paging/sorting - any ideas would be appreciated

    Reply Contact

    I was also getting the Your gridview xxx "fired event Sorting which wasn't handled"

    It took hours to find the fix.

    I found this on the Microsoft page about the GridView class: http://msdn2.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview(VS.80).aspx

    =======================

    Binding to Data

    The GridView control can be bound to a data source control (such as SqlDataSource , ObjectDataSource , and so on), as well as any data source that implements the System.Collections.IEnumerable interface (such as System.Data.DataView , System.Collections.ArrayList , or System.Collections.Hashtable ). Use one of the following methods to bind the GridView control to the appropriate data source type:

    • To bind to a data source control, set the DataSourceID property of the GridView control to the ID value of the data source control. The GridView control automatically binds to the specified data source control and can take advantage of the data source control's capabilities to perform sorting, updating, deleting, and paging functionality. This is the preferred method to bind to data.

    • To bind to a data source that implements the System.Collections.IEnumerable interface, programmatically set the DataSource property of the GridView control to the data source and then call the DataBind method. When using this method, the GridView control does not provide built-in sorting, updating, deleting, and paging functionality. You need to provide this functionality by using the appropriate event.

     =============================

    The DataBind() method DOES NOT provide built-in sorting, updating, deleting and paging!

     Hope this helps.

     - bob archer

    Filed under: "fired event Sorting which wasn't handled"
    • Post Points: 5
Page 1 of 1 (2 items)

Copyright © 2006-2007 Strong Coders Community. All rights reserved.
Privacy Statement | Terms Of Use | Advertise with us | Site Feedback

Powered by Community Server (Commercial Edition), by Telligent Systems