[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 266
  • Last Modified:

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

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 asp.net doing this in the first place??  the code is not specifically launching the change event.

thanks in advanced
0
aaalife
Asked:
aaalife
  • 2
  • 2
1 Solution
 
nauman_ahmedCommented:
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");

-Nauman.
0
 
TornadoVCommented:
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";
        dropdown.DataBind();
}

0
 
aaalifeAuthor Commented:
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 asp.net 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.  
0
 
nauman_ahmedCommented:
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.

-Nauman.
0
 
aaalifeAuthor Commented:
found the problem, finally!  buggy code.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now