CG Unit - I
CG Unit - I
______________________
PERIYAKULAM – 625604
APRIL - 2023
DEPARTMENT OF CS, BCA AND IT
PERIYAKULAM – 625604
Name : ....................................................
Reg. No : ……………………….
This is to certified to be the bonafide record for practical work done at Mary Matha
College of Arts and Science during the academic year 2022-23.
PAGE.
SIGN
S. No DATE TITLE No
ARITHMETIC OPERATION
4
USINGJAVASCRIPT
7 ANIMATE AN OBJECT
8 VALIDATE FORM
PAGE.
SIGN
S. No DATE TITLE No
2 REGISTERATION FORM
3 ADROTATOR CONTROL
4 CALENDER CONTROL
5 MULTIPLICATION TABLE
6 VALIDATION CONTROL
ALGORITHM:
PROGRAM:
<html>
<head>
<title> fibonacci.html </title>
</head>
<body style="background-color:pink">
<h3 style="text-align:center; color:white"> Program to generate the Fibonacci
Series </h3>
<script type="text/javascript">
var limit = prompt("Enter the limit 'n' to generate the fibonacci series:", " ");
var f1=0;
var f2=1;
var i,f3;
for(i=2; i<limit; i++)
{
f3=f1+f2;
document.write("<br>","",f3," ");
f1=f2;
f2=f3;
}
</script>
</body>
</html>
OUTPUT:
RESULT:
Thus the program was written, executed and verified successfully.
Ex.No:2
CHECK WHETHER PALINDROME
Date: OR NOT
AIM:
ALGORITHM:
PROGRAM:
<html>
<head>
<script>
function Palindrome()
{
var rem, temp, final = 0;
var number = Number(document.getElementById("N").value);
temp = number;
while(number>0)
{
rem = number%10;
number = parseInt(number/10);
final = final*10+rem;
}
if(final==temp)
{
window.alert("The inputed number is Palindrome");
}
else
{
window.alert("The inputted number is not palindrome");
}
}
</script>
</head>
<body>
<br>
<h1>Whether a number is Palindrome or not</h1>
Enter The Number :<input type="text" name="n" id = "N"/>
<hr color="cyan">
<br>
<center><button onClick="Palindrome()">CHECK</button>
</body>
</html>
OUTPUT:
RESULT:
Thus the program was written, executed and verified successfully.
Ex.No:3 TO VALID AN EMAIL ADDRESS
Date:
AIM:
ALGORITHM:
PROGRAM:
<html>
<body bgcolor="pink">
<script type="text/javascript">
RESULT:
ALGORITHM:
Step1: Start the program.
Step2: Design the from using the html tags.
Step3: Include the Java Script Coding To Perfrom Arithmetic
Operation Using Javascript.
Step4:Display the result.
PROGRAM:
<html>
<head>
<title>math</title>
<script type= "text/javascript ">
<!--
function oper()
{
var ch=parseInt(prompt( "Enter your choice 1.Addition 2.Subtraction
3.Multiplication 4.Division "));
switch(ch)
{
case 1:
var v1=parseInt(prompt( "Enter the first value "));
var v2=parseInt(prompt( "Enter the second value "));
var v3=v1+v2;
document.writeln( "<br> "+ "Addition: "+v3);
break;
case 2:
var v4=parseInt(prompt( "Enter the first value "));
var v5=parseInt(prompt( "Enter the second value "));
var v6=v4-v5;
document.writeln( "<br> "+ "Subtraction: "+v6);
break;
case 3:
var v7=parseInt(prompt( "Enter the first value "));
var v8=parseInt(prompt( "Enter the second value "));
var v9=v7*v8;
document.writeln( "<br> "+ "Multiplication: "+v9);
break;
case 4:
var v10=parseInt(prompt( "Enter the first value "));
var v11=parseInt(prompt( "Enter the second value "));
var v12=v10/v11;
document.writeln( "<br> "+ "Divison: "+v12);
break;
case 5:
var v13=parseInt(prompt( "Enter the first value "));
var v14=parseInt(prompt( "Enter the second value "));
var v15=v13%v14;
document.writeln( "<br> "+ "Modulus: "+v15);
break;
default:
document.writeln( "Enter choice correctly ");
}
}
</script>
</head>
<body bgcolor="green" onLoad= "oper()"></body>
</html>
OUTPUUT:
RESULT:
Thus the program was written, executed and verified successfully.
Ex.No:5
TO REMOVE ITEMS FROM A DROPDOWN LIST
Date:
AIM:
To write a JavaScript Program For Remove Items From A Drop Down List.
ALGORITHM:
PROGRAM:
<html>
<head>
</head>
<body>
<form>
<select id="colorSelect">
<option>Red</option>
<option>Green</option>
<option>White</option>
<option>Black</option>
<option>Purple</option>
<option>Blue</option>
</select>
<input type="button" onclick="removecolor()" value="Select and Remove">
</form>
</body>
</html>
Output:
RESULT:
ALGORITHM:
PROGRAM:
<html>
<head>
<title> Random Image Generator </title>
</head>
<script>
function getRandomImage() {
//declare an array to store the images
var randomImage = new Array();
</body>
</html>
OUTPUT:
RESULT:
Thus the program was written, executed and verified successfully.
Ex.No:7
ANIMATE AN OBJECT
Date:
AIM:
ALGORITHM:
PROGRAM:
<html>
<head>
<title>JavaScript Animation</title>
<script type = "text/javascript">
<!--
var imgObj = null;
function init() {
imgObj = document.getElementById('myImage');
imgObj.style.position= 'relative';
imgObj.style.left = '0px';
}
function moveRight() {
imgObj.style.left = parseInt(imgObj.style.left) + 10 + 'px';
}
window.onload = init;
//-->
</script>
</head>
<body>
<form>
<img id = "myImage" src = "/img/a.jpg" height=200 widt=200 />
<p>Click button below to move the image to right</p>
<input type = "button" value = "Click Me" onclick = "moveRight();" />
</form>
</body>
</html>
OUTPUT:
RESULT:
AIM:
ALGORITHM:
PROGRAM:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>JavaScript Form validation</title>
<link rel="stylesheet" href="/examples/css/form-style.css">
<script>
// Defining a function to display error message
function printError(elemId, hintMsg) {
document.getElementById(elemId).innerHTML = hintMsg;
}
// Validate name
if(name == "") {
printError("nameErr", "Please enter your name");
} else {
var regex = /^[a-zA-Z\s]+$/;
if(regex.test(name) === false) {
printError("nameErr", "Please enter a valid name");
} else {
printError("nameErr", "");
nameErr = false;
}
}
// Validate gender
if(gender == "") {
printError("genderErr", "Please select your gender");
} else {
printError("genderErr", "");
genderErr = false;
}
// Prevent the form from being submitted if there are any errors
if((nameErr || emailErr || mobileErr || countryErr || genderErr) == true) {
return false;
} else {
// Creating a string from input data for preview
var dataPreview = "You've entered the following details: \n" +
"Full Name: " + name + "\n" +
"Email Address: " + email + "\n" +
"Mobile Number: " + mobile + "\n" +
"Country: " + country + "\n" +
"Gender: " + gender + "\n";
if(hobbies.length)
{
dataPreview += "Hobbies: " + hobbies.join(", ");
}
// Display input data in a dialog box before submitting the form
alert(dataPreview);
docmet.write("Your Form has Successfully Registered");
}
};
</script>
</head>
<body>
<form name="contactForm" onsubmit="return validateForm()"
action="/examples/actions/confirmation.php" method="post">
<h2>Application Form</h2>
<div class="row">
<label>Full Name</label>
<input type="text" name="name">
<div class="error" id="nameErr"></div>
</div>
<div class="row">
<label>Email Address</label>
<input type="text" name="email">
<div class="error" id="emailErr"></div>
</div>
<div class="row">
<label>Mobile Number</label>
<input type="text" name="mobile" maxlength="10">
<div class="error" id="mobileErr"></div>
</div>
<div class="row">
<label>Country</label>
<select name="country">
<option>Select</option>
<option>Australia</option>
<option>India</option>
<option>United States</option>
<option>United Kingdom</option>
</select>
<div class="error" id="countryErr"></div>
</div>
<div class="row">
<label>Gender</label>
<div class="form-inline">
<label><input type="radio" name="gender" value="male"> Male</label>
<label><input type="radio" name="gender" value="female"> Female</label>
</div>
<div class="error" id="genderErr"></div>
</div>
<div class="row">
<label>Hobbies <i>(Optional)</i></label>
<div class="form-inline">
<label><input type="checkbox" name="hobbies[]" value="sports"> Sports</label>
<label><input type="checkbox" name="hobbies[]" value="movies"> Movies</label>
<label><input type="checkbox" name="hobbies[]" value="music"> Music</label>
</div>
</div>
<div class="row">
<input type="submit" value="Submit">
</div>
</form>
</body>
</html>
OUTPUT:
RESULT:
Thus the program was written, executed and verified successfully.
Ex.No:9
PRIME NUMBER CHECKING
Date:
AIM:
To write a JSP Program to check whether the given number is prime or not.
ALGORITHM:
PROGRAM:
//prime.html
<%--
Document : index
Created on : 12 Oct, 2012, 7:35:11 PM
Author : nested code team
--%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body><br><br><center>
<form action="primejsp.jsp ">
<h1>Enter the no :: <input type=text name=n ><br><br>
<input type=submit value="Submit"></h1>
</form></center>
</body>
</html>
//primejsp.jsp
<%--
Document : primejsp
Created on : 31 Oct, 2012, 11:59:34 AM
Author :NESTED CODE
--%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body><center><h1>The required Result is:: </h1>
<h2>
<%
int n,i,flag=0;
for(i=2;i<=n/2;i++)
{
if(n%i==0)
{
flag=1;
break;
}
}
}
if(flag==0)
{
out.println("<pre>");
out.println(n+" is a prime no.");
out.println("</pre>");
}
else
{
out.println("<pre>");
out.println(n+" is not a prime no.");
out.println("</pre>");
}
%>
</h2></center>
</body>
</html>
OUTPUT:
RESULT:
Thus the program was written, executed and verified successfully.
Ex.No:10
ADD THE CONTENTS OF ANOTHER JSP FILE
Date: USING @INCLUDE DIRECTIVE
AIM:
Write a JSP to add the contents of another JSP file using @include
directive.
ALGORITHM:
Step1: Start the program.
Step2: Design the from using the html tags.
Step3: Include the Java Script Coding to add the
contents of another JSP file using @include directive .
Step4:Display the result.
PROGRAM:
index.jsp
<html>
<head>
<title>Main JSP Page</title>
</head>
<body>
<%@ include file="file1.jsp" %>
Main JSP Page: Content between two include directives.
<%@ include file="file2.jsp" %>
</body>
file1.jsp
<palign="center">
This is my File1.jsp and I will include it in index.jsp using include directive
</p>
file2.jsp
<palign="center">
This is File2.jsp
</p>
OUTPUT:
RESULT:
Thus the program was written, executed and verified successfully.
Ex.No:11
FORWARD ONE JSP FILE TO
ANOTHERJSP FILE USING FORWARD
Date:
ACTION
AIM:
Write a JSP To forward one JSP file to anotherJSP file Using forward
Action.
ALGORITHM:
PROGRAM:
index.jsp
<html>
<head>
<title>JSP forward action tag example</title>
</head>
<body>
<palign="center">My main JSP page</p>
<jsp:forwardpage="display.jsp"/>
</body>
</html>
display.jsp
<html>
<head>
<title>Display Page</title>
</head>
<body>Hello this is a display.jsp Page</body>
</html>
OUTPUT:
RESULT:
Thus the program was written, executed and verified successfully.
ASP.NET
Ex.No: 01
CHANGING TEXT BOX FORE AND BACK COLOR
Date:
AIM:
To write an ASP.NET program to change the background and fore color of the
textbox.
ALGORITHM:
FORE CLOR.ASPX :
<%@PageLanguage="C#"AutoEventWireup="true"CodeBehind="WebForm1.aspx.cs"Inheri
ts="change_backcolor_and_forecolor.WebForm1"%>
<htmlxmlns="http://www.w3.org/1999/xhtml">
<headrunat="server">
<title></title>
</head>
<body>
<formid="form1"runat="server">
<divstyle="height: 226px; width: 1498px">
<h2style="color:Green">Changing Backcolor and Forecolor of Textbox</h2>
<asp:Label
ID="Label1"
runat="server"
Text="Enter Your Text"
></asp:Label>
<asp:TextBox
ID="TextBox1"
runat="server"style="z-index: 1; left: 240px; top: 72px; position: absolute"
>
</asp:TextBox>
<br/><br/>
<asp:Button
ID="Button1"
runat="server"
ForeColor="Red"
Text="Change the ForeColor"
OnClick="Button1_Click"
Font-Bold="true"
style="z-index: 1; left: 533px; top: 134px; position: absolute"Width="454px"
/>
<asp:Button
ID="Button2"
runat="server"
Font-Bold="true"
ForeColor="Red"
Text="Change The BackColor "
OnClick="Button2_Click"
style="z-index: 1; left: 72px; top: 134px; position: absolute; right: 1035px; margin-top:
0px"Width="421px"
/>
</div>
</form>
</body>
</html>
FORE COLOR.ASPX.CS :
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace change_backcolor_and_forecolor
{
publicpartialclassWebForm1 : System.Web.UI.Page
{
protectedvoid Page_Load(object sender, EventArgs e)
{
OUTPUT :
RESULT:
Thus, the above ASP. NET program has been successfully verified and output is
shown.
Ex.No:2
REGISTERATION FORM
Date:
AIM:
ALGORITHM:
Step 1: Open Microsoft Visual Studio 2010
Step 2: Click new project -> Asp.net web application with C#
Step 3: Solution explorer right click -> add -> new item -> webform with C#
Step 4: Place required controls for the application
Step 5: write the necessary coding in C#
Step 6: Run the application.
REGISTERATION.ASPX
<%@PageLanguage="C#"AutoEventWireup="true"CodeBehind="Registration
form.aspx.cs"Inherits="WebApplication14.WebForm1"%>
<htmlxmlns="http://www.w3.org/1999/xhtml">
<headrunat="server">
<styletype="text/css">
.auto-style1 {
width: 100%;
}
.auto-style2 {
width: 278px;
}
.auto-style3 {
width: 278px;
height: 23px;
}
.auto-style4 {
height: 23px;
}
</style>
<title>Registration Form</title>
</head>
<body>
<formid="form1"runat="server">
<div>
<tableclass="auto-style1">
<tr>
<td>
<asp:LabelID="Label1"runat="server"Text="User Name"></asp:Label>
</td>
<td>
<asp:TextBoxID="username"runat="server"required="true"></asp:TextBox></td>
</tr>
<tr>
<td>
<asp:LabelID="Label6"runat="server"Text="Email ID"></asp:Label>
</td>
<td>
<asp:TextBoxID="EmailID"runat="server"TextMode="Email"></asp:TextBox></td>
</tr>
<tr>
<td>
<asp:LabelID="Label2"runat="server"Text="Password"></asp:Label></td>
<td>
<asp:TextBoxID="TextBox2"runat="server"TextMode="Password"></asp:TextBox>
</td>
</tr>
<tr>
<td>
<asp:LabelID="Label3"runat="server"Text="Confirm Password"></asp:Label></td>
<td>
<asp:TextBoxID="TextBox3"runat="server"TextMode="Password"></asp:TextBox>
</td>
</tr>
<tr>
<td>
<asp:LabelID="Label4"runat="server"Text="Gender"></asp:Label></td>
<td>
<asp:RadioButtonID="RadioButton1"runat="server"GroupName="gender"Text="Ma
le"/>
<asp:RadioButtonID="RadioButton2"runat="server"GroupName="gender"Text="Fe
male"/></td>
</tr>
<tr>
<td>
<asp:LabelID="Label5"runat="server"Text="Select Course"></asp:Label>s</td>
<td>
<asp:CheckBoxID="CheckBox1"runat="server"Text="DOTNET"/>
<asp:CheckBoxID="CheckBox2"runat="server"Text="PYTHON"/>
<asp:CheckBoxID="CheckBox3"runat="server"Text="PHP"/>
</td>
</tr>
<tr>
<td>
</td>
<td>
<br/>
<asp:ButtonID="Button1"runat="server"Text="Register"CssClass="btn btn-
primary"OnClick="Button1_Click"/>
</td>
</tr>
</table>
<asp:LabelID="message"runat="server"Font-
Size="Medium"ForeColor="Red"></asp:Label>
</div>
</form>
<tableclass="auto-style1">
<tr>
<tdclass="auto-
style2"><asp:LabelID="ShowUserNameLabel"runat="server"></asp:Label></td>
<td>
<asp:LabelID="ShowUserName"runat="server"></asp:Label></td>
</tr>
<tr>
<tdclass="auto-
style2"><asp:LabelID="ShowEmailIDLabel"runat="server"></asp:Label></td>
<td>
<asp:LabelID="ShowEmail"runat="server"></asp:Label></td>
</tr>
<tr>
<tdclass="auto-
style3"><asp:LabelID="ShowGenderLabel"runat="server"></asp:Label></td>
<tdclass="auto-style4">
<asp:LabelID="ShowGender"runat="server"></asp:Label></td>
</tr>
<tr>
<tdclass="auto-
style2"><asp:LabelID="ShowCourseLabel"runat="server"></asp:Label></td>
<td>
<asp:LabelID="ShowCourses"runat="server"></asp:Label></td>
</tr>
</table>
</div>
</form>
</body>
</html>
REGISTERATION.ASPX.CS
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace WebApplication14
{
publicpartialclassWebForm1 : System.Web.UI.Page
{
protectedvoid Page_Load(object sender, EventArgs e)
{
TextBox1.Text = "";
TextBox2.Text = "";
TextBox3.Text = "";
TextBox4.Text = "";
RadioButton1.Checked = false;
RadioButton2.Checked = false;
CheckBox1.Checked = false;
CheckBox2.Checked = false;
CheckBox3.Checked = false;
}
}
}
OUTPUT:
RESULT:
Thus the above ASP. NET program has been successfully verified and output
is shown.
Ex.No:3 ADROTATOR CONTROL
Date:
AIM:
ALGORITHM:
Step 1: Open Microsoft Visual Studio 2010
Step 2: Click new project -> Asp.net web application with C#
Step 3: Solution explorer right click -> add -> new item -> webform with C#
Step 4: Place required controls for the application
Step 5: write the necessary coding in C#
Step 6: Run the application.
AD.xml
<?xml version="1.0" encoding="utf-8"?>
<Advertisements>
<Ad>
<ImageUrl>img/1.png</ImageUrl>
<NavigateUrl>https://meeraacademy.com</NavigateUrl>
<AlternateText>Meera Academy</AlternateText>
<Impressions>50</Impressions>
<Keyword>Meera</Keyword>
</Ad>
<Ad>
<ImageUrl>img/2.png</ImageUrl>
<NavigateUrl>http://meera.com</NavigateUrl>
<AlternateText>Meerta Aademy</AlternateText>
<Impressions>100</Impressions>
<Keyword>Academy</Keyword>
</Ad>
<Ad>
<ImageUrl>img/3.png</ImageUrl>
<NavigateUrl>https://meeraacademy.com</NavigateUrl>
<AlternateText>Meerta Aademy</AlternateText>
<Impressions>50</Impressions>
<Keyword>Academy</Keyword>
</Ad>
</Advertisements>
AD.ASPX
OUTPUT:
RESULT:
Thus, the above ASP. NET program has been successfully verified and output is
shown.
Ex.No:4
CALENDER CONTROL
Date:
AIM:
To write an ASP.NET program to design a calendar control.
ALGORITHM:
Step 1: Open Microsoft Visual Studio 2010
Step 2: Click new project -> Asp.net web application with C#
Step 3: Solution explorer right click -> add -> new item -> webform with C#
Step 4: Place required controls for the application
Step 5: write the necessary coding in C#
Step 6: Run the application.
CALENDER.ASPX
<%@PageLanguage="C#"AutoEventWireup="true"CodeBehind="WebForm1.aspx.cs"Inheri
ts="WebApplication16.WebForm1"%>
<htmlxmlns="http://www.w3.org/1999/xhtml">
<headrunat="server">
<title></title>
</head>
<bodystyle="height: 573px">
<formid="form1"runat="server">
<div>
</div>
<asp:CalendarID="Calendar1"runat="server"BackColor="#FFFFCC"
BorderColor="#FFCC66"BorderWidth="1px"DayNameFormat="Shortest"selectionmode=D
ayWeekMonth
Font-Names="Verdana"Font-Size="8pt"ForeColor="#663399"Height="200px"
ShowGridLines="True"Width="220px"
onselectionchanged="Calendar1_SelectionChanged">
<DayHeaderStyleBackColor="#FFCC66"Font-Bold="True"Height="1px"/>
<NextPrevStyleFont-Size="9pt"ForeColor="#FFFFCC"/>
<OtherMonthDayStyleForeColor="#CC9966"/>
<SelectedDayStyleBackColor="#CCCCFF"Font-Bold="True"/>
<SelectorStyleBackColor="#FFCC66"/>
<TitleStyleBackColor="#990000"Font-Bold="True"Font-Size="9pt"
ForeColor="#FFFFCC"/>
<TodayDayStyleBackColor="#FFCC66"ForeColor="White"/>
</asp:Calendar>
<asp:TextBoxID="TextBox1"runat="server"
style="z-index: 1; left: 388px; top: 285px; position: absolute"></asp:TextBox>
<br/>
&nbs
p; &n
bsp;
Today's date</form>
</body>
</html>
CALENDER.SAPX.CS
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace WebApplication16
{
publicpartialclassWebForm1 : System.Web.UI.Page
{
protectedvoid Page_Load(object sender, EventArgs e)
{
RESULT:
Thus, the above ASP. NET program has been successfully verified and output is show
Ex.No:5
MULTIPLICATION TABLE
Date:
AIM:
To write an ASP.NET program to change the background and fore color of the
textbox.
ALGORITHM:
Step 1: Open Microsoft Visual Studio 2010
Step 2: Click new project -> Asp.net web application with C#
Step 3: Solution explorer right click -> add -> new item -> webform with C#
Step 4: Place required controls for the application
Step 5: write the necessary coding in C#
Step 6: Run the application.
MULTIPLICATION T.ASPX
<%@PageLanguage="C#"AutoEventWireup="true"CodeBehind="WebForm1.aspx.cs"Inheri
ts="multiplication_table.WebForm1"%>
<htmlxmlns="http://www.w3.org/1999/xhtml">
<headrunat="server">
<title></title>
<styletype="text/css">
.style1
{
height: 50px;
}
.style2
{
height: 44px;
}
</style>
</head>
<body>
<formid="form1"runat="server">
<div><center><h2>MULTIPLICATION TABLE</h2></center>
<table>
<tr><td>Table
Number</td><td><asp:textboxid="txtinputno"runat="server"xmlns:asp="#unknown"></asp:
textbox></td></tr>
<tr><tdclass="style2">Enter the
limit</td><tdclass="style2"><asp:textboxid="txtlimit"runat="server"xmlns:asp="#unknown"
></asp:textbox></td></tr>
<tr><tdcolspan="2">
<asp:ButtonID="Button1"runat="server"Text="Generate Table"Width="219px"
onclick="Button1_Click"/>
</td></tr>
<tr><tdcolspan="2"class="style1">
<asp:LabelID="Label1"runat="server"
style="z-index: 1; left: 402px; top: 208px; position: absolute; width: 155px; right: 971px;
margin-top: 6px"></asp:Label>
</td></tr>
</table>
</div>
</form>
</body>
</html>
MULTIPLICATION .ASPX.CS
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Text;
namespace multiplication_table
{
publicpartialclassWebForm1 : System.Web.UI.Page
{
protectedvoid Page_Load(object sender, EventArgs e)
{
{
int number, limit;
StringBuilder sb = newStringBuilder();
number = Convert.ToInt32(txtinputno.Text);
limit = Convert.ToInt32(txtlimit.Text);
RESULT:
Thus, the above ASP. NET program has been successfully verified and output is
shown.
Ex.No:6
VALIDATION CONTROL
Date:
AIM:
To write an ASP.NET program to create a validation control.
ALGORITHM:
Step 1: Open Microsoft Visual Studio 2010
Step 2: Click new project -> Asp.net web application with C#
Step 3: Solution explorer right click -> add -> new item -> webform with C#
Step 4: Place required controls for the application
Step 5: write the necessary coding in C#
Step 6: Run the application.
VALIDATION.ASPX:
<%@PageLanguage="C#"AutoEventWireup="true"CodeBehind="WebForm1.aspx.cs"Inheri
ts="validation_Control.WebForm1"%>
<htmlxmlns="http://www.w3.org/1999/xhtml">
<headrunat="server">
<title>validation control</title>
<styletype="text/css">
.auto-style1 {
width: 100%;
}
.auto-style2 {
width: 144px;
}
.auto-style3 {
width: 144px;
text-align: right;
}
.auto-style4 {
width: 136px;
}
.auto-style5 {
width: 144px;
text-align: right;
height: 26px;
}
.auto-style6 {
width: 136px;
height: 26px;
}
.auto-style7 {
height: 26px;
}
</style>
</head>
<body>
<formid="form1"runat="server">
<center> VALIDATION CONTROL</center>
<tableclass="auto-style1">
<tr>
<tdclass="auto-style3">User Name</td>
<tdclass="auto-style4">
<asp:TextBoxID="txtname"runat="server"Width="180px"></asp:TextBox>
</td>
<td>
<asp:RequiredFieldValidatorID="RequiredFieldValidator1"runat="server"ControlToValidate
="txtname"ErrorMessage="Plz Enter
UserName"ForeColor="Fuchsia"></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<tdclass="auto-style3">Enter Email</td>
<tdclass="auto-style4">
<asp:TextBoxID="txtemail"runat="server"Width="180px"></asp:TextBox>
</td>
<td>
<asp:RequiredFieldValidatorID="RequiredFieldValidator2"runat="server"ControlToValidate
="txtemail"ErrorMessage="Enter
EmailID"ForeColor="Fuchsia"></asp:RequiredFieldValidator>
<br/>
<asp:RegularExpressionValidatorID="RegularExpressionValidator1"runat="server"ControlT
oValidate="txtemail"ErrorMessage="Plz Enter Correct
EmailID"ForeColor="Fuchsia"ValidationExpression="\w+([-+.']\w+)*@\w+([-
.]\w+)*\.\w+([-.]\w+)*"></asp:RegularExpressionValidator>
</td>
</tr>
<tr>
<tdclass="auto-style3">Enter Password</td>
<tdclass="auto-style4">
<asp:TextBoxID="txtpass"runat="server"Width="180px"TextMode="Password"></asp:Text
Box>
</td>
<td>
<asp:RequiredFieldValidatorID="RequiredFieldValidator3"runat="server"ControlToValidate
="txtpass"ErrorMessage="Plz Enter
Password"ForeColor="Fuchsia"></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<tdclass="auto-style5">ReEnter Password</td>
<tdclass="auto-style6">
<asp:TextBoxID="txtrepass"runat="server"Width="180px"TextMode="Password"></asp:Te
xtBox>
</td>
<tdclass="auto-style7">
<asp:RequiredFieldValidatorID="RequiredFieldValidator4"runat="server"ControlToValidate
="txtrepass"ErrorMessage="ReEnter
Password"ForeColor="Fuchsia"></asp:RequiredFieldValidator>
<br/>
<asp:CompareValidatorID="CompareValidator1"runat="server"ControlToCompare="txtpass
"ControlToValidate="txtrepass"ErrorMessage="Password must me
same"ForeColor="Fuchsia"></asp:CompareValidator>
</td>
</tr>
<tr>
<tdclass="auto-style3">Enter Full Name</td>
<tdclass="auto-style4">
<asp:TextBoxID="txtFn"runat="server"Width="180px"></asp:TextBox>
</td>
<td>
<asp:RequiredFieldValidatorID="RequiredFieldValidator5"runat="server"ControlToValidate
="txtFn"ErrorMessage="Plz Enter Full
Name"ForeColor="Fuchsia"></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<tdclass="auto-style3">Select Your Country</td>
<tdclass="auto-style4">
<asp:DropDownListID="ddlCity"runat="server"Width="187px">
<asp:ListItemValue="0"Selected="True">--Select--</asp:ListItem>
<asp:ListItemValue="1">India</asp:ListItem>
<asp:ListItemValue="2">Australia</asp:ListItem>
<asp:ListItemValue="3">America</asp:ListItem>
<asp:ListItemValue="4">South Africa</asp:ListItem>
<asp:ListItemValue="5">England</asp:ListItem>
<asp:ListItemValue="6">Kenya</asp:ListItem>
<asp:ListItemValue="7">WestIndies</asp:ListItem>
</asp:DropDownList>
</td>
<td>
<asp:RequiredFieldValidatorID="RequiredFieldValidator6"runat="server"InitialValue="0"C
ontrolToValidate="ddlCity"ErrorMessage="Plz Select Your
Country"ForeColor="Fuchsia"></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<tdclass="auto-style2"></td>
<tdclass="auto-style4"></td>
<td></td>
</tr>
<tr>
<tdclass="auto-style2"></td>
<tdclass="auto-style4">
<asp:ButtonID="Button1"runat="server"Text="SUBMIT"ForeColor="Red"
OnClick="Button1_Click"Width="117px"/>
</td>
<td>
<asp:LabelID="Label1"runat="server"Text="Label"Visible="false"></asp:Label>
</td>
</tr>
</table>
<div>
</div>
</form>
<p>
</p>
</body>
</html>
VALIDATION.ASPX.CS
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace validation_Control
{
publicpartialclassWebForm1 : System.Web.UI.Page
{
protectedvoid Page_Load(object sender, EventArgs e)
{
}
protectedvoid Button1_Click(object sender, EventArgs e)
{
Label1.Visible = true;
Label1.Text = "All Validator working Perfectly!!!!!!";
}
}
}
OUTPUT:
RESULT:
Thus, the above ASP. NET program has been successfully verified and output is
shown.
Ex.No:7
DISPLAY STUDENT DETAILS FROM
Date: XML FILE
AIM:
To write an ASP.NET program to display the student details from xml file.
ALGORITHM:
Step 1: Open Microsoft Visual Studio 2010
Step 2: Click new project -> Asp.net web application with C#
Step 3: Solution explorer right click -> add -> new item -> webform with C#
Step 4: Place required controls for the application
Step 5: Iinclude the xml file
Solution explorer right click -> add -> new item -> xml file.
Step 6: write the necessary coding in C#
Step 7: Run the application.
Webfrom1.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
namespace WebApplication11
{
publicpartialclassWebForm1 : System.Web.UI.Page
{
protectedvoid Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
this.BindGrid();
}
privatevoid BindGrid()
{
using(DataSet ds = newDataSet())
{
ds.ReadXml(Server.MapPath ("~/student.xml"));
GridView1.DataSource=ds;
GridView1.DataBind();
}
}
}
}
Webfrom1.aspx
<htmlxmlns="http://www.w3.org/1999/xhtml">
<headrunat="server">
<title></title>
</head>
<body>
<formid="form1"runat="server">
<divstyle="height:276px">
<asp:GridViewID="GridView1"runat="server"BackColor="Aqua">
<Columns>
<asp:BoundFieldDataField="sname"HeaderText="Student name"ItemStyle-Width="80"/>
<asp:BoundFieldDataField="regno"HeaderText="Register No"ItemStyle-Width="90"/>
<asp:BoundFieldDataField="m1"HeaderText="Mark1"ItemStyle-Width="80"/>
<asp:BoundFieldDataField="m2"HeaderText="Mark2"ItemStyle-Width="90"/>
<asp:BoundFieldDataField="m3"HeaderText="Mark3"ItemStyle-Width="80"/>
<asp:BoundFieldDataField="m4"HeaderText="Mark4"ItemStyle-Width="90"/>
<asp:BoundFieldDataField="m5"HeaderText="Mark5"ItemStyle-Width="80"/>
</Columns>
</asp:GridView>
</div>
</form>
</body>
</html>
Student.xml
<?xmlversion="1.0"encoding="utf-8" ?>
<studentdetail>
<student>
<sname>Anu</sname>
<regno>101</regno>
<m1>67</m1>
<m2>89</m2>
<m3>78</m3>
<m4>80</m4>
<m5>90</m5>
</student>
<student>
<sname>salo</sname>
<regno>103</regno>
<m1>90</m1>
<m2>85</m2>
<m3>70</m3>
<m4>56</m4>
<m5>78</m5>
</student>
<student>
<sname>nivi</sname>
<regno>135</regno>
<m1>68</m1>
<m2>49</m2>
<m3>90</m3>
<m4>58</m4>
<m5>70</m5>
</student>
</studentdetail>
OUTPUT:
RESULT:
Thus the above ASP. NET program has been successfully verified and output is
shown.
Ex.No: 8
DISPLAYING VEHICELS DETAILS
Date: USING TREE VIEW CONTROL
AIM:
To write an ASP.NET program to display the vehicle details using Tree view control.
ALGORITHM:
Step 1: Open Microsoft Visual Studio 2010
Step 2: Click new project -> Asp.net web application with C#
Step 3: Solution explorer right click -> add -> new item -> webform with C#
Step 4: Place required controls for the application
Step 5: Iinclude the xml file
Solution explorer right click -> add -> new item -> xml file.
Step 6: write the necessary coding in C#
Step 7: Run the application.
VEHICLE.ASPX
<%@PageLanguage="C#"AutoEventWireup="true"CodeBehind="WebForm1.aspx.cs"Inheri
ts="WebApplication6.WebForm1"%>
<htmlxmlns="http://www.w3.org/1999/xhtml">
<headrunat="server">
<title></title>
</head>
<body>
<formid="form1"runat="server">
<divstyle="height: 402px">
<asp:LabelID="Label1"runat="server"BackColor="Aqua"
style="z-index: 1; left: 539px; top: 31px; position: absolute; width: 205px"
Text="Vehicle Details"></asp:Label>
<asp:TreeViewID="TreeView1"runat="server"
style="z-index: 1; left: 221px; top: 109px; position: absolute; height: 160px; width: 116px"
DataSourceID="XmlDataSource1">
</asp:TreeView>
<asp:XmlDataSourceID="XmlDataSource1"runat="server"DataFile="~/vehicle.xml"XPath=
"/vehicles"></asp:XmlDataSource>
</div>
</form>
</body>
</html>
VEHICLE.XML
<?xmlversion="1.0"encoding="utf-8" ?>
<vehicles>
<cars>
<Alto/>
<BMW/>
<Hyundai/>
<Audi/>
</cars>
<bikes>
<TVS/>
<Yamaha/>
<RoyalEnfield/>
<Honda/>
</bikes>
</vehicles>
OUTPUT:
RESULT:
Thus, the above ASP. NET program has been successfully verified and output is
shown.
Ex.No: 9
DISPLAYING BOOK DETAILS FROM
Date: XML FILE
AIM:
To write an ASP.NET program to display the book details from xml file.
ALGORITHM:
Step 1: Open Microsoft Visual Studio 2010
Step 2: Click new project -> Asp.net web application with C#
Step 3: Solution explorer right click -> add -> new item -> webform with C#
Step 4: Place required controls for the application
Step 5: Iinclude the xml file
Solution explorer right click -> add -> new item -> xml file.
Step 6: write the necessary coding in C#
Step 7: Run the application.
BOOK.ASPX
<%@PageLanguage="C#"AutoEventWireup="true"CodeBehind="Book deatails using
Grid.aspx.cs"Inherits="Book_Details_using_Grid.Book_deatails_using_Grid"%>
<htmlxmlns="http://www.w3.org/1999/xhtml">
<headrunat="server">
<title></title>
</head>
<body>
<formid="form1"runat="server">
<divstyle="height: 247px">
<asp:GridViewID="GridView1"runat="server"BackColor="White"
BorderColor="#CC9966"BorderStyle="None"BorderWidth="1px"CellPadding="4">
<FooterStyleBackColor="#FFFFCC"ForeColor="#330099"/>
<HeaderStyleBackColor="#990000"Font-Bold="True"ForeColor="#FFFFCC"/>
<PagerStyleBackColor="#FFFFCC"ForeColor="#330099"HorizontalAlign="Center"/>
<RowStyleBackColor="White"ForeColor="#330099"/>
<SelectedRowStyleBackColor="#FFCC66"Font-Bold="True"ForeColor="#663399"/>
<SortedAscendingCellStyleBackColor="#FEFCEB"/>
<SortedAscendingHeaderStyleBackColor="#AF0101"/>
<SortedDescendingCellStyleBackColor="#F6F0C0"/>
<SortedDescendingHeaderStyleBackColor="#7E0000"/>
</asp:GridView>
</div>
</form>
</body>
</html>
BOOK.XML
<?xmlversion="1.0"encoding="utf-8" ?>
<Books>
<Book>
<Book_no>101</Book_no>
<BookName>ANSI C</BookName>
<Page>95</Page>
<PRICE>100</PRICE>
<Author>E.Balagurusamy</Author>
</Book>
<Book>
<Book_no>102</Book_no>
<BookName>C</BookName>
<Page>120</Page>
<PRICE>500</PRICE>
<Author>E.Balagurusamy</Author>
</Book>
<Book>
<Book_no>103</Book_no>
<BookName>JAVA</BookName>
<Page>200</Page>
<PRICE>650</PRICE>
<Author>E.Balagurusamy</Author>
</Book>
<Book>
<Book_no>104</Book_no>
<BookName>C++</BookName>
<Page>670</Page>
<PRICE>700</PRICE>
<Author>E.Balagurusamy</Author>
</Book>
<Book>
<Book_no>105</Book_no>
<BookName>ASP.NET</BookName>
<Page>840</Page>
<PRICE>1045</PRICE>
<Author>Bill Evjen</Author>
</Book>
</Books>
Book.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
namespace Book_Details_using_Grid
{
publicpartialclassBook_deatails_using_Grid : System.Web.UI.Page
{
protectedvoid Page_Load(object sender, EventArgs e)
{
DataSet ds = newDataSet();
ds.ReadXml(Server.MapPath("~/book.xml"));
GridView1.DataSource = ds;
GridView1.DataBind();
}
}
OUTPUT:
RESULT:
Thus, the above ASP. NET program has been successfully verified and output is
shown.
Ex.No: 10
DISPLAYING COUNTRY DETAILS
Date: USING TREE VIEW CONTROL
AIM:
To write an ASP.NET program to display the country details using Tree view control.
ALGORITHM:
Step 1: Open Microsoft Visual Studio 2010
Step 2: Click new project -> Asp.net web application with C#
Step 3: Solution explorer right click -> add -> new item -> webform with C#
Step 4: Place required controls for the application
Step 5: Iinclude the xml file
Solution explorer right click -> add -> new item -> xml file.
Step 6: write the necessary coding in C#
Step 7: Run the application.
COUNTRY.XML
<?xmlversion="1.0"encoding="utf-8" ?>
<country>
<India>
<TamilNadu/>
<AndhraPradesh/>
<Kerala/>
<Karnataka/>
<Assam/>
<Maharashtra/>
</India>
<America>
<Washington/>
<Newyark/>
</America>
</country>
COUNTRY.ASPX
<%@PageLanguage="C#"AutoEventWireup="true"CodeBehind="WebForm1.aspx.cs"Inheri
ts="countrydetails.WebForm1"%>
<htmlxmlns="http://www.w3.org/1999/xhtml">
<headrunat="server">
<title></title>
</head>
<body>
<formid="form1"runat="server">
<div>
<asp:XmlDataSourceID="XmlDataSource1"runat="server"DataFile="~/country.xml">
</asp:XmlDataSource>
<asp:LabelID="Label1"runat="server"ForeColor="#FF6600"
style="z-index: 1; left: 497px; top: 49px; position: absolute; width: 233px"
Text="Country details"></asp:Label>
<asp:TreeViewID="TreeView1"runat="server"DataSourceID="XmlDataSource1"
ImageSet="BulletedList4"ShowExpandCollapse="False"
style="z-index: 1; left: 445px; top: 113px; position: absolute; height: 195px; width: 129px">
<HoverNodeStyleFont-Underline="True"ForeColor="#5555DD"/>
<NodeStyleFont-Names="Tahoma"Font-Size="10pt"ForeColor="Black"
HorizontalPadding="5px"NodeSpacing="0px"VerticalPadding="0px"/>
<ParentNodeStyleFont-Bold="False"/>
<SelectedNodeStyleFont-Underline="True"ForeColor="#5555DD"
HorizontalPadding="0px"VerticalPadding="0px"/>
</asp:TreeView>
</div>
</form>
</body>
</html>
OUTPUT:
RESULT:
Thus, the above ASP. NET program has been successfully verified and output is
shown.
Ex.No: 11
DISPLAYING STUDENT DETAILS
Date: FROM DATABASE
AIM:
To write an ASP.NET program to display the student details using SqlDataSource and
Grid view.
ALGORITHM:
Step 1: Open Microsoft Visual Studio 2010
Step 2: Click new project -> Asp.net web application with C#
Step 3: Solution explorer right click -> add -> new item -> webform with C#
Step 4: Place required controls for the application
Step 5: Iinclude the xml file
Solution explorer right click -> add -> new item -> xml file.
Step 6: write the necessary coding in C#
Step 7: Run the application.
STUDENT.ASPX.CS
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Configuration;
namespace DatabaseConnectivity
{
public partial class loginpage System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if(IsPostBack)
{
SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrin
gs["RegiConnectionString"].ConnectionString);
conn.Open();
string checkuser = "select count(*) from RegisterDataBase where StudentName='"
+TextBox1.Text+"'";
SqlCommand cmd = new SqlCommand(checkuser, conn);
int temp = Convert.ToInt32(cmd.ExecuteScalar().ToString());
if (temp == 1)
{
Response.Write("Student Already Exist");
}
conn.Close();
}
conn.Close();
}
catch (Exception ex)
{
Response.Write("error" + ex.ToString());
}
}
}
}
STUDENT.ASPX
<!DOCTYPE html>
<html xmlns="http//www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<link href="stylepage.css" type="text/css" rel="stylesheet" />
<style type="text/css">
.auto-style1 {
width 100%;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div id="title">
<h1>REGISTER PAGE</h1>
</div>
<div id ="teble"></div>
<table class="auto-style1">
<tr>
<td>
<aspLabel ID="Label1" runat="server" Text="StudentName"></aspLabel></td>
<td>
<aspTextBox ID="TextBox1" runat="server"></aspTextBox></td>
</tr>
<tr>
<td>
<aspLabel ID="Label2" runat="server" Text="Password"></aspLabel></td>
<td>
<aspTextBox ID="TextBox2" runat="server"></aspTextBox></td>
</tr>
<tr>
<td>
<aspLabel ID="Label3" runat="server" Text="EmailId"></aspLabel></td>
<td>
<aspTextBox ID="TextBox3" runat="server"></aspTextBox></td>
</tr>
<tr>
<td>
<aspLabel ID="Label4" runat="server" Text="Department"></aspLabel></td>
<td>
<aspTextBox ID="TextBox4" runat="server"></aspTextBox></td>
</tr>
<tr>
<td>
<aspLabel ID="Label5" runat="server" Text="College"></aspLabel></td>
<td>
<aspTextBox ID="TextBox5" runat="server"></aspTextBox></td>
</tr>
</table>
<div id="button">
<aspButton ID="Button1" runat="server" Text="submit" OnClick="Button1_Click" Bac
kColor="Yellow" />
</div>
<div id="sim"></div>
<aspSqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ Con
nectionStringsRegiConnectionString %>" SelectCommand="SELECT * FROM [RegisterDat
aBase]"></aspSqlDataSource>
<div id="grid">
<aspGridView ID="GridView1" runat="server" AllowPaging="True" AllowSorting=
"True" AutoGenerateColumns="False" CellPadding="4" DataSourceID="SqlDataSource1" F
oreColor="#333333" GridLines="None">
<AlternatingRowStyle BackColor="White" ForeColor="#284775" />
<Columns>
<aspBoundField DataField="Id" HeaderText="Id" SortExpression="Id" />
<aspBoundField DataField="StudentName" HeaderText="StudentName" SortEx
pression="StudentName" />
<aspBoundField DataField="Passwords" HeaderText="Passwords" SortExpressi
on="Passwords" />
<aspBoundField DataField="EmailId" HeaderText="EmailId" SortExpression="
EmailId" />
<aspBoundField DataField="Department" HeaderText="Department" SortExpre
ssion="Department" />
<aspBoundField DataField="College" HeaderText="College" SortExpression="
College" />
</Columns>
<EditRowStyle BackColor="#999999" />
<FooterStyle BackColor="#5D7B9D" -Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#5D7B9D" -Bold="True" ForeColor="White" />
<PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center"
/>
<RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
<SelectedRowStyle BackColor="#E2DED6" -
Bold="True" ForeColor="#333333" />
<SortedAscendingCellStyle BackColor="#E9E7E2" />
<SortedAscendingHeaderStyle BackColor="#506C8C" />
<SortedDescendingCellStyle BackColor="#FFFDF8" />
<SortedDescendingHeaderStyle BackColor="#6F8DAE" />
</aspGridView>
</div>
<div id="last">
<h3>Developed by
Muthuramalingam Duraipandi</h3>
</div>
</form>
</body>
</html>
OUTPUT:
RESULT:
Thus, the above ASP. NET program has been successfully verified and output is
shown.
Ex.No: 12
EMPLOYEE DETAILS USING XML
Date: DATA SOURCE
AIM:
To write an ASP.NET program to display the employee details from using Grid view.
ALGORITHM:
Step 1: Open Microsoft Visual Studio 2010
Step 2: Click new project -> Asp.net web application with C#
Step 3: Solution explorer right click -> add -> new item -> webform with C#
Step 4: Place required controls for the application
Step 5: Iinclude the xml file
Solution explorer right click -> add -> new item -> xml file.
Step 6: write the necessary coding in C#
Step 7: Run the application.
EMPLOYEE.XML
<Employees>
<EmployeeId ="1"City ="Chennai">
<EmployeeName>Arun</EmployeeName>
<Country>India</Country>
</Employee>
<EmployeeId ="2"City ="Madurai">
<EmployeeName>Bhavani</EmployeeName>
<Country>India</Country>
</Employee>
<EmployeeId ="3"City ="Coimbatore">
<EmployeeName>Kannan</EmployeeName>
<Country>India</Country>
</Employee>
<EmployeeId ="4"City ="London">
<EmployeeName>Jhon</EmployeeName>
<Country>UK</Country>
</Employee>
<EmployeeId ="5"City = "Newyork">
<EmployeeName>Stephen</EmployeeName>
<Country>USA</Country>
</Employee>
<EmployeeId ="6"City ="Chennai">
<EmployeeName>David</EmployeeName>
<Country>India</Country>
</Employee>
<EmployeeId ="7"City ="London">
<EmployeeName>Robert King</EmployeeName>
<Country>UK</Country>
</Employee>
<EmployeeId ="8"City ="Seattle">
<EmployeeName>Laura Callahan</EmployeeName>
<Country>USA</Country>
</Employee>
<EmployeeId ="9"City ="London">
<EmployeeName>Anne Dodsworth</EmployeeName>
<Country>UK</Country>
</Employee>
</Employees>
EMPLOYEE.ASPX
<%@PageLanguage="C#"AutoEventWireup="true"CodeBehind="WebForm1.aspx.cs"Inheri
ts="Employee_details.WebForm1"%>
<htmlxmlns="http://www.w3.org/1999/xhtml">
<headrunat="server">
<title></title>
</head>
<body>
<formid="form1"runat="server">
<div>
<asp:DropDownListID="ddlCities"runat="server"OnSelectedIndexChanged="CityChanged"
AutoPostBack="true"style="z-index: 1; left: 401px; top: 12px; position: absolute">
<asp:ListItemText="All"Value=""/>
<asp:ListItemText="Madurai"Value="Seattle"/>
<asp:ListItemText="Chennai"Value="Tacoma"/>
<asp:ListItemText="Coimbatore"Value="Kirkland"/>
<asp:ListItemText="America"Value="Redmond"/>
<asp:ListItemText="London"Value="London"/>
</asp:DropDownList>
Country:
<asp:DropDownListID="ddlCountries"runat="server"OnSelectedIndexChanged="CountryCh
anged"
AutoPostBack="true"
style="z-index: 1; left: 96px; top: 15px; position: absolute; width: 98px; margin-top: 0px">
<asp:ListItemText="All"Value=""/>
<asp:ListItemText="India"Value="India"/>
<asp:ListItemText="USA"Value="USA"/>
<asp:ListItemText="UK"Value="UK"/>
</asp:DropDownList>
&nbs
p;
City:
<hr/>
<asp:XmlDataSourceID="XmlDataSource1"runat="server"DataFile="~/employee.xml">
</asp:XmlDataSource>
<asp:GridViewID="GridView1"runat="server"XPath="/Employees/Employee"DataSourceI
D="XmlDataSource1"
AutoGenerateColumns="False"HeaderStyle-BackColor="#3AC0F2"
HeaderStyle-ForeColor="White"
style="z-index: 1; left: 165px; top: 132px; position: absolute; height: 180px; width: 437px">
<Columns>
<asp:TemplateFieldHeaderText="Id"HeaderStyle-Width="50">
<ItemTemplate>
<%# XPath("@Id") %>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateFieldHeaderText="Name"HeaderStyle-Width="100">
<ItemTemplate>
<%# XPath("EmployeeName") %>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateFieldHeaderText="City"HeaderStyle-Width="100">
<ItemTemplate>
<%# XPath("@City") %>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateFieldHeaderText="Country"HeaderStyle-Width="100">
<ItemTemplate>
<%# XPath("Country") %>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</div>
</form>
</body>
</html>
EMPLOYEE.ASP.CS
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace Employee_details
{
publicpartialclassWebForm1 : System.Web.UI.Page
{
protectedvoid Page_Load(object sender, EventArgs e)
{
}
}
}
OUTPUT:
RESULT:
Thus, the above ASP. NET program has been successfully verified and output is
shown.
Ex.No: 13
MENU SERVER CONTROL
Date:
AIM:
To write an ASP.NET program using menu server control.
ALGORITHM:
Step 1: Open Microsoft Visual Studio 2010
Step 2: Click new project -> Asp.net web application with C#
Step 3: Solution explorer right click -> add -> new item -> webform with C#
Step 4: Place required controls for the application
Step 5: write the necessary coding in C#
Step 6: Run the application.
DYNAMIC MENU.ASPX
color: #444;
} <%@ Page Language="C#" AutoEventWireup="true" CodeFile="DynamicMenu.asp
x.cs" Inherits="DynamicMenu" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Dynamic Menu Control Article for C# Corner by Upendra Pratap Shahi</title>
<style type="text/css">
body {
background-color: mediumaquamarine;
font-family: Arial;
font-size: 10pt;
.ParentMenu, .ParentMenu:hover {
width: 100px;
background-color: #fff;
color: #333;
text-align: center;
height: 30px;
line-height: 30px;
margin-right: 5px;
}
.ParentMenu:hover {
background-color: #ccc;
}
.ChildMenu, .ChildMenu:hover {
width: 110px;
background-color: #fff;
color: #333;
text-align: center;
height: 30px;
line-height: 30px;
margin-top: 5px;
}
.ChildMenu:hover {
background-color: #ccc;
}
.selected, .selected:hover {
background-color: #A6A6A6 !important;
color: #fff;
}
.level2 {
background-color: #fff;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Menu ID="Menu1" runat="server" Orientation="Horizontal">
<LevelMenuItemStyles>
<asp:MenuItemStyle CssClass="ParentMenu" />
<asp:MenuItemStyle CssClass="ChildMenu" />
<asp:MenuItemStyle CssClass="ChildMenu" />
</LevelMenuItemStyles>
<StaticSelectedStyle CssClass="selected" />
</asp:Menu>
</div>
</form>
</body>
</html>
Adding the following namespaces in the namespace section of your code behind page.
using System.IO;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
Now your page looks as in the following.
DYNAMIC MENU.ASPX.CS
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
ds.Tables.Add(dt);
var dv = ds.Tables[0].DefaultView;
dv.RowFilter = "ParentId='" + parentmenuId + "'";
DataSet ds1 = new DataSet();
var newdt = dv.ToTable();
return newdt;
}
/// <summary>
/// This is a recursive function to fetchout the data to create a menu from data table
/// </summary>
/// <param name="dt">datatable</param>
/// <param name="parentMenuId">parent menu Id of integer type</param>
/// <param name="parentMenuItem"> Menu Item control</param>
protected void DynamicMenuControlPopulation(DataTable dt, int parentMenuId, MenuIt
em parentMenuItem)
{
string currentPage = Path.GetFileName(Request.Url.AbsolutePath);
foreach (DataRow row in dt.Rows)
{
MenuItem menuItem = new MenuItem
{
Value = row["MenuId"].ToString(),
Text = row["Title"].ToString(),
NavigateUrl = row["URL"].ToString(),
Selected = row["URL"].ToString().EndsWith(currentPage, StringComparison.Curr
entCultureIgnoreCase)
};
if (parentMenuId == 0)
{
Menu1.Items.Add(menuItem);
DataTable dtChild = this.BindMenuData(int.Parse(menuItem.Value));
DynamicMenuControlPopulation(dtChild, int.Parse(menuItem.Value), menuItem);
}
else
{
parentMenuItem.ChildItems.Add(menuItem);
DataTable dtChild = this.BindMenuData(int.Parse(menuItem.Value));
DynamicMenuControlPopulation(dtChild, int.Parse(menuItem.Value), menuIte
m);
}
}
}
}
OUTPUT:
RESULT:
Thus, the above ASP. NET program has been successfully verified and output is
shown.