Results 1 to 5 of 5

Thread: DataGrid paging "previous" event failure

  1. #1
    Join Date
    Nov 2003
    Derby, UK

    DataGrid paging "previous" event failure

    Greetings :-)

    I'm having trouble getting the paging to work on one of my DataGrid web controls. The following C# code lives behind a simple ASPX page containing a single PlaceHolder control...
    PHP Code:
    private void Page_Load(object senderSystem.EventArgs e)
    // Create a table, column and 25 rows
    DataTable obDataTable = new DataTable"testtable" );
    obDataTable.Columns.Add( new DataColumn"testcol1" ) );
        for ( 
    int iLoop=0iLoop<25iLoop++ )
    obDataTable.Rows.Add( new object[] { "a" iLoop.ToString() } );

    // Create datagrid and set the paging to 10
    DataGrid obDataGrid = new DataGrid();
    obDataGrid.AllowPaging true;
    obDataGrid.PageSize 10;
    obDataGrid.PageIndexChanged += new 
    DataGridPageChangedEventHandlerPageChanged );

    // Set the Data source, bind and add to the placeholder
    obDataGrid.DataSource obDataTable.DefaultView;
    PlaceHolder1.Controls.AddobDataGrid );

    void PageChangedobject objSender
    DataGridPageChangedEventArgs eArgs )
    // Cast the datagrid and set the page index
    DataGrid obDataGrid = (DataGrid)objSender;
    obDataGrid.CurrentPageIndex eArgs.NewPageIndex;

    Moving forward through the pages works correctly, and I can breakpoint in the PageChanged handler. However the Previous button does not fire the event handler (but does fire Page_Load) and the data on screen becomes corrupt.
    Using the above code, the 3 pages show correctly, but clicking Previous on the 3rd page (which has the last 5 entries) produces a page showing the same 5 entries, plus the last 5 entries from the 1st page.
    This can be also be reproduced with the PagerStyle.Mode set to Numbered.

    Does anybody have any ideas? Why is the event handler not being called for the Previous button? Any help would be greatly appreciated.

    I am not young enough to know everything - Oscar Wilde

  2. #2
    Join Date
    Nov 2002
    Auburn, AL
    I do not use c# enough and have not experienced this problem before in vb.net so I will not be able help you figure out this specific problem, but just in general I would say write your own pageing code, custum pageing, instead of relying on the built in asp.net pageing because if you do your own code you will have more control over it and it will be valid, you do not have to worrie about how asp.net outputs js without a type attribute, and so on and so fourth. I am not doing anypaging right now but a blog I am working on will only show results from the past most and put the rest into the archive, which I actuall probably will end up pageing when this is all done, but when I used the built in pageing back in the day I did not like it because it gave me very limited control over the look and feel of it. Just out of curiosity, why are you using the place holder control, doesn't that output a table? Why wouldn't you use a <div runat="server">? This is just out of my curiosity, because I find myself running a bunch of html elements at the server to get more source control.

  3. #3
    Join Date
    Nov 2003
    Derby, UK
    Thanks for your reply :-)

    I have to agree with you about the DataGrids seemingly appauling control over the appearance of things like the paging.
    Also, unless I'm being stupid - which is highly possible - there doesn't seem to be a way to set a CssClass property on any of the controls within the DataGrid (in particular the <A> tag that is created for the title in sortable columns).

    But your suggestion of writing my own custom paging looks like it is going to be the answer - unfortunate, as we're looking at a pretty hefty deadline.

    The PlaceHolder control does not produce a table - it is used as more of a marker for the positioning of dynamically created ASP.NET HTML code.
    From MSDN "Use the PlaceHolder control as a container to store dynamically added server controls to the Web page. The PlaceHolder control does not produce any visible output and is only used as a container for other controls on the Web page."
    Do a quick test - make a simple "<html><body><asp:PlaceHolder ID="phTest"/></body></html>" page, and add a single Label object to the controls collection. The result is just a <span> tag (and associated attributes), nothing else.
    I am not young enough to know everything - Oscar Wilde

  4. #4
    Join Date
    Nov 2002
    Auburn, AL
    well does it have to infact be pageing? I wqould say count the rows from the gird like before, then divide it by 10. Then show the first 10 results, then show the next 10 when the user clicks on the next button (multiply the page# (which will incriment when the user clicks it) by 10 then add another 10 and you have your beginning and end numbers, page# * 10 = your start, page# * 10 + 10 = your end), so on and so fourth until he is on the last page where you would make the button disabled or no longer visible. A button would be good because it just resends the data, but you could also use a query string and redirect that user to the same page he was on but with the query string for the page number and it will run that page load select event and get the number of entries again too, which would look better but be slightly less efficient (but probably not noticable). You could also use the linkbutton element, to avoid this, but that element will create a java script even though it will resend the page. I try to avoid asp.net outputting js at all costs.
    Last edited by PeOfEo; 04-23-2004 at 04:10 PM.

  5. #5
    Join Date
    Aug 2005

    Have this issue been solved?

    I met the same problem. Just wonder if it has been solved.


Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center



X vBulletin 4.2.2 Debug Information

  • Page Generation 0.11570 seconds
  • Memory Usage 2,894KB
  • Queries Executed 13 (?)
More Information
Template Usage (33):
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_global_above_footer
  • (1)ad_global_below_navbar
  • (1)ad_global_header1
  • (1)ad_global_header2
  • (1)ad_navbar_below
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (1)ad_thread_first_post_content
  • (1)ad_thread_last_post_content
  • (1)bbcode_php
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)headinclude_bottom
  • (5)memberaction_dropdown
  • (1)navbar
  • (4)navbar_link
  • (1)navbar_moderation
  • (1)navbar_noticebit
  • (1)navbar_tabs
  • (2)option
  • (5)postbit
  • (5)postbit_onlinestatus
  • (5)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available (6):
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files (26):
  • ./showthread.php
  • ./global.php
  • ./includes/class_bootstrap.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/functions_navigation.php
  • ./includes/class_friendly_url.php
  • ./includes/class_hook.php
  • ./includes/class_bootstrap_framework.php
  • ./vb/vb.php
  • ./vb/phrase.php
  • ./includes/functions_facebook.php
  • ./includes/functions_calendar.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_notice.php
  • ./packages/vbattach/attach.php
  • ./vb/types.php
  • ./vb/cache.php
  • ./vb/cache/db.php
  • ./vb/cache/observer/db.php
  • ./vb/cache/observer.php 

