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

PRACTICAL WORK REPORT

WEB TECHNOLOGY LAB

Submitted in partial fulfilment of requirements and award of

BACHELOR OF COMPUTER SCIENCE


By

______________________

Under the guidance of

Mr. G. ARUNKUMAR., MCA.,

DEPARTMENT OF CS, BCA AND IT

MARY MATHA COLLEGE OF ARTS AND SCIENCE

(Affiliated to Madurai Kamaraj University)

PERIYAKULAM – 625604

APRIL - 2023
DEPARTMENT OF CS, BCA AND IT

MARY MATHA COLLEGE OF ARTS & SCIENCE

(Affiliated to Madurai Kamaraj University)

PERIYAKULAM – 625604

Name : ....................................................

Reg. No : ……………………….

Subject : Web Technology Lab

Subject Code : SCSJC6P

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.

Faculty In-Charge Head Of the Department

Submitted for the University Practical Examination held on ________________ at


Mary Matha college of Arts and Science, Periyakulam.

Internal Examiner External Examiner


INDEX

JAVASCRIPT & JSP

PAGE.
SIGN
S. No DATE TITLE No

1 GENERATING FIBONACCI SERIES

CHECK WHETHER PALINDROME OR


2
NOT

3 TO VALID AN EMAIL ADDRESS

ARITHMETIC OPERATION
4
USINGJAVASCRIPT

TO REMOVE ITEMS FROM A


5
DROPDOWN LIST

6 DISPLAY A RANDOM IMAGE

7 ANIMATE AN OBJECT

8 VALIDATE FORM

9 PRIME NUMBER CHECKING

ADD THE CONTENTS OF ANOTHER JSP


10
FILE USING @INCLUDE DIRECTIVE

FORWARD ONE JSP FILE TO ANOTHER


11
JSP FILE USING FORWARD ACTION
ASP.NET

PAGE.
SIGN
S. No DATE TITLE No

CHANGING TEXT BOX FORE AND


1
BACK COLOR

2 REGISTERATION FORM

3 ADROTATOR CONTROL

4 CALENDER CONTROL

5 MULTIPLICATION TABLE

6 VALIDATION CONTROL

DISPLAYING STUDENT DETAILS FROM


7
XML FILE

DISPLAYING VEHICELS DETAILS


8
USING TREE VIEW CONTROL

DISPLAYING BOOK DETAILS FROM


9
XML FILE

DISPLAYING COUNTRY DETAILS


10
USING TREE VIEW CONTROL

DISPLAYING STUDENT DETAILS FROM


11
DATABASE

EMPLOYEE DETAILS USING XML


12
DATA SOURCE

13 MENU SERVER CONTROL


Ex.No:
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;
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:

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.

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:

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>
OUTPUT:

RESULT:

Thus the program was written, executed and verified successfully.


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

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.

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>

Output:

RESULT:

Thus the program was written, executed and verified successfully.


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
var randomImage = 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 = '<img
src="'+randomImage[number]+'" />';
}</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>
OUTPUT:

RESULT:
Thus the program was written, executed and verified successfully.
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 Perfrom Animate An
Object.
Step4:Display the result.

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:

Thus the program was written, executed and verified successfully.


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 Perfrom Validate 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(var i=0; i < checkboxes.length; i++) {
if(checkboxes[i].checked) {
// Populate hobbies array with selected values
hobbies.push(checkboxes[i].value);
}
}

// Defining error variables with a default value


var nameErr = 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;
}
}
// 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
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:

Step1: Start the program.


Step2: Design the from using the html tags.
Step3:Include the Java Script Coding To Perfrom Check
WhetherThe 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
<%--
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>
<%
int n,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
{
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:

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

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.

FORE CLOR.ASPX :
<%@PageLanguage="C#"AutoEventWireup="true"CodeBehind="WebForm1.aspx.cs"Inheri
ts="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"
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)
{

protectedvoid Button1_Click(object sender, EventArgs e)


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

protectedvoid Button2_Click(object sender, EventArgs e)


{
TextBox1.BackColor = System.Drawing.Color.Cyan;
}
}
}

OUTPUT :

RESULT:
Thus, the above ASP. NET program has been successfully verified and output is
shown.
Ex.No:2
REGISTERATION FORM
Date:

AIM:

To write an ASP.NET program to create a registration form.

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

<!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">
<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>
</td>
</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>
</td>
</tr>
<tr>
<td>
&nbsp;<asp:LabelID="Label4"runat="server"Text="Gender"></asp:Label></td>
<td>
&nbsp;<asp:RadioButtonID="RadioButton1"runat="server"GroupName="gender"Text="Ma
le"/>
&nbsp;
<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>
&nbsp;<asp:CheckBoxID="CheckBox1"runat="server"Text="DOTNET"/>
&nbsp;<asp:CheckBoxID="CheckBox2"runat="server"Text="PYTHON"/>
&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="btn btn-
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>
</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)
{

protectedvoid Button1_Click(object sender, EventArgs e)


{
Label8.Text = "Hello " + TextBox1.Text + " ! ";
Label8.Text = TextBox1.Text + " <br> You have successfuly Registered with the following
details.";
Label9.Text = TextBox1.Text;
Label10.Text = TextBox2.Text;
if (RadioButton1.Checked)
{
Label11.Text = RadioButton1.Text;
}
else
Label11.Text = RadioButton2.Text;
var courses = "";
if (CheckBox1.Checked)
{
courses = CheckBox1.Text + " ";
}
if (CheckBox2.Checked)
{
courses = CheckBox2.Text + " ";
}
if (CheckBox3.Checked)
{
courses = CheckBox3.Text;
}
Label12.Text = courses;

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:

To write an ASP.NET program to design an AdRotator 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.

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

<!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>
<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/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs
p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n
bsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
Today&#39;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)
{

protectedvoid Calendar1_SelectionChanged(object sender, EventArgs e)


{
TextBox1.Text = Calendar1.TodaysDate.ToShortDateString();
}
}
}
OUTPUT :

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

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

protectedvoid Button1_Click(object sender, EventArgs e)


{

{
int number, limit;
StringBuilder sb = newStringBuilder();

number = Convert.ToInt32(txtinputno.Text);
limit = Convert.ToInt32(txtlimit.Text);

for (int i = 1; i <= limit; i++)


{
string tableFormat = "{0} * {1} = {2} ";
sb.Append(string.Format(tableFormat, number, i, number *
i)).Append(Environment.NewLine).Append("<br />");
}
Label1 .Text =sb.ToString();
}
}
}
}
OUTPUT:

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

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

STUDENT DETAILS USING GRID VIEW CONTROL

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

<!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=
"/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"%>

<!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: 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"%>

<!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: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();
}

protected void Button1_Click(object sender, EventArgs e)


{
try
{

SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrin


gs["RegiConnectionString"].ConnectionString);
conn.Open();
string insertQuery = "insert into RegisterDataBase(StudentName,Passwords,EmailI
d,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());
}
}
}
}

STUDENT.ASPX

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


erits="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>
<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"%>

<!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="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>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs
p;&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"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)
{

protectedvoid CountryChanged(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";
}

protectedvoid CityChanged(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";
}

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

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


{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
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);

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

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

You might also like