Vous êtes sur la page 1sur 32

Experiment No.

# 1
Write a program in ASP.Net using text box, control, multiline text box & password.

Page Source:
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb"
Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"


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

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Textbox Controls</title>
<style type="text/css">
.style1
{
width: 59%;
height: 207px;
}
.style3
{
height: 53px;
}
.style4
{
height: 89px;
}
.style5
{
height: 53px;
width: 281px;
}
.style6
{
height: 89px;
width: 281px;
}
.style7
{
width: 281px;
}
.style8
{
font-weight: bold;
text-decoration: underline;
}
.style9
{
font-size: x-large;
}
</style>
</head>
<body bgcolor="#3333ff">
<form id="form1" runat="server">
<div style="vertical-align:middle; text-align:center; color: #FFFFFF; font-
family: 'Trebuchet MS';">
<br />
<span class="style8"><span class="style9">THIS EXPERIMENT TELLS ABOUT
VARIOUS
TYPES OF TEXTBOXES IN ASP.NET</span><br />
</span>
<table class="style1">
<tr>
<td class="style5">
<asp:Label ID="Label1" runat="server" Font-Bold="True"
Font-Names="Trebuchet MS" ForeColor="White" Text="This is
a Normal Textbox"></asp:Label>
</td>
<td class="style3">
<asp:TextBox ID="TextBox1" runat="server"
Width="252px"></asp:TextBox>
</td>
</tr>
<tr>
<td class="style6">
<asp:Label ID="Label2" runat="server" Font-Bold="True"
Font-Names="Trebuchet MS" ForeColor="White" Text="This is
a Multiline Textbox"></asp:Label>
</td>
<td class="style4">
<asp:TextBox ID="TextBox2" runat="server" Height="62px"
TextMode="MultiLine"
Width="252px"></asp:TextBox>
</td>
</tr>
<tr>
<td class="style7">
<asp:Label ID="Label3" runat="server" Font-Bold="True"
Font-Names="Trebuchet MS" ForeColor="White"
Text="This is a Password Textbox. The text is not
visible."></asp:Label>
</td>
<td>
<asp:TextBox ID="TextBox3" runat="server" Font-
Names="Trebuchet MS"
TextMode="Password" Width="251px"></asp:TextBox>
</td>
</tr>
</table>

</div>
</form>
</body>
</html>
Output :
Experiment No. # 2
Write a program in ASP.Net using events in text box.

Page Source:
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb"
Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"


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

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Textbox Events</title>
<style type="text/css">
.style1
{
width: 100%;
height: 100px;
}
.style3
{
width: 483px;
height: 48px;
}
.style4
{
height: 48px;
}
.style5
{
font-size: x-large;
font-weight: bold;
text-decoration: underline;
}
</style>
</head>
<body bgcolor="#3333ff">
<form id="form1" runat="server">
<div style="color: #FFFFFF; font-family: 'Trebuchet MS'">

<br />
<span class="style5">This Experiment Shows Various Textbox Events in
ASP.NET<br />
</span>

<table class="style1">
<tr>
<td class="style3">
<asp:Label ID="Label1" runat="server"
Text="This text box has a Pre-render Event"></asp:Label>
</td>
<td class="style4">
<asp:TextBox ID="TextBox1" runat="server"
Width="296px"></asp:TextBox>
</td>
</tr>
<tr>
<td class="style3">
<asp:Label ID="Label2" runat="server"
Text="This text box has a Text Change Event connected to
Text box below"></asp:Label>
</td>
<td class="style4">
<asp:TextBox ID="TextBox2"
OnTextChanged="TextBox2_TextChanged" AutoPostBack="true" runat="server"
Width="296px"></asp:TextBox>
</td>
</tr>
<tr>
<td class="style3">
<asp:Label ID="Label3" runat="server"
Text="This text box has no events, only gets changed by
the text box above"></asp:Label>
</td>
<td class="style4">
<asp:TextBox ID="TextBox3" runat="server"
Width="296px"></asp:TextBox>
</td>
</tr>
</table>

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

VB Code Behind File:

Partial Class _Default


Inherits System.Web.UI.Page

Protected Sub TextBox1_PreRender(ByVal sender As Object, ByVal e As


System.EventArgs) Handles TextBox1.PreRender
MsgBox("The first textbox is going to be rendered! Click ok to see...",
MsgBoxStyle.OkOnly, "Message...")
End Sub

