ASP.NET 2 and dropdownlists

Soldato
Joined
12 Jan 2004
Posts
6,824
Location
Londinium
Hey guys,

i'm trying to add a default item to a dropdown list that is bbound to a data source. I can do this if I bind the ddl to the ds in code, but if I set the ds in the DataSourceID property of the ddl then adding the default option in code does not work (I guess as the ddl is bound after the code to add the default item is run).

I want to reduce the code so I want to be able to use the ddl tag properties to set the ds but need to add the default item somewhere. Can anyone tell me how to do this?
 
Answered my own question! You just add the default list item as normal and then set the AppendDataBoundItems to true. Et viola! :)
 
nero120 said:
Hey guys,

i'm trying to add a default item to a dropdown list that is bbound to a data source. I can do this if I bind the ddl to the ds in code, but if I set the ds in the DataSourceID property of the ddl then adding the default option in code does not work (I guess as the ddl is bound after the code to add the default item is run).

I want to reduce the code so I want to be able to use the ddl tag properties to set the ds but need to add the default item somewhere. Can anyone tell me how to do this?

Can you post the code on the page concerning the DDL that you already have?

Usually this is done by setting the 'AutoAppendDataItems' attribute on the drop down list to 'true', then adding the items in as if you were adding them explicitly. Any datasource you have connected should then add their items after the explicit ones..

Edit: never mind, I see you've fixed it :) and 'AppendDataBoundItems' was the one I was after, not 'AutoAppendDataItems'!
 
Back
Top Bottom