:: Home     :: MS Dynamics CRM     :: .Net 1.1     :: .Net 2.0     :: Sharepoint Portal     :: Ajax

  login:        
  passwords:  

Adding Data to a DropDownList 

The aim of this article is to answer the question 'How do I add items to a DropDownList?'

Initially as part of the declaration for the DropDownList we can also define a number of items, much in the same way as in classic ASP.

<asp:DropdownList id=ddlDropDown runat="server">
  <asp:ListItem Text="Daily" Value="Daily" Selected="True"></asp:ListItem>
  <asp:ListItem Text="Weekly" Value="Weekly"></asp:ListItem>
  <asp:ListItem Text="Monthly" Value="Monthly"></asp:ListItem>
</asp:DropdownList>

Now for the second part of the exercise. In our code behind we wish to be able to add more items to this list. To do this we add the following at the appropriate place in our code

ddlDropDown.Items.Add("Yearly")

However, this only allows us to add a value, we may also wist to add a value and text pair. To do this we need to do the following

ddlDropDown.Items.Add(New ListItem("1992", "(J/K)"))


Copyright 2005-2015, Megasolutions Ltd  |   Privacy Policy