Download as pdf or txt
Download as pdf or txt
You are on page 1of 85

Department of Computer Science

PROGRAMMING IN
WEB TECHNOLOGY LAB
PRACTICAL WORK REPORT
WEB TECHNOLOGY LAB

Submitted in partial fulfillment for requirements and award of

BACHELOR OF COMPUTER SCIENCE

by

--------------------------------
Under the guidance of

Mrs.M.PAVITHRA.M.E.,B.Ed.,

DEPARTMENT OF CS, IT & BCA


MARY MATHA COLLEGE OF ARTS & SCIENCE
(Affiliated to Madurai Kamaraj University)
PERIYAKULAMEAST - 625601

APRIL - 2024
DEPARTMENT OF CS, IT & BCA
MARY MATHA COLLEGE OF ARTS AND SCIENCE
(Affiliated to Madurai Kamaraj University)
PERIYAKULAMEAST - 625601

Name :

Reg.No. :

Subject : Web Technology Lab

SubjectCode : SCSJC6P

This is to certify that the Bonafide record for practical work done in the Mary Matha
College of Arts and Science for the practical in the academic year 2023- 2024 held
on……………………

Faculty Guide Head of the Department

Submitted for Madurai Kamaraj University 6th semester practical examination,


APRIL 2024 held at Mary Matha College of Arts and Science, Periyakulam.

Internal Examiner External Examiner


INDEX

S.N DATE PROGRAM PAGE


O. NO.
JAVA SCRIPT & JSP PROGRAMS
1 GENERATING FIBONACCI SERIES

2 CHECK WHETHER PALINDROME OR NOT

3 TO VALID AN EMAIL ADDRESS

4 ARITHMETIC OPERATION USING


JAVASCRIPT

5 TO REMOVE ITEMS FROM A DROP DOWN


LIST

6 DISPLAY A RANDOM IMAGE

7 ANIMATE AN OBJECT

8 VALIDATE FORM

PRIME NUMBER CHECKING


9

ADD THE CONTENTS OF ANOTHER JSP FILE


10 USING @INCLUDE DIRECTIVE

FORWARD ONE JSP FILE TO ANOTHER JSP FILE


11 USING FORWARD ACTION

1|Page
S.NO DATE PROGRAM PAGE SIGN
NO

ASP.NET PROGRAMS

CHANGING TEXT BOX FORE AND BACK


12 COLOR

13 REGISTERATION FORM

14 DISPLAYING STUDENT DETAILS FROM XML


FILE

15 DISPLAYING VEHICELS DETAILS USING TREE


VIEW CONTROL

16 MENU SERVER CONTROL

17 DISPLAYING STUDENT DETAILS FROM


DATABASE

18 SITEMAP DATA SOURCE

19 EMPLOYEE DETAILS USING XML DATA


SOURCE

20 WEB PAGE

21 SEND AN MAIL

2|Page
JAVASCRIPT & JSP PROGRAMS

3|Page
Ex.No:1
GENERATING FIBONACCI SERIES
Date:

Aim:
To write a JavaScript Program For Generating Fibonacci Series.

Algorithm:
Step1: Start the program..
Step2: Design the from using the html tags.
Step3: Include the Java Script Coding To Perfrom The Fibonacci Series.
Step4:Display the result.

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;

document.write("The limit entered to generate the fibonacci series is: ",limit, "<br/>");
document.write("The fibonacci series : ");
document.write("<br>","",f1," ");
document.write("<br>","",f2," ");

var i,f3;
for(i=2; i<limit; i++)
{
f3=f1+f2;
document.write("<br>","",f3," ");
f1=f2;
4|Page
f2=f3;
}
</script>
</body>
</html>
Output:

Result:

Thus the program was written, executed and verified successfully.

5|Page
Ex.No:2
CHECK WHETHER PALINDROME
Date: OR NOT

Aim:
To write a JavaScript Program For Check Whether Palindrome Or Not.

Algorithm:
Step1: Start the program.
Step2: Design the from using the html tags.
Step3: Include the Java Script Coding To Check Whether
Palindrome Or Not .
Step4:Display the result.

6|Page
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>

7|Page
Output:

Result:

Thus the program was written, executed and verified successfully.

8|Page
Ex.No:3
TO VALID AN EMAIL ADDRESS
Date:
Aim:
To write a JavaScript Program For Valid An Email Address.

Algorithm:
Step1: Start the program.
Step2: Design the from using the html tags.
Step3: Include the Java Script Coding To Perfrom to Valid an
email address .
Step4:Display the result.

Program:

<html>
<body bgcolor="pink">
<script type="text/javascript">

var input=prompt("Enter ur mail id");


alert("Your E-mail id is "+input);
function validateEmail(input)
{
atpos = input.indexOf("@");
dotpos = input.lastIndexOf(".");
if (atpos< 1 || ( dotpos - atpos< 2 )) {
document.write("Please enter correct email ID")
document.myForm.EMail.focus() ;
return false;
}
return( true );
}
document.write(validateEmail(input ));
</script>
</body>
</html>

9|Page
Output:

Result:

Thus the program was written, executed and verified successfully.

10 | P a g e
Ex.No:4
ARITHMETIC OPERATION USING JAVASCRIPT
Date:

Aim:
To write a JavaScript Program For Arithmetic Operation Using Javascript .

Algorithm:
Step1: Start the program.
Step2: Design the from using the html tags.
Step3: Include the Java Script Coding To PerfromArithmetic
Operation Using Javascript.
Step4:Display the result.

