I assume we have a drop down list (DropDownList1) one the page with following structure,
<asp:dropdownlist id="DropDownList1" runat="server" datatextfield="Name" datavaluefield="Id" xmlns:asp="#unknown">
</asp:dropdownlist>
and related code behind to populate the DropDownList with data,
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
IList persons = new List<Person>()
{
new Person(){ Id="1", Name="A"},
new Person(){ Id="2", Name="B"},
new Person(){ Id="3", Name="C"},
};
DropDownList1.DataSource = persons;
DropDownList1.DataBind();
}
public class Person
{
public string Id { get; set; }
public string Name { get; set; }
}
}
So from the above code we can seer, I created a Person type with two property Id and Name. I set the Id as value field for the DropDownList and Name as Textfield.
I Created a List of Person and set that list as data source of the DropDownList. Finally to Bind the data source with the DropDownList using DataBind().
Note: I have done all these on a page named Default.aspx
Hope it helps :)