Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

ASP.NET Web Controls: DropDownList, ListBox, RadioButtonList, Table, MultiView, TreeView, , Study notes of Computer Science

Perfect Notes For Exams to Study and Score Well!!!

Typology: Study notes

2021/2022

Available from 03/26/2023

srushti-dewalekar
srushti-dewalekar 🇮🇳

5 documents

1 / 90

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Unit 2
Web Controls
Sem 4
(B.Sc.CS)
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26
pf27
pf28
pf29
pf2a
pf2b
pf2c
pf2d
pf2e
pf2f
pf30
pf31
pf32
pf33
pf34
pf35
pf36
pf37
pf38
pf39
pf3a
pf3b
pf3c
pf3d
pf3e
pf3f
pf40
pf41
pf42
pf43
pf44
pf45
pf46
pf47
pf48
pf49
pf4a
pf4b
pf4c
pf4d
pf4e
pf4f
pf50
pf51
pf52
pf53
pf54
pf55
pf56
pf57
pf58
pf59
pf5a

Partial preview of the text

Download ASP.NET Web Controls: DropDownList, ListBox, RadioButtonList, Table, MultiView, TreeView, and more Study notes Computer Science in PDF only on Docsity!

Unit 2

Web Controls

Sem 4

(B.Sc.CS)

  • List Controls :
  • These controls display list of options to select. You can select one or more options, the choice depends upon control.
  • They all derive from the System.Web.UI.WebControls.ListControl class.
  • ASP.NET provides the following controls :  Drop-down list,  List box,  Radio button list,  Check box list,  Bulleted list. DropDown List Control:
  • DropDownList control is used select single option from multiple listed items.



  • // DropDownListExample.aspx.cs

protected void Button1_Click(object sender, EventArgs e)

if (DropDownList1.SelectedValue == "")

