0% found this document useful (0 votes)
44 views115 pages

Awp Final Practical

The document outlines practical exercises for working with C# and ASP.NET. It includes 7 topics with multiple subsections covering: 1. Basic C# and ASP.NET concepts like obtaining user input, string operations, and displaying student data. 2. Object oriented programming concepts like inheritance, interfaces, and exception handling. 3. Web forms, controls, and their properties. 4. Form and validation controls. 5. Navigation, styling with master pages. 6. Working with databases including binding controls and CRUD operations. 7. More database examples like dropdown binding and phone number retrieval.

Uploaded by

muzammil04786
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
44 views115 pages

Awp Final Practical

The document outlines practical exercises for working with C# and ASP.NET. It includes 7 topics with multiple subsections covering: 1. Basic C# and ASP.NET concepts like obtaining user input, string operations, and displaying student data. 2. Object oriented programming concepts like inheritance, interfaces, and exception handling. 3. Web forms, controls, and their properties. 4. Form and validation controls. 5. Navigation, styling with master pages. 6. Working with databases including binding controls and CRUD operations. 7. More database examples like dropdown binding and phone number retrieval.

Uploaded by

muzammil04786
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 115

INDEX

Practical
No.
Date Sign
Topic
1. Working with basic C# and ASP .NET
a. Create an application that obtains four int values
from the user and displays the product.
b. Create an application to demonstrate string
operations.
c. Create an application that receives the (Student Id,
Student Name, Course Name, Date of Birth)
information from a set of students. The application
should also display the information of all the students
once the data entered.
d. Create an application to demonstrate following
operations i. Generate Fibonacci series. ii. Test
for prime numbers. iii. Test for vowels.
iv. Use of foreach loop with arrays

v. Reverse a number and find sum of digits of a


number.
2. Working with Object Oriented C# and ASP .NET
a. Create simple application to perform following
operations i. Finding factorial Value ii. Money
Conversion iii. Quadratic Equation iv.
Temperature Conversion
b. Create simple application to demonstrate use of
following concepts

i. Function Overloading ii. Inheritance (all


types) iii. Constructor overloading iv. Interfaces
c. Create simple application to demonstrate use of
following concepts

i. Using Delegates and events ii. Exception


handling
Working with Web Forms and Controls
3. a. Create a simple web page with various sever controls
to demonstrate setting and use of their properties.
(Example :

AutoPostBack)
b. Demonstrate the use of Calendar control to perform
following operations.

a) Display messages in a calendar control. b) Display


vacation in a calendar control.

c) Selected day in a calendar control using style. d)


Difference between two calendar dates
c. Demonstrate the use of Treeview control perform
following operations.

a) Treeview control and datalist b) Treeview


operations
4. Working with Form Controls
a. Create a Registration form to demonstrate use of various
Validation controls.
b. Create Web Form to demonstrate use of Adrotator
Control.
c. Create Web Form to demonstrate use User Controls.
5. Working with Navigation, Beautification and Master
page.
a. Create Web Form to demonstrate use of Website
Navigation controls and Site Map.
b. Create a web application to demonstrate use of Master
Page with applying Styles and Themes for page
beautification.
c. Create a web application to demonstrate various states
of ASP.NET Pages.
6. Working with Database
a. Create a web application bind data in a multiline
textbox by querying in another textbox.
b. Create a web application to display records by using
database.

4|Page
c. Demonstrate the use of Datalist link control.
7. Working with Database
a. Create a web application to display Databinding using
dropdownlist control.
b. Create a web application for to display the phone no of
an author using database.
c. Create a web application for inserting and deleting
record from a database. (Using Execute-Non Query).
Practical 1

Working with basic C# and ASP .NET


a) Create an application that obtains four int values from the user and displays the product. Design

Default .aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default3.aspx.cs"
Inherits="Default3" %>

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


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

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>

6|Page
<body>
<form id="form1" runat="server">
<div>

</div>
<asp:TextBox ID="TextBox1" runat="server" Height="23px"></asp:TextBox>
<p>
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
</p>
<p>
<asp:TextBox ID="TextBox3" runat="server"></asp:TextBox>
</p>
<p>
<asp:TextBox ID="TextBox4" runat="server"></asp:TextBox>
</p>
<p>
<asp:TextBox ID="TextBox5" runat="server"></asp:TextBox>
</p>
<asp:Button ID="Button1" runat="server" onclick="Button1_Click"
Text="Button" />
</form>
</body>
</html>

Default.aspx.cs

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

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


{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
int x, y, z, p;
x = Convert.ToInt16(TextBox1.Text);
y = Convert.ToInt16(TextBox2.Text); z
= Convert.ToInt16(TextBox3.Text); p =

7|Page
Convert.ToInt16(TextBox4.Text); int q
= x * y * z * p;
TextBox5.Text = Convert.ToString(q);

}
}

Output

b) Create an application to demonstrate string operations.

Design

Default .aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs"
Inherits="Default2" %>

8|Page
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>

</div>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<br />
<asp:TextBox ID="TextBox2" runat="server" Height="92px"
TextMode="MultiLine"
Width="231px"></asp:TextBox>
<p>
<asp:Button ID="Button1" runat="server" onclick="Button1_Click"
Text="Button" />
</p>
</form>
</body>
</html>

Default.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq; using
System.Web; using System.Web.UI;
using System.Web.UI.WebControls;

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


{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
string str1;

9|Page
str1 = TextBox1.Text;
string[] words = str1.Split(' ');
for(int i =0;i<words.Length;i++)
{
TextBox2.Text=TextBox2.Text + words[i]+"\r\n";
}

}
}

Output

c) Create an application that receives the (Student Id, Student Name, Course Name, Date of Birth)
information from a set of students. The application should also display the information of all the
students once the data entered. Design

10 | P a g e
Default .aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default4.aspx.cs"
Inherits="Default4" %>

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


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

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>

</div>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<p>
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
</p>
<p>
<asp:TextBox ID="TextBox3" runat="server"></asp:TextBox>
</p>
<p>
<asp:TextBox ID="TextBox4" runat="server"></asp:TextBox>
</p>
<p>
<asp:TextBox ID="TextBox5" runat="server"></asp:TextBox>
<asp:Button ID="Button1" runat="server" onclick="Button1_Click"
Text="Button" />

11 | P a g e
</p>
<p>
<asp:Button ID="Button2" runat="server" onclick="Button2_Click"
Text="Button" />
</p>
</form>
</body>
</html>

Default.aspx.cs using
System;
using System.Collections.Generic;
using System.Linq; using
System.Web; using System.Web.UI;
using System.Web.UI.WebControls;
struct student
{
public string studid, name, cname;
public string dob;
}
;
public partial class Default4 : System.Web.UI.Page
{
static student[] s = new student[5];
static int i;

protected void Page_Load(object sender, EventArgs e)


{

}
protected void Button1_Click(object sender, EventArgs e)
{
Response.Write("i=" + i);
s[i].studid = TextBox1.Text;
s[i].name = TextBox2.Text;
s[i].cname = TextBox3.Text;
s[i].dob = TextBox4.Text; i++;
}
protected void Button2_Click(object sender, EventArgs e)
{
for (int y = 0; y < i; y++)
{
Response.Write("i=" + y);

12 | P a g e
Response.Write("student id:" + s[y].studid + "<br>");
Response.Write("Name:" + s[y].cname + "<br>");
Response.Write("Date Of Birth :" + s[y].dob + "<br>");
Response.Write("class:" + s[y].cname + "<br>");
}

}
}

Output

d) Create an application to demonstrate following operations

Generate Fibonacci Series


Design

13 | P a g e
Default .aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default7.aspx.cs"
Inherits="Default7" %>

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


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

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>

<br />
<br />
<asp:Button ID="Button1" runat="server" Text="Button"
onclick="Button1_Click1" />
<p>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
</p>
</div>
</form>
</body>
</html>

