Build Your Own ASP.NET 3.5 Website Using C# & VB (24 page)

Read Build Your Own ASP.NET 3.5 Website Using C# & VB Online

Authors: Cristian Darie,Zak Ruvalcaba,Wyatt Barnett

Tags: #C♯ (Computer program language), #Active server pages, #Programming Languages, #C#, #Web Page Design, #Computers, #Web site development, #internet programming, #General, #C? (Computer program language), #Internet, #Visual BASIC, #Microsoft Visual BASIC, #Application Development, #Microsoft .NET Framework

BOOK: Build Your Own ASP.NET 3.5 Website Using C# & VB
11.13Mb size Format: txt, pdf, ePub



RadioButtonList

Like the RadioButton control, the RadioButtonList control represents radio buttons.

However, the RadioButtonList control represents a list of radio buttons and uses

more compact syntax. Here’s an example:






CheckBoxList

As you may have guessed, the CheckBoxList control represents a group of check

boxes; it’s equivalent to using several CheckBox controls in a row:






BulletedList

The BulletedList control displays bulleted or numbered lists, using

    (unordered

    list) or

      (ordered list) tags. Unlike the other list controls, the BulletedList

      doesn’t allow the selection of items, so the SelectedIndexChanged event isn’t supported.

      The first property you’ll want to set is DisplayMode, which can be Text (the default),

      or HyperLink, which will render the list items as links. When DisplayMode is set

      Licensed to [email protected]

      Constructing ASP.NET Web Pages

      117

      to HyperLink, you can use the Click event to respond to a user’s click on one of

      the items.

      The other important property is BulletStyle, which determines the style of the

      bullets. The accepted values are:

      ■ Numbered (1, 2, 3, …)

      ■ LowerAlpha (a, b, c, …)

      ■ UpperAlpha (A, B, C, …)

      ■ LowerRoman (i, ii, iii, …)

      ■ UpperRoman (I, II, III, …)

      ■ Circle

      ■ Disc

      ■ Square

      ■ CustomImage

      If the style is set to CustomImage, you’ll also need to set the BulletStyleImageUrl

      to specify the image to be used for the bullets. If the style is one of the numbered

      lists, you can also set the FirstBulletNumber property to specify the first number

      or letter that’s to be generated.

      Advanced Controls

      These controls are advanced in terms of their usage, the HTML code they generate,

      and the background work they do for you. Some of these controls aren’t available

      to older versions of ASP.NET; we’ll learn more about many of them (as well as

      others that aren’t covered in this chapter) as we progress through this book.

      Calendar

      The Calendar is a great example of the reusable nature of ASP.NET controls. The

      Calendar control generates markup that displays an intuitive calendar in which

      the user can click to select, or move between, days, weeks, months, and so on.

      The Calendar control requires very little customization. In Visual Web Developer,

      select
      Website > Add New Item…
      , and make the changes indicated:

      Licensed to [email protected]

      118

      Build Your Own ASP.NET 3.5 Web Site Using C# & VB

      Visual Basic

      LearningASP\VB\Calendar_01.aspx

      <%@ Page Language="VB" %>

      "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">




      <br/><b>Calendar Test<br/></b>










      Again, the C# version is the same, except for the Page declaration:

      C#

      LearningASP\CS\01_Calendar.aspx
      (excerpt)

      <%@ Page Language="C#" %>


      If you save this page in your working folder and load it, you’ll see the output shown

      in
      Figure 4.4
      .

      Licensed to [email protected]

      Constructing ASP.NET Web Pages

      119

      Figure 4.4. Displaying the default calendar

      The Calendar control contains a wide range of properties, methods, and events,

      including those listed in
      Table 4.3
      .

      Licensed to [email protected]

      120

      Build Your Own ASP.NET 3.5 Web Site Using C# & VB

      Table 4.3. Some of the Calendar control’s properties

      Property

      Description

      DayNameFormat

      This property sets the format of the day names. Its possible values are

      FirstLetter, FirstTwoLetters, Full, and Short. The default

      is Short, which displays the three-letter abbreviation.

      FirstDayOfWeek

      This property sets the day that begins each week in the calendar. By default,

      the value of this property is determined by your server’s region settings,

      but you can set this to Sunday or Monday if you want to control it.

      NextPrevFormat

      Set to CustomText by default, this property can be set to ShortMonth

      or FullMonth to control the format of the next and previous month

      links.

      SelectedDate

      This property contains a DateTime value that specifies the highlighted day.

      You’ll use this property often, to determine which date the user has

      selected.

      SelectionMode

      This property determines whether days, weeks, or months can be selected;

      its possible values are Day, DayWeek, DayWeekMonth, and None, and

      the default is Day. When Day is selected, a user can only select a day;

      when DayWeek is selected, a user can select a day or an entire week; and

      so on.

      SelectMonthText

      This property controls the text of the link that’s displayed to allow users

      to select an entire month from the calendar.

      SelectWeekText

      This property controls the text of the link that’s displayed to allow users

      to select an entire week from the calendar.

      ShowDayHeader

      If True, this property displays the names of the days of the week. The

      default is True.

      ShowGridLines

      If True, this property renders the calendar with grid lines. The default is

      True.

      ShowNextPrevMonth

      If True, this property displays
      next month
      and
      previous month
      links.

      The default is True.

      ShowTitle

      If True, this property displays the calendar’s title. The default is False.

      TitleFormat

      This property determines how the month name appears in the title bar.

      Possible values are Month and MonthYear. The default is MonthYear.

      TodaysDate

      This DateTime value sets the calendar’s current date. By default, this value

      is not highlighted within the Calendar control.

      VisibleDate

      This DateTime value controls which month is displayed.

      Licensed to [email protected]

      Constructing ASP.NET Web Pages

      121

      Let’s take a look at an example that uses some of these properties, events, and

      methods to create a Calendar control which allows users to select days, weeks, and

      months. Modify the calendar in
      Calendar.aspx
      (both the VB and C# versions), and

      add a label to it, as follows:

      LearningASP\VB\Calendar_02.aspx
      (excerpt)




      Pick your dates:

      DayNameFormat="Short" FirstDayOfWeek="Sunday"

      NextPrevFormat="FullMonth" SelectionMode="DayWeekMonth"

      SelectWeekText="Select Week"

      SelectMonthText="Select Month" TitleFormat="Month"

      OnSelectionChanged="SelectionChanged" />

      You selected these dates:





      Now edit the

      C#

      LearningASP\CS\Calendar_02.aspx
      (excerpt)


      Save your work and test it in a browser. Try selecting a day, week, or month. The

      selection will be highlighted in a similar way to the display shown in Figure 4.5
      . Figure 4.5. Using the Calendar control

      In SelectionChanged, we loop through each of the dates that the user has selected,

      and append each to the Label we added to the page.

      Licensed to [email protected]

      Constructing ASP.NET Web Pages

      123

      AdRotator

      The AdRotator control allows you to display a list of banner advertisements at

      random within your web application. However, it’s more than a mere substitute for

      creating a randomization script from scratch. Since the AdRotator control gets its

Other books

Waking in Dreamland by Jody Lynne Nye
Half Moon Street by Anne Perry
Dead Romantic by C. J. Skuse
Frío como el acero by David Baldacci
Destroying the Wrong by Evelyne Stone
In Loco Parentis by Nigel Bird
Full Circle by Davis Bunn