German Wear Discount Shop - Click Here Write for Dotnet-friends and earn for your each submission [Dot]Net-Friends
Skip Navigation Links
Home
Latest
Fast Code
Articles
Tutorials
Online Resources
Forums
Login   | Hi, Guest


Dropdownlist or ComboBox default Value/Text using C#

Written by omerkamal on Mar 28, 2007
How to make an item as a Default Item of a DropdownList using C-Sharp in ASP .NET

Explanation:


1. In an ASP .NET Page side code use Selected="True" with the Node



Male
Female
Prefer not to declare


2. In the ASP .NET code behind:

· If you only care about the First item selection: 

ListItem item1=new ListItem("ItemText1","ItemVal1");
ListItem item2 = new ListItem("ItemText2", "ItemVal2");
item1.Selected = true;

DropDownList1.Items.Add(item1);
DropDownList1.Items.Add(item2);


· If you want to make sure about the index of more Itemes 

ListItem item1=new ListItem("ItemText1","ItemVal1");
ListItem item2 = new ListItem("ItemText2", "ItemVal2");

DropDownList1.Items.Insert(0, item1);
DropDownList1.Items.Insert(1, item2);


By Default, the every next item is inserted after the Previously added Item i.e.

Index of last added Item = Index of Previously added Item + 1
Visitors/Readers Comments
(for questions please use The Forum)



Reena
Sir I have a Dropdownlist which i have bound with a master table in database.when data will going large then that dropdownlist will create problem..so please suggest me that how can i make that dropdownlist easy.

14/06/2007 00:06:23 UTC

kamal

Do you mean about showing alot of data inside the Dropdown? like you have to show more then 1000 values inside the list.

If this is the case then one solution would be to make it auto-complete dropdownlistbox. when some one start typing in the box it will only show the values starts from enterd piece of alphabits. You can use Ajax control Auto-Complete for that.

see the sample here:

http://ajax.asp.net/ajaxtoolkit/AutoComplete/AutoComplete.aspx

14/06/2007 04:02:01 UTC

er
ddl.Items.Insert(5, new ListItem("B: 80-86%", "B"));

30/10/2007 13:49:48 UTC

blb
i want toa that , seclected from dropdownlist and whole information show in textbox

25/09/2008 02:39:37 UTC

Ramesh
how to create the row and column in comboBox? not datagridview.

13/10/2008 05:01:03 UTC




Add your Comments

Name:  
Message:
Note: For faster response please use Forums >> for your questions instead of the comments area! (Admin)