Default.aspx.cs using
System;
using System.Collections.Generic;
using System.Linq; using
System.Web; using System.Web.UI;
using System.Web.UI.WebControls;

14 | P a g e
public partial class Default7 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click1(object sender, EventArgs e)
{
int f1 = 0, f2 = 1, f3, n, co;
n = int.Parse(TextBox1.Text); co
= 0;
Response.Write("Fibonaaci series :");
Response.Write(f1 + "\t" + f2); while
(co <= n)
{
f3 = f1 + f2;
Response.Write("\t" + f3);
f1 = f2;
Response.Write("\t" + f3);
f1 = f2; f2 = f3;

co++;
}
}
}

Output

15 | P a g e
Test For Prime Number
Design

Default .aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs"
Inherits="_Default" %>

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


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

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>

<br />
<br />
<br />

</div>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<br />
<asp:Button ID="Button1" runat="server" onclick="Button1_Click"
Text="Button" />
<p>
&nbsp;</p>
<p>
&nbsp;</p>
<div>

<br />

16 | P a g e
</div>
</form>
<p>
&nbsp;</p>
</body>
</html>

Default.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq; using
System.Web; using System.Web.UI;
using System.Web.UI.WebControls;

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


{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{ int
n, c;
n = int.Parse(TextBox1.Text);

for (c = 2; c <= n - 1; c++)


{
if ((n % c) == 0)
break;
} if
(n == 1)
Response.Write(n +
"is neither prime
nor composite");

else if (c < n - 1)
Response.Write(n + "is not prime number");

else
Response.Write(n + "is prime number");

}
}

17 | P a g e
Output

Test For Vowels


Design

Default .aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs"
Inherits="Default2" %>

18 | P a g e
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>

</div>
<p>
&nbsp;</p>
<asp:Button ID="Button1" runat="server" Text="Button" />
<br />
<br />
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
</form>
</body>
</html>

Default.aspx.cs using
System;
using System.Collections.Generic;
using System.Linq; using
System.Web; using System.Web.UI;
using System.Web.UI.WebControls;

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


{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{ string ch;
int count = 0; ch =
TextBox1.Text; for
(int i = 0; i < ch.Length;
i++)
{

19 | P a g e
if ((ch.Substring(i, 1) == "a") || (ch.Substring(i, 1) == "e") ||
(ch.Substring(i, 1) == "i") || (ch.Substring(i, 1) == "o") ||
(ch.Substring(i, 1) == "u"))
{
count++;
}
}
Response.Write("Given string:" + ch);
Response.Write("Total number of vowels:" + count);

}
}

Output

Use of for each loop with arrays

Design

20 | P a g e
Default .aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs"
Inherits="_Default" %>

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


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

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>

<br />
<br />

</div>
<asp:Button ID="Button1" runat="server" Text="Button" />
</form>
</body>
</html>

Default.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq; using
System.Web; using System.Web.UI;
using System.Web.UI.WebControls;

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


{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
int[] a = { 1, 2, 3, 4 };
foreach (int x in a)
Response.Write(x);

21 | P a g e
}
}

Output

Reverse a number and find sum of digit of a number

Design

Default .aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs"
Inherits="_Default" %>

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


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

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>

22 | P a g e
<body>
<form id="form1" runat="server">
<div>

<br />
<br />

</div>
<asp:Button ID="Button1" runat="server" Text="Button" />
<br />
<br />
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
</form>
</body>
</html>

Default.aspx.cs

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

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


{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
int n, m, r = 0, d, sum = 0;
n = int.Parse(TextBox1.Text);
m = n; while (n > 0) {
d = n % 10; r = r * 10 +
d; sum = sum + d;
n = n / 10;
}
Response.Write("Reverse of " + m + "=" + r + "<br>");
Response.Write("sum of its digits :" + sum);

23 | P a g e
}

Output

24 | P a g e
Practical 2

Working with Object Oriented C# and ASP .NET

a) Create simple application to perform following operations:


i)Finding factorial value:

Design

Default.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs"
Inherits="_Default" %>

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


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

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>

<asp:Button ID="Button1" runat="server" Text="Button" />

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

25 | P a g e
</html>

Default.aspx.cs

using System;
using System.Collections.Generic;
using System.Linq; using
System.Web; using System.Web.UI;
using System.Web.UI.WebControls;
class fact { public int n, f;
public fact() { f = 1;
}
public void cal()
{
int i;
for (i = 1; i <= n; i++)
{
f = f * i;
}
} }
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
fact f1 = new fact();
f1.n = 5; f1.cal();
Response.Write(f1.n + "!= " + f1.f);
}
}

Output

ii)Money Conversion
Design

26 | P a g e
Default.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs"
Inherits="_Default" %>

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


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

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<asp:RadioButton ID="RadioButton1" runat="server" AutoPostBack="True"
oncheckedchanged="RadioButton1_CheckedChanged" Text="Dollar to Rupee" />
&nbsp;&nbsp;&nbsp;
<asp:RadioButton ID="RadioButton2" runat="server" AutoPostBack="True"
oncheckedchanged="RadioButton2_CheckedChanged" Text="Rupee to Dollar" />
&nbsp;&nbsp;&nbsp;
<asp:RadioButton ID="RadioButton3" runat="server" AutoPostBack="True"
oncheckedchanged="RadioButton3_CheckedChanged" Text="Euro to Rupee" />
&nbsp;&nbsp;&nbsp;
<asp:RadioButton ID="RadioButton4" runat="server" AutoPostBack="True"
oncheckedchanged="RadioButton4_CheckedChanged" Text="Rupee to Euro" />
</form>
</body>
</html>

Default.aspx.cs using
System; using
System.Collections.Ge
neric; using

27 | P a g e
System.Linq; using
System.Web; using
System.Web.UI; using
System.Web.UI.WebCont
rols; public class
Class1
{ public double r, e, d;
public Class1()
{ r
= 0; e
= 0; d
= 0; }
public void convertdtor()
{
double ev = 60;
r = d * ev;
}
public void convertetor()
{
double ev = 80;
r = e * ev;
}
public void convertrtod()
{
double ev = 65;
d = r / ev;
}
public void convertrtoe()
{
double ev = 80;
e = r / ev;
} }
public partial class _Default : System.Web.UI.Page
{
Class1 f1;
protected void Page_Load(object sender, EventArgs e)
{
f1 = new Class1();
}
protected void RadioButton1_CheckedChanged(object sender, EventArgs e)
{
if (RadioButton1.Checked == true)
{
f1.d = Convert.ToInt16(TextBox1.Text);
f1.convertdtor();
Response.Write(f1.d + " Dollar " + " = Rs." + f1.r);
}

28 | P a g e
}
protected void RadioButton2_CheckedChanged(object sender, EventArgs e)
{
if (RadioButton2.Checked == true)
{
f1.r = Convert.ToInt16(TextBox1.Text);
f1.convertrtod();
Response.Write(f1.r + " Rupee " + " = $" + f1.d);
}
}
protected void RadioButton3_CheckedChanged(object sender, EventArgs e)
{
if (RadioButton3.Checked == true)
{
f1.e = Convert.ToInt16(TextBox1.Text);
f1.convertetor();
Response.Write(f1.e + " Euro " + " = Rs." + f1.r);
}
}
protected void RadioButton4_CheckedChanged(object sender, EventArgs e)
{
if (RadioButton4.Checked == true)
{
f1.r = Convert.ToInt16(TextBox1.Text);
f1.convertrtoe();
Response.Write(f1.r + "=Rs to Euro " + f1.e);
}
}
}

Output

iii)Quadratic Equations
Design

29 | P a g e
Default.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs"
Inherits="_Default" %>

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


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

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>

<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>


