Padding Padding
Janet
Systems
 Register  Login 
Telephone  01628 566 178
Website Design, Hosting and Software Services
  Search 
Padding
corner Padding corner
Padding Padding
corner Padding corner
 ASP.NET Articles

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=ddlFrequency 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

ddlFrequency.Items.Add("Yearly")

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

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

To make use of the ListItem it is necessary to add

Imports System.Web.UI.WebControls

at the start of your code.

NAT September 2005 (Revised)
NAT March 2006 (Revised)


This article viewed: 1515 times Back

Copyright © 2004-2007 Janet Systems Ltd.

 Print   

DotNetNuke Website design and hosting from £15.00 per month. More...

Looking for a website design company in the Thames Valley, call us on 01628 566178

DotNetNuke Modules
DotNetNuke Modules availalble from Janet Systems

DotNetNuke Skins
DotNetNukeSkins.gif

from Janet Systems

Padding
Copyright 2002-2008 Janet Systems Ltd.   Terms Of Use  Privacy Statement Tuesday, May 13, 2008