gridview sort triggering drop down select index changed??????

Posted on 2006-05-10
Last Modified: 2008-01-09
hi all, i've got a web app that has a drop down box with values day/week/month/year which populates a datagrid with the appropriate sales values.  the drop down has autopostback = true, so when changing from time frame values, the grid is repopulated.

the columns in the datagrid are sortable, so if column a is clicked, sort is ascending, if column a is clicked again, sort is descending.  

i noticed the sorting was taking more time than usual, while watching debug path of execution, turns out when you click a column to sort, the dropdown index changed event is fired, then the sorting routine is called.  why??????

how can i prevent .net from triggering the drop down index changed value from firing when user is just sorting???  and more specifically, why is doing this in the first place??  the code is not specifically launching the change event.

thanks in advanced
Question by:aaalife
    LVL 25

    Expert Comment

    I tried but when the GridView is sorted the drop-down IndexChanged event didnt fired. It can be something else in your code that is causing this event to fire for e.g. you may be setting the selected item index somewhere in teh code. On Drop-Down selected index changed even, write a debugging statement and see the results:

    Response.Write("index changed");

    LVL 11

    Expert Comment

    Just a guess, do you populate your dropdown on a page load? If yes try the following:

    if (!IsPostBack)
            dropdown.DataSource = someSource;
            dropdown.DataTextField = "yourText";


    Author Comment

    when i run in debug mode and click column header to sort, the page load event is fired then the drop down index changed event is fired.  there is logic to call the inex changed event for drop down but only when the page is not a postback, and the sort action is considered a postback so that's not where the call is coming from.

    the code has an onsort = "sortroutine" for the gridview, and the drop down has an onselectedindexchanged="timeframechange".

    no other logic is there to call the selectedindexchanged routine.

    the code above from tonadov, i don't have a datasource for the grid, just text values for day/week/month/year in the properties.  
    LVL 25

    Accepted Solution

    I think you should check the code again. Even when the Page is not posted back, if you call Me.DropDownList1.SelectedIndex = 0, the SelectedIndexChanged event will fire.


    Author Comment

    found the problem, finally!  buggy code.

    Featured Post

    6 Surprising Benefits of Threat Intelligence

    All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

    Join & Write a Comment

    This article discusses the ASP.NET AJAX ModalPopupExtender control. In this article we will show how to use the ModalPopupExtender control, how to display/show/call the ASP.NET AJAX ModalPopupExtender control from javascript, how to show/display/cal…
    I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
    Hi everyone! This is Experts Exchange customer support.  This quick video will show you how to change your primary email address.  If you have any questions, then please Write a Comment below!
    In this sixth video of the Xpdf series, we discuss and demonstrate the PDFtoPNG utility, which converts a multi-page PDF file to separate color, grayscale, or monochrome PNG files, creating one PNG file for each page in the PDF. It does this via a c…

    745 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    13 Experts available now in Live!

    Get 1:1 Help Now