&nbsp;&nbsp;&nbsp;
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
&nbsp;&nbsp;&nbsp;
<asp:TextBox ID="TextBox3" runat="server"></asp:TextBox>
&nbsp;&nbsp;&nbsp;
<asp:Button ID="Button1" runat="server" onclick="Button1_Click"
Text="Button" />

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

Default.aspx.cs using
System;

30 | P a g e
using System.Collections.Generic;
using System.Linq; using
System.Web; using System.Web.UI;
using System.Web.UI.WebControls; class
Quadraticroots
{ public double a, b, c, r1, r2;
public double compute()
{ int m;
double d1; d1 = b * b -
4 * a * c; if (d1 == 0)
{
r1 = r2 = (-b) / (2 * a);
return d1;
}
else if (d1 > 0)
{
r1 = (-b + Math.Sqrt(d1)) / (2 * a);
return d1;
}
else {
r1 = (-b) / (2 * a); r2
= Math.Sqrt(-d1) / (2 * a); return
d1;
}
} }
public partial class _Default : System.Web.UI.Page
{
Quadraticroots q;
protected void Page_Load(object sender, EventArgs e)
{
q = new Quadraticroots();
}
protected void Button1_Click(object sender, EventArgs e)
{
q.a = Convert.ToInt16(TextBox1.Text);
q.b = Convert.ToInt16(TextBox2.Text);
q.c = Convert.ToInt16(TextBox3.Text); double d = q.compute();
if (d == 0)
{
Response.Write("\nRoots are Real and Equal <br>");
Response.Write("First and Second root is "+q.r1);
}
else if (d < 0)
{
Response.Write("\nRoots are Real and Distinct<br>");
Response.Write("\nFirst root is: "+q.r1+"<br>");

31 | P a g e
Response.Write("\nSecond root is: " + q.r2 + "<br>"); }
else
{
Response.Write("\nRoots are Imaginary<br>");
Response.Write("\nFirst root is: " + q.r1 + "<br>");
Response.Write("\nSecond root is: " + q.r2 + "<br>");
}
}

Output

iv)Temperature Conversion
Design

32 | P a g e
Default.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs"
Inherits="_Default" %>

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


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

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>

<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>


<br />
<br />
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
<br />
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
<br />
<asp:Button ID="Button1" runat="server" onclick="Button1_Click"
Text="Button" />

</div>
</form>
</body>
</html>
Default.aspx.cs using
System;
using System.Collections.Generic;
using System.Linq; using
System.Web; using System.Web.UI;
using System.Web.UI.WebControls;
class converttemp
{
public float celsius, faren;
public converttemp()
{ celsius
= 0; faren =
0;
}
public void converttofaren()
{
faren = ((celsius * 9.0f / 5.0f) + 32.0f);
}

33 | P a g e
public void converttocel()
{
celsius = (faren - 32) * (5.0f / 9.0f);
}
}
public partial class _Default : System.Web.UI.Page
{
converttemp c;
protected void Page_Load(object sender, EventArgs e)
{
c = new converttemp();
}
protected void Button1_Click(object sender, EventArgs e)
{
char ch;
ch = Convert.ToChar(TextBox1.Text);
if (ch == 'c')
{
c.celsius = float.Parse(TextBox2.Text);
c.converttofaren();
Label1.Text = "Celsius to Farenheit: " + c.faren;
}
else
{
c.faren = float.Parse(TextBox2.Text);
c.converttocel();
Label1.Text = "Farenheit to Celsius: " + c.celsius;
}
}
}

Output

34 | P a g e
b) Create simple application to demonstrate use of following concepts
i. Function Overloading
Design

Default.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs"
Inherits="_Default" %>

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


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

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>

<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>


<br />
<asp:Label ID="Label2" runat="server" Text="Label"></asp:Label>
<br />
<asp:Label ID="Label3" runat="server" Text="Label"></asp:Label>
<br />
<asp:Button ID="Button1" runat="server" onclick="Button1_Click"
Text="Button" />

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

Default.aspx.cs using
System;
using System.Collections.Generic;
using System.Linq; using
System.Web; using System.Web.UI;
using System.Web.UI.WebControls;
class overloading
{

35 | P a g e
public int sum(int a, int b)
{
int x;
return x = a + b;
}
public int sum(int a, int b,int c)
{
int y;
return y = a + b + c;
}
public float sum(float a, float b)
{ float u;
return u = a + b;
}
public float sum(float a, float b, float c)
{
float v;
return v = a + b + c;
} }
public partial class _Default : System.Web.UI.Page
{
overloading o;
protected void Page_Load(object sender, EventArgs e)
{
o = new overloading();
}
protected void Button1_Click(object sender, EventArgs e)
{
Label1.Text = Convert.ToString(o.sum(10,20));
Label2.Text = Convert.ToString(o.sum(10,20,30));
Label3.Text = Convert.ToString(o.sum(12.0f,23.1f,32.5f));
}
}

Output

ii)Inheritance Single
Inheritance
Design

36 | P a g e
Default.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs"
Inherits="_Default" %>

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


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

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>

<asp:Button ID="Button1" runat="server" onclick="Button1_Click"


Text="Button" />

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

Default.aspx.cs using
System;
using System.Collections.Generic;
using System.Linq; using
System.Web; using System.Web.UI;
using System.Web.UI.WebControls;
public class basec
{
public int d;
public string basemethod()
{
string p = "This is baseclass method";
return p;
} }
public class Derived : basec
{
public string derivedmethod()
{
string s = "This is derivedclass method";
return s;
} }
public partial class _Default : System.Web.UI.Page
{

37 | P a g e
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
basec b = new basec();
Response.Write("Calling from base class object: " + b.basemethod());
Derived d = new Derived();
Response.Write("<br>Calling from derived class method:<br>" +
d.basemethod());
Response.Write("<br>" + d.derivedmethod());
}
}

Output

B)Multi Level Inheritance


Design

Default.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs"
Inherits="_Default" %>

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


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

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>

<asp:Button ID="Button1" runat="server" onclick="Button1_Click"


Text="Button" />

</div>
</form>

38 | P a g e
</body>
</html>
Default.aspx.cs using
System;
using System.Collections.Generic;
using System.Linq; using
System.Web; using System.Web.UI;
using System.Web.UI.WebControls;
class A {
public string show()
{
return ("First base Class");
} }
class B : A
{
public string display()
{
return ("Second base Class");
} }
class C : B
{
public string show1()
{
return ("Child Class");
} }
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
C obj = new C();
Response.Write(obj.show()+"<br>");
Response.Write(obj.display()+"<br>");
Response.Write(obj.show1()+"<br>");
}
}
Output

39 | P a g e
C)Multiple Inheritance
Design

Default.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs"
Inherits="_Default" %>

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


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

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>

<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>


<br />
<asp:Label ID="Label2" runat="server" Text="Label"></asp:Label>
<br />
<asp:Button ID="Button1" runat="server" onclick="Button1_Click"
Text="Button" />

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

Default.aspx.cs using
System;
using System.Collections.Generic;
using System.Linq; using
System.Web; using System.Web.UI;
using System.Web.UI.WebControls;
class Shape

40 | P a g e
{ public int side; public void
setSide(int s)
{ side
= s;
} }
public interface Cost
{
int getCost(int area);
}
class square : Shape, Cost
{
public int getArea()
{
return (side * side);
}
public int getCost(int area)
{
return area * 10;
} }
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
square sq = new square();
int area; sq.setSide(15);
area = sq.getArea(); Label1.Text =
"Area: " + area; int c =
sq.getCost(area); Label2.Text =
"Cost is Rs: " + c;
}
}

Output

D) Hierarchical Inheritance
Design

41 | P a g e
Default.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs"
Inherits="_Default" %>

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


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

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>

<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>