{ Label1.Text = "Please Select a City";

else

Label1.Text = "Your Choice is: " + DropDownList1.SelectedValue;

ListBox Control:

  • The ListBox control is similar to the DropDownList but main difference is that you can select multiple items from ListBox at a time.
  • ListBox control has SelectionMode property that enables you to select multiple items from ListBox control.
  • By default SelectionMode property is set as single. If you want to select multiple items from the ListBox, then set SelectionMode property value as Multiple. The ListBox control also supports data binding. You can bind the ListBox through coding with database or attach it with one of the predefined DataSourceControl objects, which contains the items to display in the control.
  • DataTextField and DataValueField properties are used to bind to the Text and Value field in the data source.

ListBox Eg:

ABC PQR MNO XYZ

RadioButtonList

  • RadioButtonList Control is same as DropDownList but it displays a list of radio buttons that can be arranged either

horizontally or vertically. You can select only one item from the given RadioButtonList of options. These options are

mutually exclusive.

The RadioButtonList control supports three important properties that affect its layout:

RepeatColumns: It displays the number of columns of radio buttons.

RepeatDirection: The direction that the radio buttons repeat. By default RepeatDirection value is vertical. Possible values

are Horizontal and Vertical.

RepeatLayout: Determines whether the radio buttons display in an HTML table.

Eg:

<asp:RadioButtonList ID="RadioButtonList1" runat="server">

<asp:ListItem Value="1">Red</asp:ListItem>

<asp:ListItem Value="2">Green</asp:ListItem>

<asp:ListItem Value="3">Blue</asp:ListItem>

<asp:ListItem Value="4">Yellow</asp:ListItem>

<asp:ListItem Value="5">Orange</asp:ListItem>

</asp:RadioButtonList>

<asp:Label ID="Label1" runat="server" EnableViewState="False"></asp:Label>

<asp:Button ID="btnValidate" OnClick="Button1_Click" runat="server" Text=“Show" />

<asp:Button ID="btnValidate" OnClick="Button2_Click" runat="server" Text=“RepeatDirection" /> <asp:Button ID="btnValidate" OnClick="btnValidate_Click" runat="server" Text="Validate" /> protected void Button1_Click(object sender, EventArgs e) { Label1.Text = "You have selected
Item=" + RadioButtonList1.SelectedItem.Text + "
Value =" + RadioButtonList1.SelectedValue + "
Index =" + RadioButtonList1.SelectedIndex ; } protected void Button2_Click(object sender, EventArgs e) { if (RadioButtonList1.RepeatDirection == RepeatDirection.Vertical) { RadioButtonList1.RepeatDirection = RepeatDirection.Horizontal; } else { RadioButtonList1.RepeatDirection = RepeatDirection.Vertical; } } protected void btnValidate_Click(object sender, EventArgs e) { if (rblTest.SelectedIndex == -1) { Label1.Text =“Select 1 Item”; } }

  • Bulleted List:
  • BulletedList control is very rich in displaying the items in different styles. It displays the list either in unordered or ordered

list. Each list item can be rendered as plain text, a LinkButton control, or a link to another web page.

BulletedList control supports the BulletStyle property. The default value of BulletStyle property is NotSet and rendered as

in list of bulleted items.

  • Possible values are as follows:

 Circle

 CustomImage

 Disc

 LowerAlpha

 LowerRoman

 NotSet

 Numbered

 Square

 UpperAlpha

 UpperRoman

Output:-

Table control:

  • The System.Web.UI.Controls namespace defines the Table class, along with the other Web controls. You can create tables

in .NET using a Table control and its helper controls TableRow and TableCell. As with all Web controls, you can create a

Table control at run-time as well as at design-time using visual Studio.

  • Table: ASP.NET table and its Helper Control Classes

Manages a collection of table cells such as adding a cell to a row or removing a cell from it.

CONTROL CODE DESCRIPTION Table <asp:Table> The System.Web.UI.Table class encapsulates an HTML table. An HTML table control, used to creates a table with the help of TableRow and TableCell. TableRow <asp:TableRow> The System.Web.UI.TableRow class encapsulates a row within a table, which later can be used to get or set row's cells values using TableCell. TableCell <asp:TableCell> The System.Web.UI.TableCell class encapsulates a cell within a table. TableRowCollection <asp:TableRowCollection> The System.Web.UI.TableCell class encapsulates a TableRowCollection and is used to manage a collection of table a collection or removing a row from it. TableCellCollection <asp:TableCellCollection> Manages a collection of table cells such as adding a cell to a row or removing a cell from it. TableHeaderCollection <asp:TableHeaderCell> Encapsulate a table header cell.

  • Example of Table Control in ASP.NET
  • <%@ Page Language="C#" %>
Id Name Address 1 Dotprogramming Chirawa 2 Narendra Chirawa

Web control Events and AutoPostBack

  • An important feature of ASP.NET is that it allows you to program Web pages using an event-based model that is similar to that in client applications. As a simple example, you can add a button to an ASP.NET Web page and then write an event handler for the button's click event. Although this is common in Web pages that work exclusively with client script (by handling the button's onclick event in dynamic HTML), ASP.NET brings this model to server-based processing.
  • Events raised by ASP.NET server controls work somewhat differently than events in traditional HTML pages or in client-based Web applications. The difference arises primarily because of the separation of the event itself from where the event is handled. In client-based applications, events are raised and handled on the client. In ASP.NET Web pages, however, events associated with server controls originate on the client (browser) but are handled on the Web server by the ASP.NET page.
  • For events raised on the client, the ASP.NET Web control event model requires that the event information be captured on the client and an event message transmitted to the server, through an HTTP post. The page must interpret the post to determine what event occurred and then call the appropriate method in your code on the server to handle the event.
  • ASP.NET web form supports many web controls like Check box, button list, Text box, etc.
  • Each web control has related events. Types of web control events are:
  • Types of Web control events:- 1. PostBack Event
    1. Cached Event
    2. Validation Event