Program:

<html>
<head>
<title>math</title>
<script type= "text/javascript ">
<!--
function oper()
{
varch=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);
11 | P a g e
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>

12 | P a g e
Output:

Result:
Thus the program was written, executed and verified successfully.

13 | P a g e
Ex.No:5
TO REMOVE ITEMS FROM A DROP DOWN LIST
Date:
Aim:
To write a JavaScript Program For Remove Items From A Drop Down List.

Algorithm:
Step1: Start the program.
Step2: Design the from using the html tags.
Step3: Include the Java Script Coding To Remove Items From A
Drop Down List.
Step4:Display the result.

14 | P a g e
Program:
<html>
<head>

<script type= "text/javascript ">


<!--
function removecolor()
{
var x=document.getElementById("colorSelect");
x.remove(x.selectedIndex);
}
</script>

<title>Remove items from a dropdown list</title>

</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>

15 | P a g e
Output:

Result:
Thus the program was written, executed and verified successfully.
16 | P a g e
Ex.No:6
DISPLAY A RANDOM IMAGE
Date:
Aim:
To write a JavaScript Program For Display A Random Image.

Algorithm:
Step1: Start the program.
Step2: Design the from using the html tags.
Step3: Include the Java Script Coding To Display A Random
Image .
Step4:Display the result.

Program:
<html>
<head>
<title> Random Image Generator </title>
</head>
<script>
function getRandomImage() {
//declare an array to store the images
varrandomImage = new Array();

//insert the URL of images in array


randomImage[0] = "img/1.jpg ";
randomImage[1] = "img/2.jpg";
randomImage[2] = "img/3.png";
randomImage[3] = "img/4.jpg";
randomImage[4] = "img/5.jpg";

//generate a number and provide to the image to generate randomly


var number = Math.floor(Math.random()*randomImage.length);

//return the images generated by a random number


return document.getElementById("result").innerHTML =
'<imgsrc="'+randomImage[number]+'" />';
}

17 | P a g e
</script>
<body>
<center><h2 style="color:green"> Random Image Generator </h2></center>
<h4> Click the button to generate and display random images on the webpage </h4>
<!-- call user-defined getRandomImage function after 2 seconds -->
<button onclick = "setInterval(getRandomImage, 2000)"> Generate Image </button>
<br><br>
<span id="result" align="center"></span>

</body>
</html>

18 | P a g e
Output:

Result:
Thus the program was written, executed and verified successfully.
19 | P a g e
Ex.No:7
ANIMATE AN OBJECT
Date:

Aim:
To write a JavaScript Program For Animate An Object.

Algorithm:
Step1: Start the program.
Step2: Design the from using the html tags.
Step3: Include the Java Script Coding To PerfromAnimate An
Object .
Step4:Display the result.
Program:

<html>
<head>
<title>JavaScript Animation</title>
<script type = "text/javascript">
<!--
varimgObj = 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>
20 | P a g e
</html>
Output:

Result:

Thus the program was written, executed and verified successfully.

21 | P a g e
Ex.No:8
VALIDATE FORM
Date:

Aim:
To write a JavaScript Program For Validate Form.

Algorithm:
Step1: Start the program.
Step2: Design the from using the html tags.
Step3: Include the Java Script Coding To PerfromValidate Form.
Step4:Display the result.

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;
}

// Defining a function to validate form