<br />
<asp:Button ID="Button1" runat="server" onclick="Button1_Click"
Text="Button" />

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

Default.aspx.cs using
System;
using System.Collections.Generic;
using System.Linq; using
System.Web; using System.Web.UI;
using System.Web.UI.WebControls;
class A {
public string show()
{
return ("Welcome");
} }
class B : A
{
public string display()
{
return (" to the World");
} }
class C : A

42 | P a g e
{ public string show1()
{
return (" Of Programming");
} }
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
C c1 = new C();
B b1 = new B();
string s = ""; s +=
c1.show(); s +=
b1.display(); s +=
c1.show1();
Label1.Text = s;
}
}

Output

iii) Constructor Overloading Design

Default.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs"
Inherits="_Default" %>

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


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

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>

43 | P a g e
<asp:Button ID="Button1" runat="server" onclick="Button1_Click"
style="height: 29px" Text="Button" />
</div>
</form>
</body>
</html>

Default.aspx.cs using
System;
using System.Collections.Generic;
using System.Linq; using
System.Web; using System.Web.UI;
using System.Web.UI.WebControls;
class Marksheet
{
public float m1, m2, m3;
string name; public
Marksheet()
{ m1
= 20; m2
= 40; m3
= 40; }
public Marksheet(float ms)
{ m1
= ms; }
public Marksheet(float ms1, float ms2)
{ m1 =
ms1; m2 =
ms2; }
public Marksheet(float ms1, float ms2,float ms3)
{ m1 =
ms1; m2 =
ms2; m3 =
ms3; }
public float tot()
{
float t = m1 + m2 + m3;
return t;
} }
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
Marksheet a = new Marksheet();

44 | P a g e
Marksheet b = new Marksheet(90);
Marksheet c = new Marksheet(88,60);
Marksheet d = new Marksheet(70, 90, 55);
Response.Write("In marksheet 1:");
Response.Write(a.tot()+"<br>");
Response.Write("In marksheet 2:");
Response.Write(b.tot()+"<br>");
Response.Write("In marksheet 3:");
Response.Write(c.tot()+"<br>");
Response.Write("In marksheet 4:");
Response.Write(d.tot()+"<br>");
}
}

Output

iv)Interfaces Design

Default.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs"
Inherits="_Default" %>

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


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

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>

<asp:Button ID="Button1" runat="server" onclick="Button1_Click"


style="height: 29px" Text="Button" />

</div>
</form>

45 | P a g e
</body>
</html>
Default.aspx.cs using
System;
using System.Collections.Generic;
using System.Linq; using
System.Web; using System.Web.UI;
using System.Web.UI.WebControls;
public interface ITransactions
{ string
retcode(); double
amtfunc();
}
public class Transaction : ITransactions
{ private string tCode;
private double amount;
public Transaction()
{ tCode =
""; amount =
0.0;
}
public Transaction(string c, double a)
{ tCode
= c; amount
= a;
}
public double amtfunc()
{
return amount;
}
public string retcode()
{
return tCode;
} }
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
Transaction t1 = new Transaction("Cr", 780.00);
Transaction t2 = new Transaction("Db", 400.00);
Response.Write("<br>Code: " + t1.retcode());
Response.Write("<br>Amount: " + t1.amtfunc());
Response.Write("<br>Code: " + t2.retcode());
Response.Write("<br>Amount: " + t2.amtfunc());

46 | P a g e
}
}

Output

2)c)Create a simple application to demonstrate use of following concepts:


(i) Using Delegates and Events: Design

Default.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs"
Inherits="_Default" %>

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


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

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Button ID="Button1" runat="server" Text="Button"
onclick="Button1_Click" />
</div>
</form>
</body>
</html>

Default.aspx.cs using
System;
using System.Collections.Generic;
using System.Linq; using
System.Web; using System.Web.UI;
using System.Web.UI.WebControls;

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


{

47 | P a g e
public delegate void SimpleDelegate();
public void callingFunction()
{
Response.Write("First Function Called.....<br>");
}
public void secfunction()
{
Response.Write("Second Function Called.....<br>");
}
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
SimpleDelegate sd = new SimpleDelegate(callingFunction);
sd();
sd += new SimpleDelegate(secfunction);
sd();
}
}
Output

(ii) Exception Handling:


Design

Default.aspx

48 | P a g e
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs"
Inherits="_Default" %>

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


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

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>

<asp:Button ID="Button1" runat="server" onclick="Button1_Click"


Text="Button" />
&nbsp;&nbsp;&nbsp;
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>

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

Default.aspx.cs using
System;
using System.Collections.Generic;
using System.Linq; using System.Web;
using System.Web.UI; using
System.Web.UI.WebControls; class
NegativeException : Exception
{
public NegativeException(string msg)
: base(msg)
{
} }
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{ int
num; try
{

49 | P a g e
num = int.Parse(TextBox1.Text);
if (num < 0)
throw new NegativeException("Negative Number");
else
Console.WriteLine("Positive Number");
}
catch (NegativeException en)
{
Response.Write(en.Message);
}
}
}

Output

50 | P a g e
Practical3

Working with Web Forms and Controls

a. Create a simple web page with various sever controls to demonstrate


setting and use of their properties. (Example : AutoPostBack) Design

Default.aspx

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

51 | P a g e
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<style type="text/css">
.style1
{
width: 100%;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<table class="style1">
<tr>
<td>
<asp:Label ID="Label1" runat="server" Text="Rno"></asp:Label>
</td>
<td>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td>
<asp:Label ID="Label2" runat="server" Text="Name"></asp:Label>
</td>
<td>
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td>
<asp:Label ID="Label3" runat="server" Text="Class"></asp:Label>
</td>
<td>
<asp:RadioButton ID="RadioButton1" runat="server" Text="FY" />
<asp:RadioButton ID="RadioButton2" runat="server" Text="SY" />
<asp:RadioButton ID="RadioButton3" runat="server" Text="TY" />
</td>
</tr>

52 | P a g e
<tr>
<td>
<asp:Label ID="Label4" runat="server" Text="Course"></asp:Label>
</td>
<td>
<asp:DropDownList ID="DropDownList1" runat="server">
<asp:ListItem>B.Com</asp:ListItem>
<asp:ListItem>BMS</asp:ListItem>
<asp:ListItem>B.SC(IT)</asp:ListItem>
<asp:ListItem>B.SC(CS)</asp:ListItem>
</asp:DropDownList>
</td>
</tr>
<tr>
<td>
&nbsp;</td>
<td>
<asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" />
</td>
</tr>
<tr>
<td colspan="2">
<asp:Label ID="Label5" runat="server" Text="Label"></asp:Label>
</td>
</tr>
</table>
<div>

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

Default.aspx.cs using
System;
using System.Collections.Generic;
using System.Linq; using
System.Web; using
System.Web.UI;
using System.Web.UI.WebControls;

53 | P a g e
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

}
protected void Button1_Click(object sender, EventArgs e)
{
string s;
if (RadioButton1.Checked == true)
{
s = RadioButton1.Text;
}
if (RadioButton2.Checked == true)
{
s = RadioButton2.Text;
}
else
{
s = RadioButton3.Text;
}
Label5.Text += "in " + s;
}
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
Label5.Text = "You have been enrolled in" + DropDownList1.SelectedItem;
}
}

Output

54 | P a g e
3b)Demonstrate the use of Calendar control to perform following operations.
a) Display messages in a calendar control Design

55 | P a g e
Default.aspx

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

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


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

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">

56 | P a g e
<div>

<asp:Calendar ID="Calendar1" runat="server" BackColor="White"


