Click here to Skip to main content
15,919,774 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi , i have created small web application, in my web application, i have drop-down list in that drop-down list i am binding some data's from my database on my web page load event, but here the problem is by default the drop-down list is in selected index 0, i want to set the null value in my drop-down list, i mean the selected index should be -1, how shall i do this.....please give me some sample code
Posted

You can add a blank entry and set it as first option and selected. something like:
C#
ddlist.Items.Insert(0, new ListItem(String.Empty, String.Empty)); 
ddlist.SelectedIndex = 0;
 
Share this answer
 
Comments
sameertm 13-Jan-12 2:33am    
hi dear, i tried your code,its working fine, but the problem is, that empty string is in added into the list, i don want to show that empty string into my data list
Hi,

In Page load event,

C#
ddl1.SelectedIndex = -1;

or

Insert an item into the ddl as "Select" or empty.

like,
C#
drpList.Items.Insert(0, new ListItem(String.Empty, String.Empty));
drpList.SelectedIndex = 0;
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900