function validateForm() {
// Retrieving the values of form elements
var name = document.contactForm.name.value;
var email = document.contactForm.email.value;
var mobile = document.contactForm.mobile.value;
var country = document.contactForm.country.value;
var gender = document.contactForm.gender.value;
var hobbies = [];
var checkboxes = document.getElementsByName("hobbies[]");
for(vari=0; i<checkboxes.length; i++) {
if(checkboxes[i].checked) {
// Populate hobbies array with selected values
hobbies.push(checkboxes[i].value);
} 22 | P a g e
}

// Defining error variables with a default value


varnameErr = emailErr = mobileErr = countryErr = genderErr = true;

// 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 email address


if(email == "") {
printError("emailErr", "Please enter your email address");
} else {
// Regular expression for basic email validation
var regex = /^\S+@\S+\.\S+$/;
if(regex.test(email) === false) {
printError("emailErr", "Please enter a valid email address");
} else{
printError("emailErr", "");
emailErr = false;
}
}

// Validate mobile number


if(mobile == "") {
printError("mobileErr", "Please enter your mobile number");
} else {
var regex = /^[1-9]\d{9}$/;
if(regex.test(mobile) === false) {
printError("mobileErr", "Please enter a valid 10 digit mobile number");
} else{
printError("mobileErr", "");
mobileErr = false;
}
}
23 | P a g e
// Validate country
if(country == "Select") {
printError("countryErr", "Please select your country");
} else {
printError("countryErr", "");
countryErr = 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
vardataPreview = "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"> 24 | P a g e
<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> 25 | P a g e
Output:

Result:
Thus the program was written, executed and verified successfully.

26 | P a g e
Ex.No:9
PRIME NUMBER CHECKING
Date:

Aim:

To write a JSP Program to check whether the given number is prime or not.
Algorithm:
Step1: Start the program.
Step2: Design the from using the html tags.
Step3: Include the Java Script Coding To PerfromCheck Whether
The Given Number Is Prime Or Not .
Step4:Display the result.

Program:

//prime.html

<%--
Document : index
Created on : 12 Oct, 2012, 7:35:11 PM
Author : nested code team
--%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">

<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
27 | P a g e
<%--
Document : primejsp
Created on : 31 Oct, 2012, 11:59:34 AM
Author :NESTED CODE
--%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">

<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>
<%
intn,i,flag=0;

String ns= request.getParameter("n");


n=Integer.parseInt(ns);
if(n>1)
{

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
{
28 | P a g e
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.

29 | P a g e
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

30 | P a g e
</p>

Output

Result:
Thus the program was written, executed and verified successfully.

31 | P a g e
Ex.No:11
FORWARD ONE JSP FILE TO ANOTHER
Date: JSP FILE USING FORWARD ACTION

Aim:

Write a JSP To forward one JSP file to another JSP file Using forward
Action.
.
Algorithm:
Step1: Start the program.
Step2: Design the from using the html tags.
Step3: Include the Java Script Coding To Forward One
JSP File To Another JSP File Using Forward Action .
Step4:Display the result.

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>

32 | P a g e
</head>
<body>
Hello this is a display.jsp Page
</body>
</html>

Output :

Result:
Thus the program was written, executed and verified successfully.

33 | P a g e
ASP .NET PROGRAMS

34 | P a g e
Ex.No:12
CHANGING TEXT BOX FORE AND BACK
Date: COLOR

AIM:
To write an ASP.NET program to change the background and fore color of the textbox.

ALGORITHM:
1. Open Microsoft Visual Studio 2010
2. Click new project -> Asp.net web application with C#
3. Solution explorer right click -> add -> new item -> webform with C#
4. Place required controls for the application
5. write the necessary coding in C#
6. Run the application.

FORE CLOR.ASPX :
<%@PageLanguage="C#"AutoEventWireup="true"CodeBehind="WebForm1.aspx.cs"Inherits=
"change_backcolor_and_forecolor.WebForm1"%>

<!DOCTYPEhtmlPUBLIC"-//W3C//DTD XHTML 1.0


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

<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"

35 | P a g e
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 TheBackColor "
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;
usingSystem.Collections.Generic;
usingSystem.Linq;
usingSystem.Web;
usingSystem.Web.UI;
usingSystem.Web.UI.WebControls;

namespacechange_backcolor_and_forecolor
{
publicpartialclassWebForm1 :System.Web.UI.Page
{
protectedvoidPage_Load(object sender, EventArgs e)
{

protectedvoid Button1_Click(object sender, EventArgs e)


{
TextBox1.ForeColor = System.Drawing.Color.Black ;
}

protectedvoid Button2_Click(object sender, EventArgs e)

36 | P a g e
{
TextBox1.BackColor = System.Drawing.Color.Cyan;
}
}
}

OUTPUT :

RESULT:
Thus, the above ASP. NET program has been successfully verified and output is shown.

37 | P a g e
Ex.No:13
REGISTERATION FORM
Date:
AIM:
To write an ASP.NET program to create a registration form.

ALGORITHM:
1. Open Microsoft Visual Studio 2010
2. Click new project -> Asp.net web application with C#
3. Solution explorer right click -> add -> new item -> webform with C#
4. Place required controls for the application
5. write the necessary coding in C#
6. Run the application.

REGISTERATION.ASPX
<%@PageLanguage="C#"AutoEventWireup="true"CodeBehind="Registration
form.aspx.cs"Inherits="WebApplication14.WebForm1"%>

<!DOCTYPEhtmlPUBLIC"-//W3C//DTD XHTML 1.0


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

<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">

38 | P a g e
<div>
<tableclass="auto-style1">
<tr>
<td>
&nbsp;<asp:LabelID="Label1"runat="server"Text="User Name"></asp:Label>
</td>
<td>
&nbsp;<asp:TextBoxID="username"runat="server"required="true"></asp:TextBox></td>
</tr>
<tr>
<td>
&nbsp;<asp:LabelID="Label6"runat="server"Text="Email ID"></asp:Label>
</td>
<td>
&nbsp;<asp:TextBoxID="EmailID"runat="server"TextMode="Email"></asp:TextBox></td>
</tr>
<tr>
<td>
&nbsp;<asp:LabelID="Label2"runat="server"Text="Password"></asp:Label></td>
<td>
&nbsp;<asp:TextBoxID="TextBox2"runat="server"TextMode="Password"></asp:TextBox></t
d>
</tr>
<tr>
<td>
&nbsp;<asp:LabelID="Label3"runat="server"Text="Confirm Password"></asp:Label></td>
<td>
&nbsp;<asp:TextBoxID="TextBox3"runat="server"TextMode="Password"></asp:TextBox></t
d>
</tr>
<tr>
<td>
&nbsp;<asp:LabelID="Label4"runat="server"Text="Gender"></asp:Label></td>
<td>
&nbsp;<asp:RadioButtonID="RadioButton1"runat="server"GroupName="gender"Text="Male"/
>
&nbsp;
<asp:RadioButtonID="RadioButton2"runat="server"GroupName="gender"Text="Femal
e"/></td>
</tr>
<tr>
<td>
<asp:LabelID="Label5"runat="server"Text="Select Course"></asp:Label>s</td>
<td>
&nbsp;<asp:CheckBoxID="CheckBox1"runat="server"Text="DOTNET"/>
&nbsp;<asp:CheckBoxID="CheckBox2"runat="server"Text="PYTHON"/>

39 | P a g e
&nbsp;<asp:CheckBoxID="CheckBox3"runat="server"Text="PHP"/>
&nbsp;</td>
</tr>
<tr>
<td>
&nbsp;</td>
<td>
&nbsp;<br/>
&nbsp;<asp:ButtonID="Button1"runat="server"Text="Register"CssClass="btnbtn-
primary"OnClick="Button1_Click"/>
</td>
</tr>
</table>
&nbsp;<asp:LabelID="message"runat="server"Font-
Size="Medium"ForeColor="Red"></asp:Label>
</div>
</form>
&nbsp;<tableclass="auto-style1">
<tr>
<tdclass="auto-
style2"><asp:LabelID="ShowUserNameLabel"runat="server"></asp:Label></td>
<td>
&nbsp;<asp:LabelID="ShowUserName"runat="server"></asp:Label></td>
</tr>
<tr>
<tdclass="auto-
style2"><asp:LabelID="ShowEmailIDLabel"runat="server"></asp:Label></td>
<td>
&nbsp;<asp:LabelID="ShowEmail"runat="server"></asp:Label></td>
</tr>
<tr>
<tdclass="auto-
style3"><asp:LabelID="ShowGenderLabel"runat="server"></asp:Label></td>
<tdclass="auto-style4">
&nbsp;<asp:LabelID="ShowGender"runat="server"></asp:Label></td>
</tr>
<tr>
<tdclass="auto-
style2"><asp:LabelID="ShowCourseLabel"runat="server"></asp:Label></td>
<td>
&nbsp;<asp:LabelID="ShowCourses"runat="server"></asp:Label></td>
</tr>
</table>

</div>
</form>

40 | P a g e
</body>
</html>

REGISTERATION.ASPX.CS
using System;
usingSystem.Collections.Generic;
usingSystem.Linq;
usingSystem.Web;
usingSystem.Web.UI;
usingSystem.Web.UI.WebControls;

namespace WebApplication14
{
publicpartialclassWebForm1 :System.Web.UI.Page
{
protectedvoidPage_Load(object sender, EventArgs e)
{

protectedvoid Button1_Click(object sender, EventArgs e)


{
message.Text = "Hello " + username.Text + " ! ";
message.Text = message.Text + " <br/> You have successfuly Registered with the following
details.";
ShowUserName.Text = username.Text;
ShowEmail.Text = EmailID.Text;
if (RadioButton1.Checked)
{
ShowGender.Text = RadioButton1.Text;
}
elseShowGender.Text = RadioButton2.Text;
var courses = "";
if (CheckBox1.Checked)
{
courses = CheckBox1.Text + " ";
}
if (CheckBox2.Checked)
{
courses += CheckBox2.Text + " ";
}
if (CheckBox3.Checked)
{
courses += CheckBox3.Text;
}
ShowCourses.Text = courses;
ShowUserNameLabel.Text = "User Name";

41 | P a g e
ShowEmailIDLabel.Text = "Email ID";
ShowGenderLabel.Text = "Gender";
ShowCourseLabel.Text = "Courses";
username.Text = "";
EmailID.Text = "";
RadioButton1.Checked = false;
RadioButton2.Checked = false;
CheckBox1.Checked = false;
CheckBox2.Checked = false;
CheckBox3.Checked = false;

}
}
}

OUTPUT :

42 | P a g e
RESULT:
Thus the above ASP. NET program has been successfully verified and output is shown.

43 | P a g e
Ex.No:14
DISPLAYING STUDENT DETAILS FROM
Date: XML FILE

AIM:
To write an ASP.NET program to display the student details from xml file.

ALGORITHM:
1. Open Microsoft Visual Studio 2010
2. Click new project -> Asp.net web application with C#
3. Solution explorer right click -> add -> new item -> webform with C#
4. Place required controls for the application
5.Iinclude the xml file
Solution explorer right click -> add -> new item -> xml file.
6.write the necessary coding in C#
7. Run the application.

STUDENT DETAILS USING GRID VIEW CONTROL


Webfrom1.aspx.cs

using System;
usingSystem.Collections.Generic;
usingSystem.Linq;
usingSystem.Web;
usingSystem.Web.UI;
usingSystem.Web.UI.WebControls;
usingSystem.Data;

namespace WebApplication11
{
publicpartialclassWebForm1 :System.Web.UI.Page
{
protectedvoidPage_Load(object sender, EventArgs e)
{
if(!this.IsPostBack)
{
this.BindGrid();
}

privatevoidBindGrid()
{
using(DataSet ds = newDataSet())
{

44 | P a g e
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>

45 | P a g e
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>

46 | P a g e
OUTPUT:

RESULT:
Thus the above ASP. NET program has been successfully verified and output is shown.

47 | P a g e
Ex.No:15
DISPLAYING VEHICELS DETAILS USING
Date: TREE
VIEW CONTROL

AIM:
To write an ASP.NET program to display the vehicle details using Tree view control.

ALGORITHM:
1. Open Microsoft Visual Studio 2010
2. Click new project -> Asp.net web application with C#
3. Solution explorer right click -> add -> new item -> webform with C#
4. Place required controls for the application
5.Iinclude the xml file
Solution explorer right click -> add -> new item -> xml file.
6.write the necessary coding in C#
7. Run the application.

VEHICLE.ASPX
<%@PageLanguage="C#"AutoEventWireup="true"CodeBehind="WebForm1.aspx.cs"Inherits=
"WebApplication6.WebForm1"%>

<!DOCTYPEhtmlPUBLIC"-//W3C//DTD XHTML 1.0


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

<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="/ve
hicles"></asp:XmlDataSource>

48 | P a g e
</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>

49 | P a g e
OUTPUT:

RESULT:
Thus, the above ASP. NET program has been successfully verified and output is shown.

50 | P a g e
Ex.No:16
MENU SERVER CONTROL
Date:
AIM:
To write an ASP.NET program using menu server control.

ALGORITHM:
1. Open Microsoft Visual Studio 2010
2. Click new project -> Asp.net web application with C#
3. Solution explorer right click -> add -> new item -> webform with C#
4. Place required controls for the application
5. write the necessary coding in C#
6. Run the application.

DYNAMIC MENU.ASPX
color: #444;
} <%@ Page Language="C#" AutoEventWireup="true" CodeFile="DynamicMenu.aspx.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;

51 | P a g e
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>

52 | P a g e
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;

public partial class DynamicMenu : System.Web.UI.Page


{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{

53 | P a g e
DataTable dt = this.BindMenuData(0);
DynamicMenuControlPopulation(dt, 0, null);
}
}
/// <summary>
/// This function retur a datatable according to parent menu id passed by user
/// </summary>
/// <param name="parentmenuId">parent menu ID</param>
/// <returns>data table</returns>
protected DataTable BindMenuData(int parentmenuId)
{
//declaration of variable used
DataSet ds = new DataSet();
DataTable dt;
DataRow dr;
DataColumn menu;
DataColumn pMenu;
DataColumn title;
DataColumn description;
DataColumn URL;
//create an object of datatable
dt=new DataTable();

//creating column of datatable with datatype


menu= new DataColumn("MenuId",Type.GetType("System.Int32"));
pMenu=new DataColumn("ParentId", Type.GetType("System.Int32"));
title=new DataColumn("Title",Type.GetType("System.String"));
description=new DataColumn("Description",Type.GetType("System.String"));
URL=new DataColumn("URL",Type.GetType("System.String"));

//bind data table columns in datatable


dt.Columns.Add(menu);//1st column
dt.Columns.Add(pMenu);//2nd column
dt.Columns.Add(title);//3rd column
dt.Columns.Add(description);//4th column
dt.Columns.Add(URL);//5th column

//creating data row and assiging the value to columns of datatable


//1st row of data table
dr = dt.NewRow();
dr["MenuId"] = 1;
dr["ParentId"] = 0;
dr["Title"] = "Home";
dr["Description"] = "";
dr["URL"] = "~/Home.aspx";
dt.Rows.Add(dr);

54 | P a g e
//2nd row of data table
dr = dt.NewRow();
dr["MenuId"] = 2;
dr["ParentId"] = 0;
dr["Title"] = "Customer Service";
dr["Description"] = "Customer Service";
dr["URL"] = "~/Customer.aspx";
dt.Rows.Add(dr);

//3rd row of data table


dr = dt.NewRow();
dr["MenuId"] = 3;
dr["ParentId"] = 0;
dr["Title"] = "About";
dr["Description"] = "About us page";
dr["URL"] = "~/AboutUs.aspx";
dt.Rows.Add(dr);

//4th row of data table


dr = dt.NewRow();
dr["MenuId"] = 4;
dr["ParentId"] = 0;
dr["Title"] = "Contact Us";
dr["Description"] = "Contact Us page";
dr["URL"] = "~/Contact.aspx";
dt.Rows.Add(dr);

//5th row of data table


dr = dt.NewRow();
dr["MenuId"] = 5;
dr["ParentId"] = 0;
dr["Title"] = "Testmonial";
dr["Description"] = "Testimonial page";
dr["URL"] = "~/Testimonial.aspx";
dt.Rows.Add(dr);

//6th row of data table


dr = dt.NewRow();
dr["MenuId"] = 6;
dr["ParentId"] = 2;
dr["Title"] = "Consulting";
dr["Description"] = "Consulting page";
dr["URL"] = "~/Consult.aspx";
dt.Rows.Add(dr);

55 | P a g e
//7th row of data table
dr = dt.NewRow();
dr["MenuId"] = 7;
dr["ParentId"] = 2;
dr["Title"] = "Outsourcing";
dr["Description"] = "Outsourcing page";
dr["URL"] = "~/Outsource.aspx";
dt.Rows.Add(dr);

//8th row of data table


dr = dt.NewRow();
dr["MenuId"] = 8;
dr["ParentId"] = 7;
dr["Title"] = "Domestic";
dr["Description"] = "Domestic outsourcing page";
dr["URL"] = "~/Domestic.aspx";
dt.Rows.Add(dr);

//9th row of data table


dr = dt.NewRow();
dr["MenuId"] = 9;
dr["ParentId"] = 7;
dr["Title"] = "International";
dr["Description"] = "International outsourcing page";
dr["URL"] = "~/International.aspx";
dt.Rows.Add(dr);

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, MenuItem
parentMenuItem)
{
string currentPage = Path.GetFileName(Request.Url.AbsolutePath);
foreach (DataRow row in dt.Rows)

56 | P a g e
{
MenuItem menuItem = new MenuItem
{
Value = row["MenuId"].ToString(),
Text = row["Title"].ToString(),
NavigateUrl = row["URL"].ToString(),
Selected = row["URL"].ToString().EndsWith(currentPage, StringComparison.Current
CultureIgnoreCase)
};
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), menuItem);

}
}
}
}

57 | P a g e
OUTPUT:

58 | P a g e
RESULT:
Thus, the above ASP. NET program has been successfully verified and output is shown.

59 | P a g e
Ex.No:17
DISPLAYING STUDENT DETAILS FROM
Date: DATABASE

AIM:
To write an ASP.NET program to display the student details using SqlDataSource and
Grid view.

ALGORITHM:
1. Open Microsoft Visual Studio 2010
2. Click new project -> Asp.net web application with C#
3. Solution explorer right click -> add -> new item -> webform with C#
4. Place required controls for the application
5.Iinclude the xml file
Solution explorer right click -> add -> new item -> xml file.
6.write the necessary coding in C#
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.ConnectionStrings[
"RegiConnectionString"].ConnectionString);
conn.Open();
string checkuser = "select count(*) from RegisterDataBase where StudentName='"+Te
xtBox1.Text+"'";

60 | P a g e
SqlCommand cmd = new SqlCommand(checkuser, conn);
int temp = Convert.ToInt32(cmd.ExecuteScalar().ToString());

if (temp == 1)
{
Response.Write("Student Already Exist");
}

conn.Close();
}

protected void Button1_Click(object sender, EventArgs e)


{
try
{

SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings[


"RegiConnectionString"].ConnectionString);
conn.Open();
string insertQuery = "insert into RegisterDataBase(StudentName,Passwords,EmailId,
Department,College)values (@studentname,@passwords,@emailid,@department,@college)";
SqlCommand cmd = new SqlCommand(insertQuery, conn);
cmd.Parameters.AddWithValue("@studentname", TextBox1.Text);
cmd.Parameters.AddWithValue("@passwords", TextBox2.Text);
cmd.Parameters.AddWithValue("@emailid", TextBox3.Text);
cmd.Parameters.AddWithValue("@department", TextBox4.Text);
cmd.Parameters.AddWithValue("@college", TextBox5.Text);
cmd.ExecuteNonQuery();

Response.Write("Student registeration Successfully!!!thank you");

conn.Close();

}
catch (Exception ex)
{
Response.Write("error" + ex.ToString());
}
}
}
}