Protected Sub TextBox2_TextChanged(ByVal sender As Object, ByVal e As


System.EventArgs) Handles TextBox2.TextChanged
TextBox3.Text = TextBox2.Text
End Sub
End Class
Output:
Experiment No. # 3
Write a program in ASP.Net using Labels, Text Box & Button Control.

Page source:
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb"
Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"


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

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Labels Textboxes and Buttons</title>
<style type="text/css">
.style1
{
width: 100%;
}
.style3
{
width: 311px;
text-align: center;
height: 45px;
}
.style4
{
height: 46px;
width: 311px;
text-align: center;
}
.style5
{
width: 432px;
text-align: center;
}
.style7
{
text-align: center;
}
.style8
{
height: 58px;
width: 311px;
text-align: center;
}
.style9
{
width: 432px;
text-align: center;
height: 58px;
}
.style10
{
text-align: center;
height: 58px;
}
.style11
{
width: 432px;
text-align: center;
height: 45px;
}
.style12
{
text-align: center;
height: 45px;
}
</style>
</head>
<body bgcolor="#3333ff">
<form id="form1" runat="server">
<div style="font-family: 'Trebuchet MS'; color: #FFFFFF">

<table class="style1">
<tr>
<td class="style3">
<asp:Label ID="Label4" runat="server" BorderColor="Black"
BorderStyle="Solid"
BorderWidth="2px" Font-Bold="True" Font-Underline="True"
style="text-align: center" Text="These are
labels"></asp:Label>
</td>
<td class="style11">
<asp:Label ID="Label5" runat="server" BorderColor="Black"
BorderStyle="Solid"
BorderWidth="2px" Font-Bold="True" Font-Underline="True"
Text="These are textboxes"></asp:Label>
</td>
<td class="style12">
<asp:Label ID="Label6" runat="server" BorderColor="Black"
BorderStyle="Solid"
BorderWidth="2px" Font-Bold="True" Font-Underline="True"
Text="These are buttons"></asp:Label>
</td>
</tr>
<tr>
<td class="style8">
<asp:Label ID="Label1" runat="server" Text="Label
One"></asp:Label>
</td>
<td class="style9">
<asp:TextBox ID="TextBox1" runat="server"
Width="340px"></asp:TextBox>
</td>
<td class="style10">
<asp:Button ID="Button1" runat="server" BackColor="Black"
BorderColor="White"
BorderStyle="Solid" BorderWidth="2px" Font-Bold="True"
Font-Size="Medium"
ForeColor="White" Height="42px" Text="Button 1"
Width="104px" />
</td>
</tr>
<tr>
<td class="style8">
<asp:Label ID="Label2" runat="server" Text="Label
Two"></asp:Label>
</td>
<td class="style9">
<asp:TextBox ID="TextBox2" runat="server"
Width="340px"></asp:TextBox>
</td>
<td class="style10">
<asp:Button ID="Button4" runat="server" BackColor="Black"
BorderColor="White"
BorderStyle="Solid" BorderWidth="2px" Font-Bold="True"
Font-Size="Medium"
ForeColor="White" Height="42px" Text="Button 2"
Width="104px" />
</td>
</tr>
<tr>
<td class="style4">
<asp:Label ID="Label3" runat="server" Text="Label
Three"></asp:Label>
</td>
<td class="style5">
<asp:TextBox ID="TextBox3" runat="server"
Width="340px"></asp:TextBox>
</td>
<td class="style7">
<asp:Button ID="Button5" runat="server" BackColor="Black"
BorderColor="White"
BorderStyle="Solid" BorderWidth="2px" Font-Bold="True"
Font-Size="Medium"
ForeColor="White" Height="42px" Text="Button 3"
Width="104px" />
</td>
</tr>
</table>

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

VB Code Behind File:

Partial Class _Default


Inherits System.Web.UI.Page