BorderColor="Black" BorderStyle="Solid" CellSpacing="1" Font-Names="Verdana" Font-
Size="9pt" ForeColor="Black" Height="250px" NextPrevFormat="ShortMonth"
ondayrender="Calendar1_DayRender" onselectionchanged="Calendar1_SelectionChanged"
Width="330px"> <DayHeaderStyle Font-Bold="True" Font-Size="8pt" ForeColor="#333333"
Height="8pt" />
<DayStyle BackColor="#CCCCCC" />
<NextPrevStyle Font-Bold="True" Font-Size="8pt" ForeColor="White" />
<OtherMonthDayStyle ForeColor="#999999" />
<SelectedDayStyle BackColor="#333399" ForeColor="White" />
<TitleStyle BackColor="#333399" BorderStyle="Solid" Font-Bold="True"
Font-Size="12pt" ForeColor="White" Height="12pt" />
<TodayDayStyle BackColor="#999999" ForeColor="White" />
</asp:Calendar>

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

Default.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq; using
System.Web; using
System.Web.UI;
using System.Web.UI.WebControls;

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


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

}
protected void Calendar1_SelectionChanged(object sender, EventArgs e)
{

}
protected void Calendar1_DayRender(object sender, DayRenderEventArgs e)

57 | P a g e
{
if (e.Day.Date.Day == 18)
e.Cell.Controls.Add(new LiteralControl("</br>Holiday"));
}

Output

b) Display vacation in a calendar control


Design

58 | P a g e
Default.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

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


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

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>

59 | P a g e
<asp:Calendar ID="Calendar1" runat="server" BackColor="White"
BorderColor="Black" BorderStyle="Solid" CellSpacing="1" Font-Names="Verdana"
Font-Size="9pt" ForeColor="Black" Height="250px" NextPrevFormat="ShortMonth"
ondayrender="Calendar1_DayRender" onselectionchanged="Calendar1_SelectionChanged"
Width="330px"> <DayHeaderStyle Font-Bold="True" Font-Size="8pt" ForeColor="#333333"
Height="8pt" />
<DayStyle BackColor="#CCCCCC" />
<NextPrevStyle Font-Bold="True" Font-Size="8pt" ForeColor="White" />
<OtherMonthDayStyle ForeColor="#999999" />
<SelectedDayStyle BackColor="#333399" ForeColor="White" />
<TitleStyle BackColor="#333399" BorderStyle="Solid" Font-Bold="True"
Font-Size="12pt" ForeColor="White" Height="12pt" />
<TodayDayStyle BackColor="#999999" ForeColor="White" />
</asp:Calendar>

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

Default.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq; using
System.Web; using
System.Web.UI;
using System.Web.UI.WebControls;

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


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

}
protected void Calendar1_SelectionChanged(object sender, EventArgs e)
{

}
protected void Calendar1_DayRender(object sender, DayRenderEventArgs e)
{

60 | P a g e
if ((e.Day.Date >= new DateTime(2018, 09, 18)) && (e.Day.Date <= new DateTime(2018, 09, 25)))
{
e.Cell.BackColor=System.Drawing.Color.Blue;
e.Cell.BorderColor = System.Drawing.Color.Black;
e.Cell.BorderWidth = new Unit(3);
}
}

Output

c) Selected day in a calendar control using style


Design

61 | P a g e
Default.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

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


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

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>

62 | P a g e
<asp:Calendar ID="Calendar1" runat="server" BackColor="White"
BorderColor="Black" BorderStyle="Solid" CellSpacing="1" Font-Names="Verdana"
Font-Size="9pt" ForeColor="Black" Height="250px" NextPrevFormat="ShortMonth"
ondayrender="Calendar1_DayRender" onselectionchanged="Calendar1_SelectionChanged"
Width="330px"> <DayHeaderStyle Font-Bold="True" Font-Size="8pt" ForeColor="#333333"
Height="8pt" />
<DayStyle BackColor="#CCCCCC" />
<NextPrevStyle Font-Bold="True" Font-Size="8pt" ForeColor="White" />
<OtherMonthDayStyle ForeColor="#999999" />
<SelectedDayStyle BackColor="#333399" ForeColor="White" />
<TitleStyle BackColor="#333399" BorderStyle="Solid" Font-Bold="True"
Font-Size="12pt" ForeColor="White" Height="12pt" />
<TodayDayStyle BackColor="#999999" ForeColor="White" />
</asp:Calendar>

</div>
</form>
</body>
</html> Default.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq; using
System.Web; using
System.Web.UI;
using System.Web.UI.WebControls;

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


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

}
protected void Calendar1_SelectionChanged(object sender, EventArgs e)
{

}
protected void Calendar1_DayRender(object sender, DayRenderEventArgs e)
{
if ((e.Day.Date >= new DateTime(2018, 09, 9)) && (e.Day.Date <= new DateTime(2018, 09, 18)))
{

63 | P a g e
e.Cell.BackColor = System.Drawing.Color.Cyan;
e.Cell.BorderColor = System.Drawing.Color.Black;
e.Cell.BorderWidth = new Unit(3);
}
if (e.Day.IsOtherMonth)
{
e.Cell.Controls.Clear();
}
}
}

Output

d) Difference between two calendar dates


Design

64 | P a g e
Default.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

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

65 | P a g e
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>

<asp:Calendar ID="Calendar1" runat="server"


onselectionchanged="Calendar1_SelectionChanged"></asp:Calendar>
<br />
<asp:Calendar ID="Calendar2" runat="server"></asp:Calendar>
<br />
<asp:Label ID="Label1" runat="server" Text="No Of Days is: "></asp:Label>
<asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" />

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

Default.aspx.cs
Default.aspx.cs

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

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


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

}
protected void Calendar1_SelectionChanged(object sender, EventArgs e)
{

66 | P a g e
}
protected void Calendar1_DayRender(object sender, DayRenderEventArgs e)
{
if (e.Day.Date.Day == 18)
e.Cell.Controls.Add(new LiteralControl("</br>Holiday")); if ((e.Day.Date >= new
DateTime(2018, 09, 23)) && (e.Day.Date <= new DateTime(2018, 09, 30)))
{
e.Cell.BackColor = System.Drawing.Color.Blue;
e.Cell.BorderColor = System.Drawing.Color.Black;
e.Cell.BorderWidth = new Unit(3);
}
if ((e.Day.Date >= new DateTime(2018, 07, 09)) && (e.Day.Date <= new DateTime(2018, 07, 18)))
{
e.Cell.BackColor = System.Drawing.Color.Cyan;
e.Cell.BorderColor = System.Drawing.Color.Black;
e.Cell.BorderWidth = new Unit(3);
}
if (e.Day.IsOtherMonth)
{
e.Cell.Controls.Clear();
}
}
protected void Button1_Click(object sender, EventArgs e)
{
TimeSpan t = Calendar1.SelectedDate - Calendar2.SelectedDate;
Label1.Text += t.Days.ToString();
}
}

Output

67 | P a g e
3c)Demonstrate the use of Treeview control perform following operations.
Treeview control and datalist
Design

68 | P a g e
Default.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

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


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

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>

69 | P a g e
<asp:TreeView ID="TreeView1" runat="server">
<Nodes>
<asp:TreeNode Checked="True" ShowCheckBox="True" Text="Course" Value="Course">
<asp:TreeNode Checked="True" ShowCheckBox="True" Text="BSC(IT)"
Value="BSC(IT)"></asp:TreeNode>
<asp:TreeNode Checked="True" ShowCheckBox="True" Text="B.Com"
Value="B.Com"></asp:TreeNode>
</asp:TreeNode>
</Nodes>
</asp:TreeView>

<br />
<asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" />
<br />
<asp:DataList ID="DataList1" runat="server">
<ItemTemplate>
<%# Eval("text") %>>
</ItemTemplate>
</asp:DataList>

</div>
</form>
</body>
</html> Default.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq; using
System.Web; using
System.Web.UI;
using System.Web.UI.WebControls;

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


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

}
protected void Button1_Click(object sender, EventArgs e)
{
TreeNodeCollection T;
T = TreeView1.CheckedNodes;

70 | P a g e
DataList1.DataSource = T;
DataList1.DataBind();
DataList1.Visible = true;
}
}

