Online Book Reader

Home Category

Programming Microsoft ASP.NET 4 - Dino Esposito [224]

By Root 5596 0
of the list box also contains the set of SelectedXXX properties we considered earlier. In this case, they work as they do for the CheckBoxList control—that is, they return the selected item with the lowest index.

Note

All the list controls examined so far support the SelectedIndexChanged event, which is raised when the selection from the list changes and the page posts back to the server. You can use this event to execute server-side code whenever a control is selected or deselected.

The BulletedList Control


The BulletedList control is a programming interface built around the

    and
      HTML tags, with some extra features such as the bullet style, data binding, and support for custom images. The following example uses a custom bullet object:

      One

      Two

      Three

      The bullet style lets you choose the style of the element that precedes the item. You can use numbers, squares, circles, and uppercase and lowercase letters. The child items can be rendered as plain text, hyperlinks, or buttons. Table 10-3 details the main properties of a BulletedList control.

      Table 10-3. Properties of the BulletedList Control

      Property

      Description

      AppendDataBoundItems

      Indicates whether statically defined items should be maintained or cleared when adding data-bound items

      BulletImageUrl

      Gets or sets the path to the image to use as the bullet

      BulletStyle

      Determines the style of the bullet

      DataMember

      The name of the table in the DataSource to bind

      DataSource

      The data source that populates the items of the list

      DataSourceID

      ID of the data source component to provide data

      DataTextField

      Name of the data source field to supply the text of list items

      DataTextFormatString

      Formatting string used to visually format list items to be displayed

      DataValueField

      Name of the data source field to supply the value of a list item

      DisplayMode

      Determines how to display the items: as plain text, link buttons, or hyperlinks

      FirstBulletNumber

      Gets or sets the value that starts the numbering

      Items

      Gets the collection of items in the list control

      Target

      Indicates the target frame in the case of hyperlink mode

      The items of a BulletedList control support a variety of graphical styles—disc, circle, custom image, plus a few types of numberings, including roman numbering. The initial number can be programmatically set through the FirstBulletNumber property. The DisplayMode property determines how to display the content of each bullet—plain text (the default), link button, or hyperlink. In the case of link buttons, the Click event is fired on the server to let you handle the event when the page posts back. In the case of hyperlinks, the browser displays the target page in the specified frame—the Target property. The target URL coincides with the contents of the field specified by DataValueField.

      Figure 10-4 shows a sample page that includes RadioButtonList and BulletedList controls. The radio-button list is bound to the contents of a system enumerated type—BulletStyle—and displays as selectable radio buttons the various bullet styles. To bind the contents of an enumerated type to a data-bound control, you do as follows:

      BulletOptions.DataSource = Enum.GetValues(typeof(BulletStyle));

      BulletOptions.SelectedIndex = 0;

      BulletOptions.DataBind();

      To retrieve and set the selected value, use the following code:

      var style = (BulletStyle) Enum.Parse(typeof(BulletStyle),

      BulletOptions.SelectedValue);

      BulletedList1.BulletStyle = style;

      Figure 10-4. A sample page to preview the style of a BulletedList control.

      Iterative Controls


      Iterative controls supply a template-based mechanism to create free-form user interfaces. Iterative controls take a data source, loop through the items, and iteratively apply user-defined HTML templates to each row. This basic behavior is common to all three ASP.NET iterators: Repeater, DataList, and DataGrid. Beyond

Return Main Page Previous Page Next Page

®Online Book Reader