61 | P a g e
STUDENT.ASPX

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="loginpage.aspx.cs" Inherit


s="DatabaseConnectivity.loginpage" %>

<!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>

62 | P a g e
<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" BackC
olor="Yellow" />
</div>
<div id="sim"></div>
<aspSqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ Connect
ionStringsRegiConnectionString %>" SelectCommand="SELECT * FROM [RegisterDataBase]"
></aspSqlDataSource>

<div id="grid">
<aspGridView ID="GridView1" runat="server" AllowPaging="True" AllowSorting="Tr
ue" AutoGenerateColumns="False" CellPadding="4" DataSourceID="SqlDataSource1" ForeCol
or="#333333" GridLines="None">
<AlternatingRowStyle BackColor="White" ForeColor="#284775" />
<Columns>
<aspBoundField DataField="Id" HeaderText="Id" SortExpression="Id" />
<aspBoundField DataField="StudentName" HeaderText="StudentName" SortExpre
ssion="StudentName" />
<aspBoundField DataField="Passwords" HeaderText="Passwords" SortExpression=
"Passwords" />
<aspBoundField DataField="EmailId" HeaderText="EmailId" SortExpression="Em
ailId" />
<aspBoundField DataField="Department" HeaderText="Department" SortExpressio
n="Department" />
<aspBoundField DataField="College" HeaderText="College" SortExpression="Coll
ege" />
</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" />