Output

Treeview operations
Design

71 | P a g e
Default.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

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


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

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>

</div>
<asp:TreeView ID="TreeView1" runat="server"

72 | P a g e
onselectednodechanged="TreeView1_SelectedNodeChanged">
<Nodes>
<asp:TreeNode Checked="True" ShowCheckBox="True" Text="Course" Value="Course">
<asp:TreeNode Checked="True" ShowCheckBox="True" Text="BSC(IT)" Value="BSC(IT)">
<asp:TreeNode Text="FY" Value="FY"></asp:TreeNode>
<asp:TreeNode Text="SY" Value="SY"></asp:TreeNode>
</asp:TreeNode>
<asp:TreeNode Checked="True" ShowCheckBox="True" Text="B.Com" Value="B.Com">
<asp:TreeNode Text="FY" Value="FY"></asp:TreeNode>
<asp:TreeNode Text="TY" Value="TY"></asp:TreeNode>
</asp:TreeNode>
</asp:TreeNode>
</Nodes>
</asp:TreeView>
</form>
</body>
</html> Default.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq; using
System.Web; using
System.Web.UI;
using System.Web.UI.WebControls;

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


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

}
protected void TreeView1_SelectedNodeChanged(object sender, EventArgs e)
{
Response.Write("You have selected the option: "+TreeView1.SelectedValue);
}
protected void TreeView1_TreeNodeCollapsed(object sender, TreeNodeEventArgs e)
{
Response.Write("The value Collapsed Was: "+e.Node.Value);
}
}

73 | P a g e
Output

74 | P a g e
Practical 4

Working with Form Controls

a)Create a Registration form to demonstrate use of various Validation


controls.
Design

Default.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

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


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

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<style type="text/css">

75 | P a g e
.style1
{
width: 100%;
height: 252px; }
.style3
{
width: 150px;
text-align: center;
}
.style4
{
width: 192px;
text-align: right;
}
.style5
{}
.style7
{
width: 269px;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<table class="style1">
<tr>
<td class="style4">
<asp:Label ID="Label1" runat="server" Text="Enter Name :"></asp:Label>
</td>
<td class="style3">
<asp:TextBox ID="TextBox1" runat="server" Width="150px"></asp:TextBox>
</td>
<td class="style7">
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server"
ControlToValidate="TextBox1" ErrorMessage="*Name
Required"></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td class="style4">

76 | P a g e
<asp:Label ID="Label2" runat="server" Text="Enter Password :"></asp:Label>
</td>
<td class="style3">
<asp:TextBox ID="TextBox2" runat="server" TextMode="Password"
Width="150px"></asp:TextBox>
</td>
<td class="style7">
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server"
ControlToValidate="TextBox2" ErrorMessage="*Password
Required"></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td class="style4">
<asp:Label ID="Label3" runat="server" Text="Confirm Password :"></asp:Label>
</td>
<td class="style3">
<asp:TextBox ID="TextBox3" runat="server" TextMode="Password"
Width="150px"></asp:TextBox>
</td>
<td class="style7">
<asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server"
ControlToValidate="TextBox3" Display="Dynamic"
ErrorMessage="*Password Required"></asp:RequiredFieldValidator>
<asp:CompareValidator ID="CompareValidator1" runat="server"
ControlToCompare="TextBox2" ControlToValidate="TextBox3"
ErrorMessage="*Enter Same Password"></asp:CompareValidator>
</td>
</tr>
<tr>
<td class="style4">
<asp:Label ID="Label4" runat="server" Text="Enter Your Age :"></asp:Label>
</td>
<td class="style3">
<asp:TextBox ID="TextBox4" runat="server" Width="150px"></asp:TextBox>
</td>
<td class="style7">
<asp:RequiredFieldValidator ID="RequiredFieldValidator4" runat="server"
ControlToValidate="TextBox4" Display="Dynamic" ErrorMessage="*Enter
Age"></asp:RequiredFieldValidator>

77 | P a g e
<asp:RangeValidator ID="RangeValidator1" runat="server"
ControlToValidate="TextBox4"
ErrorMessage="*Age Required should be between 21 to 30" MaximumValue="30"
MinimumValue="21"></asp:RangeValidator>
</td>
</tr>
<tr>
<td class="style4">
<asp:Label ID="Label5" runat="server" Text="Enter Your Email Id :"></asp:Label>
</td>
<td class="style3">
<asp:TextBox ID="TextBox5" runat="server" Width="150px"></asp:TextBox>
</td>
<td class="style7">
<asp:RequiredFieldValidator ID="RequiredFieldValidator5" runat="server"
ControlToValidate="TextBox5" Display="Dynamic"
ErrorMessage="*Email Id Required"></asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server"
ControlToValidate="TextBox5" ErrorMessage="*Email Id should be proper"
ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([.]\w+)*"></asp:RegularExpressionValidator>
</td>
</tr>
<tr>
<td class="style4">
<asp:Label ID="Label6" runat="server" Text="User Id :"></asp:Label>
</td>
<td class="style3">
<asp:TextBox ID="TextBox6" runat="server" Width="150px"></asp:TextBox>
</td>
<td class="style7">
<asp:RequiredFieldValidator ID="RequiredFieldValidator6" runat="server"
ControlToValidate="TextBox6" Display="Dynamic" ErrorMessage="*User Id
Required"></asp:RequiredFieldValidator>
<asp:CustomValidator ID="CustomValidator1" runat="server"
ControlToValidate="TextBox6" ErrorMessage="*User Id should write properly"
onservervalidate="CustomValidator1_ServerValidate"></asp:CustomValidator>
</td>
</tr>
<tr>
<td class="style4">
&nbsp;</td>

78 | P a g e
<td class="style3">
<asp:Button ID="Button1" runat="server" CssClass="style5" Text="Button" />
</td>
<td class="style7">
&nbsp;</td>
</tr>
</table>
</form>
</body>
</html>

Default.aspx.cs using
System;
using System.Collections.Generic;
using System.Linq; using
System.Web; using
System.Web.UI;
using System.Web.UI.WebControls;

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


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

}
protected void CustomValidator1_ServerValidate(object source, ServerValidateEventArgs args)
{
string str = args.Value;
args.IsValid = false;
if (str.Length < 7 || str.Length > 20)
{
return;
}
}
protected void Button1_Click(object sender, EventArgs e)
{
Response.Write("Submitted");
}}

Output

79 | P a g e
80 | P a g e
b) Create Web Form to demonstrate use of Adrotator Control. Design

Default.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

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


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

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>

<asp:AdRotator ID="AdRotator1" runat="server"


AdvertisementFile="~/XMLFile.xml" />

</div>
</form>
</body>
</html>
Default.aspx.cs
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

81 | P a g e
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>

<asp:AdRotator ID="AdRotator1" runat="server"


AdvertisementFile="~/XMLFile.xml" />

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

Create Web Form to demonstrate use User Controls. Design

82 | P a g e
Default.aspx

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>


<%@Register src="~/WebUserControl.ascx" TagName="WebUserControl" TagPrefix="uc1" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

83 | P a g e
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" />
<asp:TextBox ID="TextBox2" runat="server"
ontextchanged="TextBox2_TextChanged"></asp:TextBox></br>
<uc1:WebUserControl runat="server" id="WebUserControl1"/>
</div>
</form>
</body>
</html>
WebUserControl.ascx

<%@ Control Language="C#" AutoEventWireup="true" CodeFile="WebUserControl.ascx.cs"


Inherits="WebUserControl" %>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" />
<asp:TextBox ID="TextBox2" runat="server"
ontextchanged="TextBox2_TextChanged"></asp:TextBox>

