Using ASP.NET List Controls

69557 Users read it.
by Kevin Marshall
This tutorial will explain how to correctly use the ASP.NET List Controls. These comprise of three types of control, DropDownList, ListBox and HTMLSelect. During the course of this tutorial you will learn how to bind dynamic data such as Database contents and how these controls can interact with events and other controls on your page. A common problem associated with using these controls in Dreamweaver where the selected item often ends up being the first item in the list after a postback is solved. How to manually insert, delete and pre-select items in a list controls is also shown.
User Rating (131 votes)
Support



Details...
User Level:Any
Product:Dreamweaver MX
Server Language:C#, VB.NET
Technologies:HTML, .NET
Number Of Pages:13
  • An introduction to the available list controls
  • An introduction to the ListItem class
  • The DropDownList Control
  • The ListBox Control
  • The HTMLSelect Control
  • Defining the items of a list control
  • Programmatically Adding items to a list control
  • Programmatically Inserting items into a list control
  • Programmatically Selecting items in a list control
  • Programmatically Removing items from a list control
  • Binding Database content to a list control
  • Binding collections (Arrays) to a list control
  • A Common problem and solution
  • Using ASP.NET List Controls

    This tutorial will explain how to correctly use the ASP.NET List Controls. These comprise of three types of control, DropDownList, ListBox and HTMLSelect. During the course of this tutorial you will learn how to bind

    dynamic data such as Database contents and how these controls can interact with events and other controls on your page. A common problem associated with using these controls in Dreamweaver where the selected item often ends up being the first item in the list after a postback is solved. How to manually insert, delete and pre-select items in a list controls is also shown.

    • An introduction to the available list controls
    • An introduction to the ListItem class
    • The DropDownList Control
    • The ListBox Control
    • The HTMLSelect Control
    • Defining the items of a list control
    • Programmatically Adding items to a list control
    • Programmatically Inserting items into a list control
    • Programmatically Selecting items in a list control
    • Programmatically Removing items from a list control
    • Binding Database content to a list control
    • Binding collections (Arrays) to a list control
    • A Common problem and solution

    An introduction to the available list controls

    There are three list controls built into the .NET Framework, these are:

    • System.Web.UI.WebControls.DropDownList
      this control renders a drop-down list in the page at runtime. Only the selected item is visible when the user is not interacting with the list, and the other items become visible when the user clicks the control to see the items that can be selected. Only one item can be selected in this control. This control must be inserted into a server side form (runat="server") applied.




    • System.Web.UI.WebControls.ListBox
      this control renders a list of items within a scrolling box, multiple items can be selected in this control if required. This control must be inserted into a server side form (runat="server") applied.



    • System.Web.UI.HTMLControls.HTMLSelectthis control can be used to render a drop-down list or a scrolling list of items. This control has less built in functionality when compared with controls above (It lacks many of the properties that can be used to influence the display style such as ForeColor and BackColor to name a couple) ,but it is still capable of performing most common uses of a list control. This control can be inserted anywhere, and does not require a server side form.

    Activate your free membership today | Login | Currency