63 | P a g e
<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.

64 | P a g e
Ex.No:18
SITEMAP DATA SOURCE
Date:
AIM:
To write an ASP.NET program using sitemap data control.

ALGORITHM:
1. Open Microsoft Visual Studio 2010
2. Click new project -> Asp.net web application with C#
3. Solution explorer right click -> add -> new item -> webform with C#
4. Solution explorer right click -> add -> new item ->web.sitemap
4. Place required controls for the application
5. write the necessary coding in C#
6. Run the application.

TUTORIAL.sitemap

<?xmlversion="1.0"encoding="utf-8" ?>
<siteMapxmlns="http://schemas.microsoft.com/AspNet/SiteMap-File-1.0">
<siteMapNodeurl=""title="My Favourate"description="Favourate">

<siteMapNodeurl=""title="Websites"description="my fav websites">

<siteMapNodeurl="www.google.com"title="c-sharpcorner"description="microsoft
technology world" />

<siteMapNodeurl="www.vbdotnetheaven.com"title="vbdotnetheaven.com"description="
vb.net world" />

<siteMapNodeurl="www.longhorncorner.com"title="longhorncorner.com"description="
XAML,WPF world" />

</siteMapNode>
<siteMapNodeurl=""title="Movies"description="my fav movies">

<siteMapNodeurl=""title="Gladiator"description="Gladiator"></siteMapNode>