Default.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq; using
System.Web; using
System.Web.UI;
using System.Web.UI.WebControls;

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


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

}
protected void Button1_Click(object sender, EventArgs e)

84 | P a g e
{
TextBox2.Text = "hello Guest: " + TextBox1.Text;
}
protected void TextBox2_TextChanged(object sender, EventArgs e)
{

}
}

WebUserControl.ascx.cs

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

public partial class WebUserControl : System.Web.UI.UserControl


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

}
protected void Button1_Click(object sender, EventArgs e)
{
TextBox2.Text = "Welcome " + TextBox1.Text;
}
protected void TextBox2_TextChanged(object sender, EventArgs e)
{

}
}
Output

85 | P a g e
Practical 5

Working with Navigation, Beautification and Master page.

a) Create Web Form to demonstrate use of Website Navigation controls and Site
Map.
Design

86 | P a g e
87 | P a g e
Default.aspx

Default.aspx

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

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


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

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>

<asp:SiteMapPath ID="SiteMapPath1" runat="server">


</asp:SiteMapPath>

</div>
<asp:Menu ID="Menu1" runat="server" DataSourceID="SiteMapDataSource1">
</asp:Menu>

88 | P a g e
<asp:SiteMapDataSource ID="SiteMapDataSource1" runat="server" />
</form>
</body>
</html>

========================================================

Default2.aspx

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %>

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


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

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>

<asp:SiteMapPath ID="SiteMapPath1" runat="server">


</asp:SiteMapPath>
<br/>Welcome to Online Store

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

=============================================================

Default3.aspx

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default3.aspx.cs" Inherits="Default3" %>

89 | P a g e
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>

<asp:SiteMapPath ID="SiteMapPath1" runat="server">


</asp:SiteMapPath>
</br>Hi welcome to online shopping :Mobiles

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

========================================================

Web.sitemap

<?xml version="1.0" encoding="utf-8" ?>


<siteMap xmlns="http://schemas.microsoft.com/AspNet/SiteMap-File-1.0" >
<siteMapNode url="Default.aspx" title="Home" description="" >
<siteMapNode url="Default2.aspx" title="Second" description="" />
<siteMapNode url="Default3.aspx" title="Third" description="" />
</siteMapNode>
</siteMap>

Output

90 | P a g e
b) Create a web application to demonstrate use of Master Page with applying
Styles and Themes for page beautification.
Design

91 | P a g e
92 | P a g e
93 | P a g e
Default.aspx
MasterPage.master

<%@ Master Language="C#" AutoEventWireup="true" CodeFile="MasterPage.master.cs"


Inherits="MasterPage" %>

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


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

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">Vodafone Mobile Store</p>
<title>Vodafone Mobile Store</title>
<asp:ContentPlaceHolder id="head" runat="server">
</asp:ContentPlaceHolder>
</head>
<body>
<link href="StyleSheet.css" rel="stylesheet" type="text/css" />
<form id="form1" runat="server">
<div>
<asp:ContentPlaceHolder id="ContentPlaceHolder1" runat="server">

94 | P a g e
</asp:ContentPlaceHolder>
</div>
</form>
</body>
</html>

Default.aspx

<%@ Page Title="" Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true"


CodeFile="Default.aspx.cs" Inherits="_Default" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">


</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<asp:Label ID="Label1" runat="server" Text="Select The Date"></asp:Label>
<asp:Calendar ID="Calendar1" runat="server"></asp:Calendar>
<asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl="~/Default2.aspx">Next</asp:HyperLink>
</asp:Content>

=============================================================

Default2.aspx

<%@ Page Title="" Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true"


CodeFile="Default2.aspx.cs" Inherits="Default2" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">


</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label> <br
/>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
</asp:Content>

================================================================

StyleSheet.css

95 | P a g e
body
{
background-color:Gray;
font:italic|Arial|12;
}

================================================

SkinFile.skin

<%--
Default skin template. The following skins are provided as examples only.

1. Named control skin. The SkinId should be uniquely defined


because
duplicate SkinId's per control type are not allowed in the same theme.

<asp:GridView runat="server" SkinId="gridviewSkin" BackColor="White" >


<AlternatingRowStyle BackColor="Blue" />
</asp:GridView>

2. Default skin. The SkinId is not defined. Only one default


control skin per control type is allowed in the same theme.

<asp:Image runat="server" ImageUrl="~/images/image1.jpg" />


--%>
<asp:Label runat="server" backcolor=blue/>

96 | P a g e
Output

c. Create a web application to demonstrate various states of ASP.NET Pages.


Design

97 | P a g e
Default.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs"
Inherits="_Default" %>

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


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

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>

<asp:HiddenField ID="HiddenField1" runat="server" Value="2" />

98 | P a g e
</div>
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
<br />
<asp:Label ID="Label2" runat="server" Text="Label"></asp:Label>
<br />
<asp:Button ID="Button1" runat="server" onclick="Button1_Click"
Text="View State" />
<br />
<br />
<asp:Button ID="Button2" runat="server" onclick="Button2_Click"
Text="Hidden Field" />
<br />
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<br />
<br />
<br />
<asp:Button ID="Button3" runat="server" onclick="Button3_Click"
Text="Cookies" />
</form>
</body> </html>

Default.aspx.cs using
System;
using System.Collections.Generic;
using System.Linq; using
System.Web; using System.Web.UI;
using System.Web.UI.WebControls;

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


{
protected void Page_Load(object sender, EventArgs e)
{
if (IsPostBack)
{
if (ViewState["count"] != null)
{
int ViewstateVal = Convert.ToInt32(ViewState["count"]) + 1;
Label2.Text = "View State :" + ViewstateVal.ToString();
ViewState["count"] = ViewstateVal.ToString();
}
else
{
ViewState["count"] = "1";
}
}
}

99 | P a g e
protected void Button1_Click(object sender, EventArgs e)
{
Label1.Text = ViewState["count"].ToString();
}
protected void Button2_Click(object sender, EventArgs e)
{
if (HiddenField1.Value != null)
{
int val = Convert.ToInt32(HiddenField1.Value) + 1;
HiddenField1.Value = val.ToString();
}
}
protected void Button3_Click(object sender, EventArgs e)
{
HttpCookie h = new HttpCookie("name");
h.Value = TextBox1.Text;
Response.Cookies.Add(h);
Response.Redirect("Default2.aspx");
}
}
Default2.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs"
Inherits="Default2" %>

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


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

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>

</div>
</form>
</body>
</html>
Default2.aspx.cs using
System;
using System.Collections.Generic;
using System.Linq; using
System.Web; using System.Web.UI;
using System.Web.UI.WebControls;

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

100 | P a g e
{
protected void Page_Load(object sender, EventArgs e)
{
if (Request.Cookies["name"] != null)
Response.Write("Welcome: "+Request.Cookies["name"].Value);
}
}

Output

101 | P a g e
Practical 6

Working with Database


a) Create a web application bind data in a multiline textbox by querying in
another textbox.
Design

Default.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs"
Inherits="_Default" %>

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


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

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>

102 | P a g e
<form id="form1" runat="server">
<div>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:TextBox ID="TextBox2" runat="server" TextMode="MultiLine"
Width="268px"></asp:TextBox>
<asp:Button ID="Button1" runat="server" Text="Button"
onclick="Button1_Click" />

</div>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"></asp:SqlDataSource>
</form>
</body>
</html>

Default.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;

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