Protected Sub Button1_Click(ByVal sender As Object, ByVal e As


System.EventArgs) Handles Button1.Click
MsgBox("The first button is clicked...", MsgBoxStyle.OkOnly, "This is a
message...")
End Sub

Protected Sub Button4_Click(ByVal sender As Object, ByVal e As


System.EventArgs) Handles Button4.Click
MsgBox("The second button is clicked...", MsgBoxStyle.OkOnly, "This is a
message...")
End Sub

Protected Sub Button5_Click(ByVal sender As Object, ByVal e As


System.EventArgs) Handles Button5.Click
MsgBox("The third button is clicked...", MsgBoxStyle.OkOnly, "This is a
message...")
End Sub
End Class

Output:
Experiment No. # 4
Write a program in ASP.Net using Radiobutton.

Page Source:
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb"
Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"


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

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Radio Button Experiment</title>
</head>
<body bgcolor="#3333ff" style="font-family: 'Trebuchet MS'; color: #FFFFFF; text-
align: center">
<form id="form1" runat="server">
<div>

<div style="border: 10px solid #FFFFFF; width: 678px; height: 370px;">


<asp:Label ID="Label1" runat="server" Font-Bold="True" Font-
Size="Large"
Height="47px"
Text="You have to select the right radio button. Guess the
correct one, and see how the radio button works...."
Width="591px"></asp:Label>
<br />
<br />
<asp:RadioButton ID="RadioButton1" runat="server" GroupName="aaa"
Text="Radio Button 1" />
<br />
<asp:RadioButton ID="RadioButton2" runat="server" GroupName="aaa"
Text="Radio Button 2" />
<br />
<asp:RadioButton ID="RadioButton3" runat="server" GroupName="aaa"
Text="Radio Button 3" />
<br />
<asp:RadioButton ID="RadioButton4" runat="server" GroupName="aaa"
Text="Radio Button 4" />
<br />
<asp:RadioButton ID="RadioButton5" runat="server" GroupName="aaa"
Text="Radio Button 5" />
<br />
<asp:RadioButton ID="RadioButton6" runat="server" GroupName="aaa"
Text="Radio Button 6" />
<br />
<asp:RadioButton ID="RadioButton7" runat="server" GroupName="aaa"
Text="Radio Button 7" />
<br />
<asp:RadioButton ID="RadioButton8" runat="server" GroupName="aaa"
Text="Radio Button 8" />
<br />
<br />
<asp:Button ID="Button1" runat="server" Font-Bold="True"
Text="Click here and see your luck..." />
<br />
<br />
<asp:Label ID="Label2" runat="server" BackColor="White" Font-
Size="XX-Large"
Height="40px" Text="Label" Visible="False"
Width="118px"></asp:Label>
<br />
</div>

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

VB Code Behind File:

Partial Class _Default


Inherits System.Web.UI.Page

Protected Sub Button1_Click(ByVal sender As Object, ByVal e As


System.EventArgs) Handles Button1.Click
If RadioButton1.Checked = True Then
RadioButton1.BackColor = Drawing.Color.Red
RadioButton5.BackColor = Drawing.Color.Green
RadioButton6.BackColor = Drawing.Color.Transparent
RadioButton2.BackColor = Drawing.Color.Transparent
RadioButton3.BackColor = Drawing.Color.Transparent
RadioButton4.BackColor = Drawing.Color.Transparent
RadioButton7.BackColor = Drawing.Color.Transparent
RadioButton8.BackColor = Drawing.Color.Transparent
Label2.ForeColor = Drawing.Color.Red
Label2.Text = "WRONG!"
Label2.Visible = True
ElseIf RadioButton2.Checked = True Then
RadioButton2.BackColor = Drawing.Color.Red
RadioButton5.BackColor = Drawing.Color.Green
RadioButton1.BackColor = Drawing.Color.Transparent
RadioButton6.BackColor = Drawing.Color.Transparent
RadioButton3.BackColor = Drawing.Color.Transparent
RadioButton4.BackColor = Drawing.Color.Transparent
RadioButton7.BackColor = Drawing.Color.Transparent
RadioButton8.BackColor = Drawing.Color.Transparent
Label2.ForeColor = Drawing.Color.Red
Label2.Text = "WRONG!"
Label2.Visible = True
ElseIf RadioButton3.Checked = True Then
RadioButton3.BackColor = Drawing.Color.Red
RadioButton5.BackColor = Drawing.Color.Green
RadioButton1.BackColor = Drawing.Color.Transparent
RadioButton2.BackColor = Drawing.Color.Transparent
RadioButton6.BackColor = Drawing.Color.Transparent
RadioButton4.BackColor = Drawing.Color.Transparent
RadioButton7.BackColor = Drawing.Color.Transparent
RadioButton8.BackColor = Drawing.Color.Transparent
Label2.ForeColor = Drawing.Color.Red
Label2.Text = "WRONG!"
Label2.Visible = True
ElseIf RadioButton4.Checked = True Then
RadioButton4.BackColor = Drawing.Color.Red
RadioButton5.BackColor = Drawing.Color.Green
RadioButton1.BackColor = Drawing.Color.Transparent
RadioButton2.BackColor = Drawing.Color.Transparent
RadioButton3.BackColor = Drawing.Color.Transparent
RadioButton6.BackColor = Drawing.Color.Transparent
RadioButton7.BackColor = Drawing.Color.Transparent
RadioButton8.BackColor = Drawing.Color.Transparent
Label2.ForeColor = Drawing.Color.Red
Label2.Text = "WRONG!"
Label2.Visible = True
ElseIf RadioButton5.Checked = True Then
RadioButton5.BackColor = Drawing.Color.Green
Label2.ForeColor = Drawing.Color.Green
RadioButton1.BackColor = Drawing.Color.Transparent
RadioButton2.BackColor = Drawing.Color.Transparent
RadioButton3.BackColor = Drawing.Color.Transparent
RadioButton4.BackColor = Drawing.Color.Transparent
RadioButton7.BackColor = Drawing.Color.Transparent
RadioButton6.BackColor = Drawing.Color.Transparent
RadioButton8.BackColor = Drawing.Color.Transparent
Label2.Text = "RIGHT!"
Label2.Visible = True
ElseIf RadioButton6.Checked = True Then
RadioButton6.BackColor = Drawing.Color.Red
RadioButton1.BackColor = Drawing.Color.Transparent
RadioButton2.BackColor = Drawing.Color.Transparent
RadioButton3.BackColor = Drawing.Color.Transparent
RadioButton4.BackColor = Drawing.Color.Transparent
RadioButton7.BackColor = Drawing.Color.Transparent
RadioButton8.BackColor = Drawing.Color.Transparent
RadioButton5.BackColor = Drawing.Color.Green
Label2.ForeColor = Drawing.Color.Red
Label2.Text = "WRONG!"
Label2.Visible = True
ElseIf RadioButton7.Checked = True Then
RadioButton7.BackColor = Drawing.Color.Red
RadioButton5.BackColor = Drawing.Color.Green
RadioButton1.BackColor = Drawing.Color.Transparent
RadioButton2.BackColor = Drawing.Color.Transparent
RadioButton3.BackColor = Drawing.Color.Transparent
RadioButton4.BackColor = Drawing.Color.Transparent
RadioButton6.BackColor = Drawing.Color.Transparent
RadioButton8.BackColor = Drawing.Color.Transparent
Label2.ForeColor = Drawing.Color.Red
Label2.Text = "WRONG!"
Label2.Visible = True
ElseIf RadioButton8.Checked = True Then
RadioButton8.BackColor = Drawing.Color.Red
RadioButton5.BackColor = Drawing.Color.Green
RadioButton1.BackColor = Drawing.Color.Transparent
RadioButton2.BackColor = Drawing.Color.Transparent
RadioButton3.BackColor = Drawing.Color.Transparent
RadioButton4.BackColor = Drawing.Color.Transparent
RadioButton7.BackColor = Drawing.Color.Transparent
RadioButton6.BackColor = Drawing.Color.Transparent
Label2.ForeColor = Drawing.Color.Red
Label2.Text = "WRONG!"
Label2.Visible = True
Else
MsgBox("You selected NONE!!! Please select one....",
MsgBoxStyle.OkOnly, "Message...")
End If
End Sub
End Class

Output:
Experiment No. # 5
Write a program in ASP.Net using CheckBoxList.

Page Source:
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb"
Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"


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

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Check Box List</title>
<style type="text/css">
.style1
{
font-size: x-large;
font-weight: bold;
text-decoration: underline;
}
</style>
</head>
<body bgcolor="#3333ff">
<form id="form1" runat="server">
<div class="style1" style="font-family: 'Trebuchet MS'; color: #FFFFFF">

This Experiment shows how a Checkboxlist works in ASP.NET....<br />


<br />
<br />

</div>
<div>
<asp:CheckBoxList ID="CheckBoxList1" runat="server" AutoPostBack="true"
BorderColor="White"
BorderStyle="Solid" BorderWidth="5px" Font-Bold="True" Font-
Underline="True"
ForeColor="White" Width="167px">
<asp:ListItem>Bold</asp:ListItem>
<asp:ListItem>Italic</asp:ListItem>
<asp:ListItem>Underline</asp:ListItem>
<asp:ListItem>Red</asp:ListItem>
<asp:ListItem>Green</asp:ListItem>
<asp:ListItem>Border</asp:ListItem>
</asp:CheckBoxList>
<div style="border: 5px solid #FFFFFF; position: absolute; top: 128px;
left: 208px; width: 427px; height: 154px;">
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<br />
<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb
sp;&nbsp;&nbsp;
<asp:Label ID="Label1" runat="server" Font-Bold="False" Font-
Names="Verdana"
Font-Size="X-Large" ForeColor="White" Text="See your Text
here..."></asp:Label>
</div>
</div>
</form>
</body>
</html>

VB Code Behind File:

Partial Class _Default


Inherits System.Web.UI.Page

Protected Sub CheckBoxList1_SelectedIndexChanged(ByVal sender As Object,


ByVal e As System.EventArgs) Handles CheckBoxList1.SelectedIndexChanged
If CheckBoxList1.SelectedIndex = 0 Then
Label1.Font.Bold = True
ElseIf Not CheckBoxList1.SelectedIndex = 0 Then
Label1.Font.Bold = False
End If

If CheckBoxList1.SelectedIndex = 1 Then
Label1.Font.Italic = True
ElseIf Not CheckBoxList1.SelectedIndex = 1 Then
Label1.Font.Italic = False
End If

If CheckBoxList1.SelectedIndex = 2 Then
Label1.Font.Underline = True
ElseIf Not CheckBoxList1.SelectedIndex = 2 Then
Label1.Font.Underline = False
End If

If CheckBoxList1.SelectedIndex = 3 Then
Label1.ForeColor = Drawing.Color.Red
ElseIf Not CheckBoxList1.SelectedIndex = 3 Then
Label1.ForeColor = Drawing.Color.White
End If

If CheckBoxList1.SelectedIndex = 4 Then
Label1.ForeColor = Drawing.Color.Green
ElseIf Not CheckBoxList1.SelectedIndex = 4 Then
Label1.ForeColor = Drawing.Color.White
End If

If CheckBoxList1.SelectedIndex = 5 Then
Label1.BorderColor = Drawing.Color.Yellow
Label1.BorderStyle = BorderStyle.Dashed
Label1.BorderWidth = Unit.Pixel(5)
ElseIf Not CheckBoxList1.SelectedIndex = 5 Then
Label1.BorderStyle = BorderStyle.None

End If
End Sub
End Class
Output:
Experiment No. # 6
Write a program in ASP.Net using DropDownList.

Page Source:
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb"
Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"


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

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Drop Down List</title>
<style type="text/css">
.style1
{
font-weight: bold;
text-decoration: underline;
font-size: x-large;
}
.style2
{
width: 67%;
}
.style3
{
text-align: center;
}
.style4
{
text-align: center;
height: 50px;
}
.style5
{
height: 50px;
}
.style6
{
text-align: center;
height: 48px;
}
.style7
{
height: 48px;
}
</style>
</head>
<body bgcolor="#3333ff">
<form id="form1" runat="server">
<div class="style1" style="font-family: 'Trebuchet MS'; color: #FFFFFF">

This Experiment shows how DropDownList works in ASP.NET<br />


<br />

</div>
<div style="height: 207px">
<table class="style2">
<tr>
<td class="style6">
<asp:Label ID="Label1" runat="server" Font-Bold="True"
ForeColor="White"
Text="Write your Name here: "></asp:Label>
</td>
<td class="style7">
<asp:TextBox ID="TextBox1" runat="server"
Width="248px"></asp:TextBox>
</td>
</tr>
<tr>
<td class="style4">
<asp:Label ID="Label2" runat="server" Font-Bold="True"
ForeColor="White"
Text="Select your Country:"></asp:Label>
</td>
<td class="style5">
<asp:DropDownList ID="DropDownList1" runat="server"
Height="22px" Width="249px">
<asp:ListItem>India</asp:ListItem>
<asp:ListItem>Iran</asp:ListItem>
<asp:ListItem>Nepal</asp:ListItem>
<asp:ListItem>Pakistan</asp:ListItem>
<asp:ListItem>Sri Lanka</asp:ListItem>
<asp:ListItem>UK</asp:ListItem>
<asp:ListItem>USA</asp:ListItem>
</asp:DropDownList>
</td>
</tr>
<tr>
<td class="style3" colspan="2">
<asp:Button ID="Button1" runat="server" style="text-align:
center"
Text="Click Here" />
</td>
</tr>
</table>
</div>
</form>
</body>
</html>

VB Code Behind File:

Partial Class _Default


Inherits System.Web.UI.Page

Protected Sub Button1_Click(ByVal sender As Object, ByVal e As


System.EventArgs) Handles Button1.Click
MsgBox("Your Name is " & TextBox1.Text & " and you are from " &
DropDownList1.SelectedValue & " !!!", MsgBoxStyle.OkOnly, "Result")
End Sub
End Class
Output:
Experiment No. # 7
Write a program in ASP.Net using ListBox.

Page Source:
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb"
Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"


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

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Listbox</title>
<style type="text/css">
.style1
{
font-weight: bold;
text-decoration: underline;
font-size: x-large;
}
</style>
</head>
<body bgcolor="#3333ff">
<form id="form1" runat="server"
style="color: #FFFFFF; font-family: 'Trebuchet MS'">
<div class="style1">

This experiment demonstrates the use of ListBox in ASP.NET<br />


<br />

</div>
<div>
<asp:ListBox ID="ListBox1" runat="server" AutoPostBack="true"
Height="86px"
Width="105px">
<asp:ListItem>Grass</asp:ListItem>
<asp:ListItem>Sky</asp:ListItem>
<asp:ListItem>Soil</asp:ListItem>
<asp:ListItem>Cloud</asp:ListItem>
<asp:ListItem>Parrot</asp:ListItem>
</asp:ListBox>
&nbsp;&nbsp;&nbsp;
<asp:Label ID="Label1" runat="server" BackColor="White" Font-Bold="True"
Font-Size="X-Large" ForeColor="#66FF33" Text="Grass"
Visible="False"></asp:Label>
&nbsp;
<asp:Label ID="Label2" runat="server" BackColor="White" Font-Bold="True"
Font-Size="X-Large" ForeColor="#00CCFF" Text="Sky"
Visible="False"></asp:Label>
&nbsp;
<asp:Label ID="Label3" runat="server" BackColor="White" Font-Bold="True"
Font-Size="X-Large" ForeColor="#990000" Text="Soil"
Visible="False"></asp:Label>
&nbsp;
<asp:Label ID="Label4" runat="server" BackColor="White" Font-Bold="True"
Font-Size="X-Large" ForeColor="#666666" Text="Cloud"
Visible="False"></asp:Label>
&nbsp;
<asp:Label ID="Label5" runat="server" BackColor="#008400" Font-
Bold="True"
Font-Size="X-Large" ForeColor="Red" Text="Parrot"
Visible="False"></asp:Label>
</div>
</form>
</body>
</html>

VB Code Behind File:

Partial Class _Default


Inherits System.Web.UI.Page

Protected Sub ListBox1_SelectedIndexChanged(ByVal sender As Object, ByVal e


As System.EventArgs) Handles ListBox1.SelectedIndexChanged
If ListBox1.SelectedIndex = 0 Then
Label1.Visible = True
Else
Label1.Visible = False
End If
If ListBox1.SelectedIndex = 1 Then
Label2.Visible = True
Else
Label2.Visible = False
End If
If ListBox1.SelectedIndex = 2 Then
Label3.Visible = True
Else
Label3.Visible = False
End If
If ListBox1.SelectedIndex = 3 Then
Label4.Visible = True
Else
Label4.Visible = False
End If
If ListBox1.SelectedIndex = 4 Then
Label5.Visible = True
Else
Label5.Visible = False
End If

End Sub
End Class
Output:
Experiment No. # 8
Write a program in ASP.Net using DataList controls.

Page Source:
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb"
Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"


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

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Data List Controls</title>
<style type="text/css">
.style1
{
color: #FFFFFF;
font-weight: bold;
font-family: "Trebuchet MS";
text-decoration: underline;
font-size: x-large;
}
</style>
</head>
<body bgcolor="#3333ff">
<form id="form1" runat="server">
<div>

<span class="style1">This Experiment demonstrates the use of DataList


Control in
ASP.NET<br />
<br />
</span>
<br />

<asp:DataList ID="DataList1" runat="server" CellPadding="4"


ForeColor="#333333">
<FooterStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White"
/>
<AlternatingItemStyle BackColor="White" />
<ItemStyle BackColor="#E3EAEB" />
<SelectedItemStyle BackColor="#C5BBAF" Font-Bold="True"
ForeColor="#333333" />
<HeaderStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White"
/>
<ItemTemplate>
Item Number:
<asp:Label ID="IdLabel" runat="server" Text='<%# Eval("Id")%>'></asp:Label><br />
Text from Database:
<asp:Label ID="NameLabel" runat="server" Text='<%# Eval("detailtxt")
%>'></asp:Label><br />

</ItemTemplate>
</asp:DataList>

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

VB Code Behind File:

Partial Class _Default


Inherits System.Web.UI.Page

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)


Handles Me.Load
Dim con As New
System.Data.OleDb.OleDbConnection("provider='microsoft.jet.oledb.4.0';data
source='C:\Users\Kaash\Documents\Visual Studio 2008\ASP.net Lab
Exp\Exp8\App_Data\dbexp8.mdb'")
' Dim comm As New Data.OleDb.OleDbCommand("select 8 from details",
con)
Dim ds As New Data.DataSet
Dim da As New Data.OleDb.OleDbDataAdapter("select * from details", con)
con.Open()
da.Fill(ds, "details")
DataList1.DataSource = ds
DataList1.DataBind()
con.Close()

End Sub
End Class

Output:
Experiment No. # 9
Write a program in ASP.Net using DataList controls with styles.

Page Source:
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb"
Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"


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

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>Data List Controls</title>
<style type="text/css">
.style1
{
color: #FFFFFF;
font-weight: bold;
font-family: "Trebuchet MS";
text-decoration: underline;
font-size: x-large;
}
</style>
</head>
<body bgcolor="#3333ff">
<form id="form1" runat="server">
<div>

<span class="style1">This Experiment demonstrates the use of DataList


Control in
ASP.NET<br />
<br />
</span>
<br />

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb
sp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb
sp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;

<asp:DataList ID="DataList1" runat="server" CellPadding="4"


ForeColor="White"
BorderColor="Black" BorderStyle="Double" BorderWidth="10px"
Caption="Stylish DataList" CaptionAlign="Top" Width="624px">
<FooterStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White"
/>
<AlternatingItemStyle BackColor="Black" BorderColor="White"
BorderStyle="Dashed" BorderWidth="3px" />
<ItemStyle BackColor="Fuchsia" BorderColor="White"
BorderStyle="Dashed"
BorderWidth="3px" Font-Bold="False" Font-Names="Tahoma"
HorizontalAlign="Center" VerticalAlign="Middle" />
<SelectedItemStyle BackColor="#C5BBAF" Font-Bold="True"
ForeColor="#333333" />
<HeaderStyle BackColor="Fuchsia" Font-Bold="True" ForeColor="White"
/>
<ItemTemplate>
Item Number:
<asp:Label ID="IdLabel" runat="server" Text='<%# Eval("Id")%>'></asp:Label><br />
Text from Database:
<asp:Label ID="NameLabel" runat="server" Text='<%# Eval("detailtxt")
%>'></asp:Label><br />

</ItemTemplate>
</asp:DataList>

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

VB Code Behind File:

Partial Class _Default


Inherits System.Web.UI.Page

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)


Handles Me.Load
Dim con As New
System.Data.OleDb.OleDbConnection("provider='microsoft.jet.oledb.4.0';data
source='C:\Users\Kaash\Documents\Visual Studio 2008\ASP.net Lab
Exp\Exp8\App_Data\dbexp8.mdb'")
' Dim comm As New Data.OleDb.OleDbCommand("select 8 from details",
con)
Dim ds As New Data.DataSet
Dim da As New Data.OleDb.OleDbDataAdapter("select * from details", con)
con.Open()
da.Fill(ds, "details")
DataList1.DataSource = ds
DataList1.DataBind()
con.Close()

End Sub
End Class
Output:
Experiment No. # 10
Write a program in ASP.Net for validation in textbox.

Page Source:
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb"
Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"


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

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Textbox Validation</title>
<style type="text/css">
.style1
{
font-weight: bold;
text-decoration: underline;
font-size: x-large;
}
.style2
{
width: 74%;
}
.style3
{
text-align: left;
}
.style4
{
text-align: center;
}
</style>
</head>
<body bgcolor="#3333ff">
<form id="form1" runat="server">
<div class="style1" style="font-family: 'Trebuchet MS'; color: #FFFFFF">

This Experiment Demonstrates Validation in ASP.NET<br />


<br />

</div>
<div>
<table align="center" class="style2">
<tr>
<td class="style4">
<asp:Label ID="Label1" runat="server" Font-Bold="True"
Font-Names="Trebuchet MS" ForeColor="White" Text="Enter
your name: "></asp:Label>
</td>
<td class="style3">
<asp:TextBox ID="TextBox1" runat="server"
Width="234px"></asp:TextBox>
&nbsp;
<asp:RegularExpressionValidator
ID="RegularExpressionValidator1" runat="server"
BackColor="White" ControlToValidate="TextBox1"
ErrorMessage="Please Enter only string..."
ValidationExpression="^[a-zA-Z]+(([\'\,\.\- ][a-zA-Z ])?
[a-zA-Z]*)*$"></asp:RegularExpressionValidator>
</td>
</tr>
<tr>
<td class="style4">
<asp:Label ID="Label2" runat="server" Font-Bold="True"
Font-Names="Trebuchet MS" ForeColor="White" Text="Enter
your Contact: "></asp:Label>
</td>
<td class="style3">
<asp:TextBox ID="TextBox2" runat="server"
Width="234px"></asp:TextBox>
&nbsp;
<asp:RegularExpressionValidator
ID="RegularExpressionValidator2" runat="server"
BackColor="White" ControlToValidate="TextBox2"
ErrorMessage="Please Enter valid telephone number..."
ValidationExpression="^0{0,1}[1-9]{1}[0-9]{2}[\s]{0,1}
[\-]{0,1}[\s]{0,1}[1-9]{1}[0-9]{6}$"></asp:RegularExpressionValidator>
</td>
</tr>
<tr>
<td class="style4">
<asp:Label ID="Label3" runat="server" Font-Bold="True"
Font-Names="Trebuchet MS" ForeColor="White" Text="Enter
your E-mail: "></asp:Label>
</td>
<td class="style3">
<asp:TextBox ID="TextBox3" runat="server"
Width="234px"></asp:TextBox>
&nbsp;
<asp:RegularExpressionValidator
ID="RegularExpressionValidator3" runat="server"
BackColor="White" ControlToValidate="TextBox3"
ErrorMessage="Please Enter a valid e-mail..."
ValidationExpression="^[A-Za-z0-9](([_\.\-]?[a-zA-Z0-
9]+)*)@([A-Za-z0-9]+)(([\.\-]?[a-zA-Z0-9]+)*)\.([A-Za-z]{2,})
$"></asp:RegularExpressionValidator>
</td>
</tr>
<tr>
<td class="style4">
<asp:Label ID="Label4" runat="server" Font-Bold="True"
Font-Names="Trebuchet MS" ForeColor="White" Text="Enter
your username: "></asp:Label>
</td>
<td class="style3">
<asp:TextBox ID="TextBox4" runat="server"
Width="234px"></asp:TextBox>
&nbsp;
<asp:RequiredFieldValidator ID="RequiredFieldValidator1"
runat="server"
BackColor="White" ControlToValidate="TextBox4"
ErrorMessage="Please Enter
text..."></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td class="style4" colspan="2">
<asp:Button ID="Button1" runat="server" Text="Submit" />
</td>
</tr>
</table>
</div>
</form>
</body>
</html>

VB Code Behind File:

Partial Class _Default


Inherits System.Web.UI.Page

Protected Sub Button1_Click(ByVal sender As Object, ByVal e As


System.EventArgs) Handles Button1.Click
MsgBox("Submitted successfully!!!!", MsgBoxStyle.OkOnly,
"Congratulations!!")
End Sub
End Class

Output:

Vous aimerez peut-être aussi