<siteMapNodeurl=""title="Once upon a time in maxico"description="once upon a time in


maxico"></siteMapNode>

<siteMapNodeurl=""title="Ghost Rider"description="ghost rider"></siteMapNode>

65 | P a g e
</siteMapNode>

<siteMapNodeurl=""title="Wrestler"description="my fav wrestler">

<siteMapNodeurl=""title="John Cena"description="john cena the marine


guy"></siteMapNode>

<siteMapNodeurl=""title="Shawn Micheal"description="shawnmicheal the great wrestler


"></siteMapNode>

</siteMapNode>

</siteMapNode>

</siteMap>

<?xmlversion="1.0"encoding="utf-8" ?>
<siteMapxmlns="http://schemas.microsoft.com/AspNet/SiteMap-File-1.0">
<siteMapNodeurl=""title="My Favourate"description="Favourate">

<siteMapNodeurl=""title="Websites"description="my fav websites">

<siteMapNodeurl="www.google.com"title="c-sharpcorner"description="microsoft
technology world" />

<siteMapNodeurl="www.vbdotnetheaven.com"title="vbdotnetheaven.com"description="
vb.net world" />

<siteMapNodeurl="www.longhorncorner.com"title="longhorncorner.com"description="
XAML,WPF world" />

</siteMapNode>

