dropdownlist and sqldatasource

Soldato
Joined
8 Mar 2005
Posts
3,676
Location
London, UK
So,
I have a dropdownlist which will populate a gridview depending on selection. However I wish to have a default additional listitem which will populate the gridview with all records as follows which works as expected:

<asp:ListItem Selected="true" Text="All Business units" value="-1" />

When page launches, gridview populates all records and the dropdown is populated with the conditions (in this case business units). However when I attempt to select one of those conditions I then get the standard error "Conversion failed when converting the nvarchar value (CONDITION) to data type int."

The sql which runs from the condition is as follows:
SELECT aMY, CallCountFail, CallCountPass, BUSINESS_UNIT FROM vw_RAA_REM_MONTH_SLA_C WHERE (BUSINESS_UNIT = @BUSINESS_UNIT OR @BUSINESS_UNIT = - 1) AND (aMY = @Amy)

If I drop the sql in italic it functions as expected minus showing all records as default on page load.

Seemingly it burps at the fact the default listitem is anegative INT as opposed to the CONDITONS being an alphanumeric, but I would have thought that would be irrelevant in this instance?.

Any pointers much appreciated.

Cheers, Paul.
 
Soldato
OP
Joined
8 Mar 2005
Posts
3,676
Location
London, UK
Wow, it was as simple as that! Many thanks.

An additional side effect of using listitem with appenddatabounditem is that I now see 2 entries for each business unit within the dropdownlist. Is there a way to remove the duplicated entries? the select query which generates the dropdownlist only returns distinct names, and if i remove the appenddatabounditem the duplicates disappear along with the default all records listitem.

In actual fact, as you may see from the above query this is actually a dropdownlist which hangs off another one, If I change the other dropdownlist it then duplicates another set of CONDITONS on the second.

cheers, Paul.

EDIT - however on page load those duplicates are present until I select another field on dropdownlist1 and then it refreshes dropdownlist2 without the duplicates, odd.
 
Last edited:
Back
Top Bottom