DropDownList DataBinding firing twice. Please help!

  • Thread starter Thread starter hwiechers
  • Start date Start date
H

hwiechers

I have two drop down lists on a page. Each one is hooked up to a
separate SqlDataSource. The second data source has a ControlParameter
set to the selected value of the first drop down. When I set the
SelectedValue of the first drop down in Page_Load, the DataBinding
event of the second fires twice. This causes the second drop down to
have duplicate values. Try as I might I haven't been able to get this
to work. Does anyone have a solution for this problem?
 
The first thing is the problem: dupe values. You can cure this by clearing
the list in each bind. It will still fire twice, which should be solved, but
you will avoid the dupes. (BTW, dupes are not really a bad thing for system
operation, as you will end up with the right answer; but, they sure are a
major annoyance to the people who pay our paychecks ;->).

The second thing is firgure out what is causing the double binig. My guess
is you have the first dropdown set to populate the second onChange and you
are binding the second first, with a default set of values, and then the
first, which then fires its event. Have not seen this in ASP.NET, but I
regard it as a possibility. If this is correct, you need to reorder the
bindings OR attach the postback event after you have bound control #1.

Without having code to debug through, I can only guess, however.

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA
http://gregorybeamer.spaces.live.com

*************************************************
Think outside of the box!
*************************************************
 
I think I've solved the problem. I wasn't actually calling DataBind at
all, just relying on the automatic databinding. I found that if I
called DataBind myself the automatic databinding wouldn't fire and the
thing would work. So now I just call DataBind on each DropDownList as I
set them. (This is only when !IsPostBack. It seems to work correctly
during postbacks.)
 
Back
Top