<siteMapNodeurl=""title="Movies"description="my fav movies">

<siteMapNodeurl=""title="Gladiator"description="Gladiator"></siteMapNode>

<siteMapNodeurl=""title="Once upon a time in maxico"description="once upon a time in


maxico"></siteMapNode>

<siteMapNodeurl=""title="Ghost Rider"description="ghost rider"></siteMapNode>

</siteMapNode>

<siteMapNodeurl=""title="Wrestler"description="my fav wrestler">

66 | P a g e
<siteMapNodeurl=""title="John Cena"description="john cena the marine
guy"></siteMapNode>

<siteMapNodeurl=""title="Shawn Micheal"description="shawnmicheal the great wrestler


"></siteMapNode>

</siteMapNode>

</siteMapNode>

</siteMap>

Web.aspx
<%@PageLanguage="C#"AutoEventWireup="true"CodeBehind="WebForm1.aspx.cs"In
herits="sitemap.WebForm1"%>

<!DOCTYPEhtmlPUBLIC"-//W3C//DTD XHTML 1.0


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

<htmlxmlns="http://www.w3.org/1999/xhtml">
<headrunat="server">
<title></title>
<styletype="text/css">
.style1
{
text-align: center;
}
</style>
</head>
<body>
<formid="form1"runat="server">
<divclass="style1"style="height: 578px">

<strongstyle="text-align: center">
<br/>
SITEMAPDATASOURCE
EXAMPLE<asp:SiteMapDataSourceID="SiteMapDataSource1"
runat="server"/>
<asp:TreeViewID="TreeView1"runat="server"DataSourceID="SiteMapDataSource1"
ImageSet="WindowsHelp"
style="z-index: 1; left: 462px; top: 210px; position: absolute; height: 253px; width:
255px">
<HoverNodeStyleFont-Underline="True"ForeColor="#6666AA"/>
<NodeStyleFont-Names="Tahoma"Font-Size="8pt"ForeColor="Black"

67 | P a g e
HorizontalPadding="5px"NodeSpacing="0px"VerticalPadding="1px"/>
<ParentNodeStyleFont-Bold="False"/>
<SelectedNodeStyleBackColor="#B5B5B5"Font-Underline="False"
HorizontalPadding="0px"VerticalPadding="0px"/>
</asp:TreeView>
</strong>

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

68 | P a g e
Output:

RESULT:
Thus, the above ASP. NET program has been successfully verified and output is shown.

69 | P a g e
Ex.No:19
EMPLOYEE DETAILS USING XML DATA
Date: SOURCE

AIM:
To write an ASP.NET program to display the employee details from using Grid view.

ALGORITHM:
1. Open Microsoft Visual Studio 2010
2. Click new project -> Asp.net web application with C#
3. Solution explorer right click -> add -> new item -> webform with C#
4. Place required controls for the application
5.Iinclude the xml file
Solution explorer right click -> add -> new item -> xml file.
6.write the necessary coding in C#
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>

70 | P a g e
<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"Inherits=
"Employee_details.WebForm1"%>

<!DOCTYPEhtmlPUBLIC"-//W3C//DTD XHTML 1.0


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

<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="CountryChan
ged"
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"/>

71 | P a g e
</asp:DropDownList>
&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;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; City:
<hr/>
<asp:XmlDataSourceID="XmlDataSource1"runat="server"DataFile="~/employee.xml">
</asp:XmlDataSource>
<asp:GridViewID="GridView1"runat="server"XPath="/Employees/Employee"DataSourceID="
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;
usingSystem.Collections.Generic;

72 | P a g e
usingSystem.Linq;
usingSystem.Web;
usingSystem.Web.UI;
usingSystem.Web.UI.WebControls;