Hooks Called (70):
  • init_startup
  • friendlyurl_resolve_class
  • init_startup_session_setup_start
  • database_pre_fetch_array
  • database_post_fetch_array
  • init_startup_session_setup_complete
  • global_bootstrap_init_start
  • global_bootstrap_init_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • load_show_variables
  • load_forum_show_variables
  • global_state_check
  • global_bootstrap_complete
  • global_start
  • style_fetch
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • strip_bbcode
  • friendlyurl_clean_fragment
  • friendlyurl_geturl
  • forumjump
  • cache_templates
  • cache_templates_process
  • template_register_var
  • template_render_output
  • fetch_template_start
  • fetch_template_complete
  • parse_templates
  • fetch_musername
  • notices_check_start
  • notices_noticebit
  • process_templates_complete
  • friendlyurl_redirect_canonical
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • bbcode_parse_start
  • postbit_imicons
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • memberaction_dropdown
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • build_navigation_data
  • build_navigation_array
  • check_navigation_permission
  • process_navigation_links_start
  • process_navigation_links_complete
  • set_navigation_menu_element
  • build_navigation_menudata
  • build_navigation_listdata
  • build_navigation_list
  • set_navigation_tab_main
  • set_navigation_tab_fallback
  • navigation_tab_complete
  • fb_like_button
  • showthread_complete
  • page_templates