Thursday, 4 April 2013

Listbox Control

      Listbox Control is used to provide a list of items and allow the user to select one or more items.
Especially when you wantto get a list of items from the database table and display them on the page then use the listbox control.

Properties for listbox control
  • DataSource : Used to specify source of data for the listbox, which can be an arrayor a collection or a database table
  • DataSource ID : Used to specify ID of a DataSource control usingwhich you want to get data from the dataSource and display it in the listbox
  • DataTextField: Used to specify column  name of the table whose data you want to display withen the listboxwhen datasource is a table in the database.
  • DataValueField: Used to specify column name in the table whose data to treat as value of the items in listbox when dataSource is a table in the database.
  • Items: It is a collection of items in listbox that can be used to specify the list of items in the listbox both as design time and runtime.
  • SelectionMode: Used to specify whether user can select a single item or multiple items within the listbox. It has two possible values single and multple. When selection mode is set to multiple ten to select multiple items from the listbox you have to hold control key or shift key on keyboard.
Runtime properties
  • SelectedIndex: Returns index of the first item selected in the listbox.
  • SelectedItem: Returns the first item selected within the istbox.
  • SelectedValue: Returns value of the first item selected.
Event
  • SelectedIndexChanged: This is a default event for listbox and it will be raised wheneveruser select an item in the listbox.

No comments:

Post a Comment