namespaceEmployee_details
{
publicpartialclassWebForm1 :System.Web.UI.Page
{
protectedvoidPage_Load(object sender, EventArgs e)
{

protectedvoidCountryChanged(object sender, EventArgs e)


{
ddlCities.SelectedIndex = -1;
string country = ddlCountries.SelectedItem.Value;
if (country != string.Empty)
{
XmlDataSource1.XPath = "/Employees/Employee[ Country='" + country + "']";
}
else
{
XmlDataSource1.XPath = "/Employees/Employee";
}

protectedvoidCityChanged(object sender, EventArgs e)


{
ddlCountries.SelectedIndex = -1;
string city = ddlCities.SelectedItem.Value;
if (city != string.Empty)
{
XmlDataSource1.XPath = "/Employees/Employee[ @City='" + city + "']";
}
else
{
XmlDataSource1.XPath = "/Employees/Employee";
}

}
}
}

73 | P a g e
OUTPUT:

74 | P a g e
RESULT:
Thus, the above ASP. NET program has been successfully verified and output is shown.

75 | P a g e
Ex.No:20
SEND AN MAIL
Date:

AIM:
To write an ASP.NET program send a mail.

ALGORITHM:
1. Open Microsoft Visual Studio 2010
2. Click new project -> Asp.net web application with C#
3. Solution explorer right click -> add -> new item -> webform with C#
4. Solution explorer right click -> add -> new item ->web.sitemap
4. Place required controls for the application
5. write the necessary coding in C#
6. Run the application.

Code in SignUp.html
<!DOCTYPE html>
<html>
<head>
<title></title>
<meta charset="utf-8" />
<style>
table, th, td {
border: 1px solid black;
}
</style>
</head>
<body>
<br />
<table width="50%">
<tr>
<td align="center" style="background-color:yellow">
<span style="font-size:25px;"> Welcome To C# Corner </span>
<br />
<br />
</td>

</tr>

<tr align="center">
<td>
<br />

76 | P a g e
<br />
Dear [newusername]
<br />
<br />
Thank you for registering with us!
<br />
<a href="http://www.c-sharpcorner.com">
Click here to Login
</a>

Regards,
<br />
<br />
</td>
</tr>
<tr>
<td align="center" style="background-color:yellow">
<br />
<br />
<span style="font-size:15px;text-
decoration:underline"> Share your knowledge </span>
<br />
<span style="font-
size:20px;"> <i>If you have knowledge, let others light their candles in it -
Margaret Fuller </span>
<br />
<br />
</td>
</tr>
</tr>
</table>
</body> </html>
Code in Web.Config file
<?xml version="1.0"?>

<!--
For more information on how to configure your ASP.NET application, please visit
http://go.microsoft.com/fwlink/?LinkId=169433
-->

<configuration>
<appSettings>
<add key="smtp" value="smtp.gmail.com"/>
<add key="portnumber" value="587"/>
<add key="username" value="xyz@gmail.com"/>
<add key="password" value="abc@123"/>

77 | P a g e
<add key="IsSSL" value="true"/>
</appSettings>
<system.web>
<compilation debug="true" targetFramework="4.5.2" />
<httpRuntime targetFramework="4.5.2" />
</system.web>

</configuration>
Code in Signup.aspx file
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Signup.aspx.cs" Inherit
s="Signup" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<style type="text/css">
.auto-style1 {
height: 30px;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div>
<h3>New User (Signup)</h3>
<table>
<tr>
<td>User Name<br />
(Email ID)
</td>
<td>
<asp:TextBox ID="txtUserName" runat="server" Width="200px"></asp:
TextBox>
</td>
</tr>
<tr>
<td>
<br />
Password
</td>

<td>
<br />
<asp:TextBox ID="txtPassword" runat="server" TextMode="Password"

78 | P a g e
Width="200px"> </asp:TextBox>
</td>
</tr>
<tr>
<td colspan="2" class="auto-style1">
<asp:Button ID="btnSubmit" runat="server" Text="Register (Signup)" On
Click="btnSubmit_Click" />
</td>
</tr>
</table>
</div>
</form>
</body>
</html>

Code in Signup.aspx.cs file


using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

//System.Net
using System.Net;

//System.Net.Mail namespace required to send mail.


using System.Net.Mail;

using System.Configuration;
using System.IO;

public partial class Signup : System.Web.UI.Page


{
protected void Page_Load(object sender, EventArgs e)
{

protected void btnSubmit_Click(object sender, EventArgs e)


{
//Fetching Settings from WEB.CONFIG file.
string emailSender = ConfigurationManager.AppSettings["emailsender"].ToString()
;
string emailSenderPassword = ConfigurationManager.AppSettings["password"].ToS
tring();

79 | P a g e
string emailSenderHost = ConfigurationManager.AppSettings["smtpserver"].ToStri
ng();
int emailSenderPort = Convert.ToInt16(ConfigurationManager.AppSettings["portnu
mber"]);
Boolean emailIsSSL = Convert.ToBoolean(ConfigurationManager.AppSettings["IsS
SL"]);

//Fetching Email Body Text from EmailTemplate File.


string FilePath = "D:\\MBK\\SendEmailByEmailTemplate\\EmailTemplates\\SignU
p.html";
StreamReader str = new StreamReader(FilePath);
string MailText = str.ReadToEnd();
str.Close();

//Repalce [newusername] = signup user name


MailText = MailText.Replace("[newusername]", txtUserName.Text.Trim());

string subject = "Welcome to CSharpCorner.Com";

//Base class for sending email


MailMessage _mailmsg = new MailMessage();

//Make TRUE because our body text is html


_mailmsg.IsBodyHtml = true;

//Set From Email ID


_mailmsg.From = new MailAddress(emailSender);

//Set To Email ID
_mailmsg.To.Add(txtUserName.Text.ToString());

//Set Subject
_mailmsg.Subject = subject;

//Set Body Text of Email


_mailmsg.Body = MailText;

//Now set your SMTP


SmtpClient _smtp = new SmtpClient();

//Set HOST server SMTP detail


_smtp.Host = emailSenderHost;

80 | P a g e
//Set PORT number of SMTP
_smtp.Port = emailSenderPort;

//Set SSL --> True / False


_smtp.EnableSsl = emailIsSSL;

//Set Sender UserEmailID, Password


NetworkCredential _network = new NetworkCredential(emailSender, emailSenderPassword
);
_smtp.Credentials = _network;

//Send Method will send your MailMessage create above.


_smtp.Send(_mailmsg);

}
}

OUTPUT:

81 | P a g e
RESULT:
Thus, the above ASP. NET program has been successfully verified and output is shown.

82 | P a g e

You might also like