In this example, I would like to tell you that how to bind a Generic List to DropDownList server control in asp.net page. Let’s start
Open your Visual Studio 2008/2010 and create a website, I will consider here that you know how to create a website in Visual Studio 2008/2010.
First I have created a DDList class in Default.aspx.cs/vb page to bind DropDownList server control.
C#
public class DDList
{
public string Item { get; set; }
public string value { get; set; }
}
VB.NET
Public Class DDList
Public Property Item() As String
Get
Return m_Item
End Get
Set(ByVal value As String)
m_Item = value
End Set
End Property
Private m_Item As String
Public Property value() As String
Get
Return m_value
End Get
Set(ByVal value As String)
m_value = value
End Set
End Property
Private m_value As String
End Class
Now,I have created a function which will return a List into DropdownList as shown below.
C#
private List<DDList> fillDropDownList()
{
return new List<DDList>(){
new DDList{ Item="SELECT", value="0"},
new DDList{ Item="Aamir Hasan", value="1"},
new DDList{ Item="Fasial Hameed", value="2"},
new DDList{ Item="Saba Khan", value="3"}
};
}
VB.NET
Private Function fillDropDownList() As List(Of DDList)
Return New List(Of DDList)() With { _
New DDList() With { _
.Item = "SELECT", _
.value = "0" _
}, _
New DDList() With { _
.Item = "Aamir Hasan", _
.value = "1" _
}, _
New DDList() With { _
.Item = "Fasial Hameed", _
.value = "2" _
}, _
New DDList() With { _
.Item = "Saba Khan", _
.value = "3" _
} _
}
End Function
Drag and drop DropDownList server control from toolbar into your Default.aspx page as given below.
<asp:DropDownList ID="DropDownList1" runat="server" />
Output

Download
Bind List to DropDownList.zip (1.03 kb)
Live demo