List Controls in ASP .NET: Part 1

Introduction

The List controls enable us to display simple lists of options. For example, we can use the RadioButtonList control to display a group of radio buttons, or the BulletedList control to display a list of links. This series of articles will also discuss DropDownList, RadioButtonList, ListBox, CheckBoxList, and BulletedList controls. We will also discuss binding them to a data source such as database tables.

Declaring list items

The List controls render a list of options. Each option is represented by an instance of the ListItem class. For example, we can use the page below to render options for selecting our subject and degree.

Fovourite Movies-

<%@ Page Language="VB" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">

</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title>Favorite Movie</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>

    <asp:Label
        id="lblSubjects"
        Text="Chose one of the Subject:"
        AssociatedControlID="rblSubjects"
        Runat="server"
        Font-Bold="true"/>

    <asp:RadioButtonList
        id="rblSubjects"
        Runat="server"
        Width="285px">
        <asp:ListItem
            Text="ASP.Net"
            Value="subject1"
            Selected="True"/>
        <asp:ListItem
            Text="VB.Net"
            Value="subject2" />
        <asp:ListItem
            Text="Silverlight"
            Value="subject3" />
        <asp:ListItem
            text="Expression Blend"
            Value="subject4" />
    </asp:RadioButtonList>
    <hr />
    <br />
    <asp:Label
        id="Label2"
        Text="Chose one of the Degrees:"
        AssociatedControlID="rblDegree"
        Runat="server"
        Font-Bold="true"/>
    <br />
    <asp:RadioButtonList
        id="rblDegree"
        Runat="server"
        Width="285px">
        <asp:ListItem
            Text="BCA"
            Value="degree1" />
        <asp:ListItem
            Text="MCA"
            Value="degree2" />
        <asp:ListItem
            Text="B.TECH.(IT)"
            Value="degree3" />
        <asp:ListItem
            text="M.TECH.(IT)"
            Value="degree4" />
    </asp:RadioButtonList>

    </div>
    </form>
</body>
</html>

In the above coding, we have used a RadioButtonList control twice. This control contains four List Item controls separately in twice of RadioButtonList.

The List Item control supports the following five properties

  1. Attributes: It enables us to add HTML attributes to a list item.
  2. Enabled: It enables us to disable a list item.
  3. Selected: It enables us to mark a list item as selected.
  4. Text: It enables us to specify the text displayed by the List Item.
  5. Value: It enables us to specify a hidden value associated with the List Item.

Note. Continue in the Next Part.

Have a great coding!


Similar Articles