{
SqlConnection cn = new SqlConnection("Data
Source=.\\SQLEXPRESS;AttachDbFilename=|DataDirectory|\\Database.mdf;Integrate
d Security=True;User Instance=True");
SqlCommand co= new SqlCommand();
SqlDataReader ds;
protected void Page_Load(object sender, EventArgs e)
{ cn.Open();
co.Connection=cn;
}
protected void Button1_Click(object sender, EventArgs e)
{
co.CommandText="select * from stdetail where city
='"+TextBox1.Text+"';";
ds=co.ExecuteReader();
while(ds.Read())
{

TextBox2.Text+=ds[0].ToString()+"\t"+ds[1].ToString()+"\t"+ds[2].ToString()+"
\n";
}
}
}

103 | P a g e
Output

b) Create a web application to display records by using database. Design

Default.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs"
Inherits="_Default" %>

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


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

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">

104 | P a g e
<div>

<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>


&nbsp;&nbsp;&nbsp;
<asp:Button ID="Button1" runat="server" onclick="Button1_Click"
Text="Button" />
&nbsp;&nbsp;&nbsp;
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>

</div>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
SelectCommand="SELECT * FROM [stdetail]"></asp:SqlDataSource>
</form>
</body>
</html>

Default.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;

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


{
SqlConnection cn = new SqlConnection("Data
Source=.\\SQLEXPRESS;AttachDbFilename=|DataDirectory|\\Database.mdf;Integrate
d Security=True;User Instance=True"); SqlCommand co = new SqlCommand();
SqlDataReader ds;
protected void Page_Load(object sender, EventArgs e)
{ cn.Open();
co.Connection = cn;
}
protected void Button1_Click(object sender, EventArgs e)
{
co.CommandText = "select name from stdetail where sno ='" +
TextBox1.Text + "';";
Label1.Text = co.ExecuteScalar().ToString();
}
}

Output

105 | P a g e
Demonstrate the use of Datalist link control
Drag and Drop Data list control, SQLDATASOURCE control.
Right click on the SQLDATASOURCE control.
Click on configure data source.
Choose your Data Connection.

106 | P a g e
Select the table to connect.

Test the query

107 | P a g e
Click on finish button Run the program.

108 | P a g e
Practical 7

Working with Database


a) Create a web application to display Databinding using dropdownlist control
Design

Default.aspx

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs"


Inherits="_Default" %>

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


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

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>

</div>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
&nbsp;&nbsp;&nbsp;

109 | P a g e
<asp:Button ID="Button1" runat="server" onclick="Button1_Click"
Text="Button" />
&nbsp;&nbsp;&nbsp;
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
&nbsp;&nbsp;&nbsp;
<asp:DropDownList ID="DropDownList1" runat="server"
onselectedindexchanged="DropDownList1_SelectedIndexChanged">
</asp:DropDownList>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
SelectCommand="SELECT * FROM [stdetail]"></asp:SqlDataSource>
</form>
</body>
</html>

Default.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;

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


{
SqlConnection cn = new SqlConnection("Data
Source=.\\SQLEXPRESS;AttachDbFilename=|DataDirectory|\\Database.mdf;Integrate
d Security=True;User Instance=True"); SqlCommand co = new SqlCommand();
SqlDataReader ds;
protected void Page_Load(object sender, EventArgs e)
{ cn.Open();
co.Connection = cn;
}
protected void Button1_Click(object sender, EventArgs e)
{
co.CommandText = "select * from stdetail;";
ds = co.ExecuteReader();
DropDownList1.DataSource = ds;
DropDownList1.DataTextField = "name";
DropDownList1.DataBind();
}
protected void DropDownList1_SelectedIndexChanged(object sender,
EventArgs e)
{
TextBox1.Text = DropDownList1.Text;
}
}

110 | P a g e
Output

111 | P a g e
b) Create a web application for to display the phone no of an author using
database
Design

Default.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs"
Inherits="_Default" %>

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


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

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>

<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>


&nbsp;&nbsp;&nbsp;
<asp:Button ID="Button1" runat="server" onclick="Button1_Click"
Text="Button" />
&nbsp;&nbsp;&nbsp;
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>

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

112 | P a g e
</html>

Default.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;

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


{
SqlConnection cn = new SqlConnection("Data
Source=.\\SQLEXPRESS;AttachDbFilename=|DataDirectory|\\Database.mdf;Integrate
d Security=True;User Instance=True"); SqlCommand co = new SqlCommand();
SqlDataReader ds;
protected void Page_Load(object sender, EventArgs e)
{ cn.Open();
co.Connection = cn;
}
protected void Button1_Click(object sender, EventArgs e)
{
co.CommandText = "select PhoneNo from bookdet where name='" +
TextBox1.Text + "';";
Label1.Text = co.ExecuteScalar().ToString();
}
}

Output

113 | P a g e
c)Create a web application for inserting and deleting record from a database.
(Using Execute-Non Query). Design

Default.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs"
Inherits="_Default" %>

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


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

114 | P a g e
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>

<asp:TextBox ID="TextBox1" runat="server"


Height="20px"></asp:TextBox>
<br />
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
<br />
<asp:TextBox ID="TextBox3" runat="server"></asp:TextBox>
<br />
<asp:TextBox ID="TextBox4" runat="server"></asp:TextBox>
<br />
<asp:Button ID="Button1" runat="server" onclick="Button1_Click"
Text="Insert" />
&nbsp;&nbsp;&nbsp;
<asp:Button ID="Button2" runat="server" onclick="Button2_Click"
Text="Delete" />
&nbsp;&nbsp;&nbsp;
<asp:Button ID="Button3" runat="server" onclick="Button3_Click"
Text="View" />
<br />
<asp:GridView ID="GridView1" runat="server"
AutoGenerateColumns="False"
DataSourceID="SqlDataSource1">
<Columns>
<asp:BoundField DataField="sno" HeaderText="sno"
SortExpression="sno" />
<asp:BoundField DataField="name" HeaderText="name"
SortExpression="name" />
<asp:BoundField DataField="class" HeaderText="class"
SortExpression="class" />
<asp:BoundField DataField="city" HeaderText="city"
SortExpression="city" />
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
SelectCommand="SELECT * FROM [stdetail]"></asp:SqlDataSource>

</div>
</form>

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

Default.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;

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


{
SqlConnection cn = new SqlConnection("Data
Source=.\\SQLEXPRESS;AttachDbFilename=|DataDirectory|\\Database.mdf;Integrate
d Security=True;User Instance=True"); SqlCommand co = new SqlCommand();
SqlDataReader ds;
SqlParameter @p1, @p2, @p3, @p4;
protected void Page_Load(object sender, EventArgs e)
{ cn.Open();
co.Connection = cn;
}
protected void Button1_Click(object sender, EventArgs e)
{
@p1 = new SqlParameter();
@p1.ParameterName = "sno";
@p1.SqlDbType = System.Data.SqlDbType.Int;
@p2 = new SqlParameter();
@p2.ParameterName = "name";
@p2.SqlDbType = System.Data.SqlDbType.VarChar;
@p3 = new SqlParameter();
@p3.ParameterName = "class";
@p3.SqlDbType = System.Data.SqlDbType.VarChar;
@p4 = new SqlParameter();
@p4.ParameterName = "city";
@p4.SqlDbType = System.Data.SqlDbType.VarChar;
co.Parameters.AddWithValue("@p1", TextBox1.Text);
co.Parameters.AddWithValue("@p2", TextBox2.Text);
co.Parameters.AddWithValue("@p3", TextBox3.Text);
co.Parameters.AddWithValue("@p4", TextBox4.Text);
co.CommandText = "insert into stdetail (sno,name,class,city)
values(@p1,@p2,@p3,@p4);"; co.ExecuteNonQuery();
}
protected void Button3_Click(object sender, EventArgs e)
{
co.CommandText = "select * from stdetail;";
ds = co.ExecuteReader();

116 | P a g e
GridView1.DataBind();
}
protected void Button2_Click(object sender, EventArgs e)
{
co.CommandText = "delete from stdetail where sno='" + TextBox1.Text +
"';";
co.ExecuteNonQuery();
}
}

Output

117 | P a g e

You might also like