2 Asp.Net Standard Controls
2 Asp.Net Standard Controls
2 Asp.Net Standard Controls
Bulleted List:-
The BulletedList control is used to create a list of items formatted with bullets. To specify the
individual list items that you want to show in a BulletedList control, place a ListItem object for each
entry between the opening and closing tags of the BulletedList control. The control can display the list
items with many different kinds of bullet styles. The control is also actively used to show a list of hyperlinks.
The BulletedList control renders either an unordered (bulleted) or ordered (numbered) list. Each list
item can be rendered as plain text, a LinkButton control, or a link to another web page. For example, the
page given below uses the BulletedList control to render an unordered list of products.
We can control the appearance of the bullets that appear for each list item with the BulletStyle property. This
property accepts the following values:
• Circle
• CustomImage
• Disc
• LowerAlpha
• LowerRoman
• NotSet
• Numbered
• Square
• UpperAlpha
• UpperRoman
We can set BulletStyle to Numbered to display a numbered list. If you set this property to the value CustomImage and
assign an image path to the BulletImageUrl property, then we can associate an image with each list item.
RadioButton
It is an input control which is used to takes input from the user. It allows user to select a choice
from the group of choices. To create RadioButton we can drag it from the toolbox of visual studio.
This is a server side control and ASP.NET provides own tag to create it.
// WebControls.aspx.cs
1. using System;
2. using System.Collections.Generic;
3. using System.Linq;
4. using System.Web;
5. using System.Web.UI;
6. using System.Web.UI.WebControls;
7. namespace WebFormsControlls
8. {
9. public partial class WebControls : System.Web.UI.Page
10. {
11. protected void Button1_Click(object sender, EventArgs e)
12. {
13. genderId.Text = "";
14. if (RadioButton1.Checked)
15. {
16. genderId.Text = "Your gender is "+RadioButton1.Text;
17. }
18. else genderId.Text = "Your gender is "+RadioButton2.Text;
19.
20. }
21. }
22. }
Radio Button List
ASP.NET Radio Button List (ASPxRadioButtonList) editor is a radio button group that allows end-users to
select a single item at a time. Its contents can be generated dynamically by binding the editor to a data
source. You can also create items explicitly by populating the Items collection manually. For each list item,
you can specify its caption and associated value.
The item selected within ASPxRadioButtonList can be determined by using specific properties declared at the
editor level (SelectedItem, SelectedIndex). You can easily get and set the selected item on the client side
using specific client methods (GetSelectedItem/SetSelectedItem, GetSelectedIndex/SetSelectedIndex).
The ASPxRadioButtonList layout can be flexibly customized. You can display radio button items in several
columns (via the RepeatColumns property), set the direction of items within the editor (horizontal or vertical,
via the RepeatDirection property), and specify whether items are aligned within a table or rendered without
any table structure (via the RepeatLayout property).
CheckBox
It is used to get multiple inputs from the user. It allows user to select choices from the set of
choices.It takes user input in yes or no format. It is useful when we want multiple choices from the
user. To create CheckBox we can drag it from the toolbox in visual studio. This is a server side
control and ASP.NET provides own tag to create it. The example is given below.
e.g. < asp:CheckBox ID="CheckBox2" runat="server" Text="J2EE"/>
// WebControls.aspx
1. using System;
2. using System.Collections.Generic;
3. using System.Linq;
4. using System.Web;
5. using System.Web.UI;
6. using System.Web.UI.WebControls;
7. namespace WebFormsControlls
8. {
9. public partial class WebControls : System.Web.UI.Page
10. {
11. protected void Page_Load(object sender, EventArgs e)
12. {
13. ShowCourses.Text = "None";
14. }
15. protected void Button1_Click(object sender, EventArgs e)
16. {
17. var message = "" ;
18. if (CheckBox1.Checked)
19. {
20. message = CheckBox1.Text+" ";
21. }
22. if (CheckBox2.Checked)
23. {
24. message += CheckBox2.Text + " ";
25. }
26. if (CheckBox3.Checked)
27. {
28. message += CheckBox3.Text;
29. }
30. ShowCourses.Text = message;
31. }
32. }
33. }
CheckBoxList
ASP.NET CheckBoxList is a web control that can be used to collate the items that
can be checked, thus giving the user the ability to select multiple items
simultaneously. This list of items in the CheckBoxList can be dynamically
generated using the Data Binding functions.
LinkButton
<asp:LinkButton
AccessKey="string"
ID="string"
OnClientClick="string"
PostBackUrl="uri"
runat="server"
/>
// LinkButtonExample.aspx
CodeBehind="LinkButtonExample.aspx.cs"
Inherits="LinkButtonExample.LinkButtonExample" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<div>
</div>
<p>
</p>
</form>
</body>
</html>
// LinkButtonExample.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace LinkButtonExample
Image Button
The image button is used to display a clickable image,and a control that displays an image and
responds to mouse clicks on the image.
Imagebutton.aspx
<%@ Page Language="C#" AutoEventWireup="true"
CodeBehind="Backgroundchanging.aspx.cs"
Inherits="imagebutton.Backgroundchanging" %>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<br />
<asp:Label ID="lblbackground" runat="server"></asp:Label>
</div>
</form>
</body>
</html>
Imagebutton.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace imagebutton
{
public partial class Backgroundchanging : System.Web.UI.Page
{
protected void imgbtnbackground_Click(object sender, ImageClickEventArgs e)
{
lblbackground.Text = e.X + " " + e.Y;
}
}
}
Hyperlink
It is a control that is used to create a hyperlink. It responds to a click event. We can use it to
refer any web page on the server.
To create HyperLink either we can write code or use the drag and drop facility of visual studio
IDE. This control is listed in the toolbox.
This is a server side control and ASP.NET provides own tag to create it.
user-form.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="user-form.aspx.cs"
Inherits="asp.netexample.user_form" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:HyperLink ID="HyperLink1" runat="server" Text="JavaTpoint"
NavigateUrl="www.javatpoint.com"></asp:HyperLink>
</div>
</form>
</body>
</html>
DropDownList
The DropDownList is a web server control which is used to create an HTML Select component. It
allows us to select an option from the dropdown list. It can contain any number of items
ASP.NET provides a tag to create DropDownList for web application. The following is the Syntax of
DropDownList tag.
// DropDownListExample.aspx
<%@ Page Title="Home Page" Language="C#" AutoEventWireup="true"
CodeBehind="Default.aspx.cs" Inherits="DropDownListExample._Default" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<p>Select a City of Your Choice</p>
<div>
<asp:DropDownList ID="DropDownList1" runat="server" >
<asp:ListItem Value="">Please Select</asp:ListItem>
<asp:ListItem>New Delhi </asp:ListItem>
<asp:ListItem>Greater Noida</asp:ListItem>
<asp:ListItem>NewYork</asp:ListItem>
<asp:ListItem>Paris</asp:ListItem>
<asp:ListItem>London</asp:ListItem>
</asp:DropDownList>
</div>
<br />
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Submit" />
<br />
<br />
<asp:Label ID="Label1" runat="server" EnableViewState="False"></asp:Label>
</form>
</body>
</html>
// DropDownListExample.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace DropDownListExample
{
public partial class _Default : Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
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 provides us a user interface that will display the List of the items. From there, the
users can select one or more items from the List. We can use the ListBox to show the multiple columns, and
these columns can contain images and other controls.
For creating the ListBox, we will follow the two approaches in Windows Form. To create the ListBox
control, either we can use the Forms Designer at the time of the designing, or we can use the ListBox class
for creating control at the run time.
e.g.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WindowsFormsApp2
{
public partial class Form1: Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
ListBox box = new ListBox();
box.Location = new Point(300, 110);
box.Size = new Size(160, 103);
box.ForeColor = Color.Purple;
box.Items.Add(765);
box.Items.Add(875);
box.Items.Add(345);
// Now we will add ListBox control
// to the form
this.Controls.Add(box);
}
}
}
Panel control
The Panel control works as a container for other controls on the page. It controls the
appearance and visibility of the controls it contains. It also allows generating controls
programmatically.
<asp:Panel ID= "Panel1" runat = "server">
</asp:Panel>
The Panel control is derived from the WebControl class. Hence it inherits all the
properties, methods and events of the same. It does not have any method or event of its own.
e.g.
<asp:Panel ID="Panel1" runat="server" BorderColor="#990000" BorderStyle="Solid"
Borderstyle="width:1px" Height="116px" ScrollBars="Both" style="width:278px">
ImageMap
The ImageMap control in ASP.NET 2.0 and onward versions can be used to create an image
that contains defined hot spot regions. When a user clicks a hot spot region, the control can
either generate a post back to the server or navigate to a specified URL.
There are three kinds of hot spot regions defined in ImageMap control.
• RectangleHotSpot
• CircleHotSpot
• PolygonHotSpot
The RectangleHotSpot defines rectangular hot spot regions. The CircleHotSpotdefines circle-
shaped ones and the PolygonHotSpot is used for irregularly shaped hot spot area.
Map.aspx
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<div>
<table>
<tr>
<td colspan="4">
</td>
</asp:Panel>
</asp:Panel>
</asp:Panel>
</asp:Panel>
</asp:Panel>
</asp:Panel>
</td>
</tr>
</table>
</div>
</form>
</body>
</html>
Map.aspx.cs
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
string aa = e.PostBackValue;
if(aa=="bhuj")
p1.Visible =true ;
p2.Visible = false;
p3.Visible = false;
p4.Visible = false;
p5.Visible = false;
p6.Visible = false;
p7.Visible = false;
}
else if(aa=="patan")
p1.Visible =false ;
p2.Visible =true ;
p3.Visible = false;
p4.Visible = false;
p5.Visible = false;
p6.Visible = false;
p7.Visible = false;
p1.Visible = false;
p2.Visible = false;
p3.Visible = true;
p4.Visible = false;
p5.Visible = false;
p6.Visible = false;
p7.Visible = false;
p1.Visible = false;
p2.Visible = false;
p3.Visible = false ;
p5.Visible = true;
p4.Visible = false;
p6.Visible = false;
p7.Visible = false;
p1.Visible = false;
p2.Visible = false;
p3.Visible = false ;
p4.Visible = true;
p5.Visible = false;
p6.Visible = false;
p7.Visible = false;
p1.Visible = false;
p2.Visible = false;
p3.Visible = false;
p5.Visible = false ;
p4.Visible = false;
p6.Visible = true;
p7.Visible = false;
}
else if (aa == "ahd")
p1.Visible = false;
p2.Visible = false;
p3.Visible = false;
p5.Visible = false ;
p4.Visible = false;
p7.Visible = true;
p6.Visible = false;
SiteMapPath
The SiteMapPath control basically is used to access web pages of the website from one
webpage to another. It is a navigation control and displays the map of the site related to its
web pages. This map includes the pages in the particular website and displays the name of
those pages. You can click on that particular page in the Site Map to navigate to that page. We
can say that the SiteMapPath control displays links for connecting to URLs of other pages. The
SiteMapPath control uses a property called SiteMapProvider for accessing data from
databases and it stores the information in a data source. The SiteMapProvider internally
utilizes the SiteMapProvider abstract class defined under the System.Web namespace. The
representation of the SiteMapPath control is as follows:
Root Node->Child Node
e.g.
</siteMapNode>
</siteMap>
e.g.
<?xmlversionxmlversion="1.0"encoding="utf-8" ?>
<siteMapxmlnssiteMapxmlns="http://schemas.microsoft.com/AspNet/SiteMap-File-1.0">
</siteMapNode>
</siteMapNode>
</siteMap>