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. In this series of article we will also discuss on DropDownList, RadioButtonList, ListBox, CheckBoxList, and BulletedList controls too. We will also discuss how to bind them to a data source such as a 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 in given below to render a set of options for selecting our subject and degree.

list1.gif

<%@ 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 Degree:"
        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 above coding we have used a RadioButtonList control twice. This control contains four ListItem controls separately in twice of RadioButtonList.

The ListItem control supports the following five properties:
 

  • Attributes: it enables us to add HTML attributes to a list item.
  • Enabled: it enables us to disable a list item.
  • Selected: it enables us to mark a list item as selected.
  • Text: it enables us to specify the text displayed by the List Item.
  • Value: it enables us to specify a hidden value associated with the List Item.

Note: Continue in Next Part.

HAVE A GREAT CODING!

Up Next
    Ebook Download
    View all
    Learn
    View all