You are on page 1of 66

PRACTICAL NO 1(a)

Aim: Write an application that obtains four int values from the user and displays
the product.

Code:

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

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


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

}
protected void btn_Product_Click(object sender, EventArgs e)
{
int a, b, c, d, p;
a = Convert.ToInt32(TextBox1.Text);
b = Convert.ToInt32(TextBox2.Text);
c = Convert.ToInt32(TextBox3.Text);
d = Convert.ToInt32(TextBox4.Text);
p = a * b * c * d;
TextBox5.Text = Convert.ToString(p);

}
}

Output:
PRACTICAL NO 1(b)

Aim: Create an application to demonstrate string operations

Code:

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

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


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

}
protected void Button1_Click(object sender, EventArgs e)
{
string str1;
str1 = TextBox1.Text;
string[] words = str1.Split(' ');
for(int i=0;i<words.Length;i++)
{
TextBox2.Text = TextBox2.Text + words[i]+"\r\n";
}

}
}

Output:
PRACTICAL NO: 01(C)
AIM: Write an application that receives the following information from a set of
students: (Student Id, Student Name, Course Name, Date of Birth). The application
should also display the information of all the students once the data is entered.
Code:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Sree1
{
class Program
{
struct Student
{
public string studid, name, cname;
public int day, month, year;
}
static void Main(string[] args)
{
Student[] s = new Student[5];
int i;
for (i = 0; i < 3; i++)
{
Console.Write("Enter Student Id:");
s[i].studid = Console.ReadLine();
Console.Write("Enter Student name : ");
s[i].name = Console.ReadLine();
Console.Write("Enter Course name : ");
s[i].cname = Console.ReadLine();
Console.Write("Enter date of birth\n Enter day(1-31):");
s[i].day = Convert.ToInt32(Console.ReadLine());
Console.Write("Enter month(1-12):");
s[i].month = Convert.ToInt32(Console.ReadLine());
Console.Write("Enter year:");
s[i].year = Convert.ToInt32(Console.ReadLine());
}
Console.WriteLine("\n\nStudent's List\n");
for (i = 0; i < 3; i++)
{
Console.WriteLine("\nStudent ID : " + s[i].studid);
Console.WriteLine("\nStudent name : " + s[i].name);
Console.WriteLine("\nCourse name : " + s[i].cname);
Console.WriteLine("\nDate of birth(dd-mm-yy) : " + s[i].day + "-" + s[i].month +
"-" + s[i].year);
}
Console.ReadLine();
}
}
}

Output:
PRACTICAL NO. : 01(D)
Aim: Create application to demonstrate the following operations
i) Fibonacci series

Code:

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

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


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

}
protected void Button1_Click(object sender, EventArgs e)
{
int f1 = 0, f2 = 1, f3, n, co;
n = int.Parse(TextBox1.Text);
co = 3;
Response.Write("Fibonaaci Series:");
Response.Write(f1 + "\t" + f2);
while (co <= n)
{
f3 = f1 + f2;
Response.Write("\t" + f3);
f1 = f2;
f2 = f3;
co++;
}

}
}

Output
PRACTICAL NO. : 01(D)
Aim: Create application to demonstrate the following operations
ii) Test for prime numbers

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

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


{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
int n, i, 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");

}
}
Output:
PRACTICAL NO. : 01(D)
Aim: Create application to demonstrate the following operations
iii) Test for vowels
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Vowels : 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++)
{

if((ch.Substring(i,1)=="a")||(ch.Substring(i,1)=="e")||(ch.Substring(i,1)=="i")||(ch.Subst
ring(i,1)=="o")||(ch.Substring(i,1)=="u"))
{
count++;
}
}
Response.Write("Given String:"+ch);
Response.Write("Total Number of Vowels:"+count);
}
}

Output:
PRACTICAL NO. : 01(D)
Aim: Create application to demonstrate the following operations
iv) using foreach loop with arrays
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Foreach : 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);
}
}

Output:
PRACTICAL NO. : 01(D)
Aim: Create application to demonstrate the following operations
v) Reverse a number and find the sum of digits of the number

Code:

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

public partial class Reverse : 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);
}
}

Output:
PRACTICAL NO: 2 (a)

Aim: Create simple application to demonstrate function overloading

Code:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace functionoverloading
{
class Shape
{
public void Area(int side)
{
int squarearea = side * side;
Console.WriteLine("The Area of Square is :" + squarearea);
}
public void Area(int length, int breadth)
{

int rectarea = length * breadth;


Console.WriteLine("The Area of Rectangle is :" + rectarea);

public void Area(double radius)


{
double circlearea = 3.14 * radius * radius;
Console.WriteLine("The Area of Circle is :" + circlearea);
}
}
class Program
{

static void Main(string[] args)


{
Shape s = new Shape();
s.Area(10);
s.Area(10, 20);
s.Area(10.8);
Console.ReadKey();
}
}
}

Output:
PRACTICAL NO: 2(b)

Aim: Create simple application to demonstrate inheritance

Single Inheritance

Code:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication20
{
class Program
{
static void Main(string[] args)
{
Teacher d = new Teacher();

d.Teach();

Student s = new Student();

s.Learn();

s.Teach();

Console.ReadKey();
}
class Teacher
{

public void Teach()


{
Console.WriteLine("Teach");

}
}

class Student : Teacher


{
public void Learn()
{

Console.WriteLine("Learn");
}

}
}
}
Output:
PRACTICAL NO: 2(c)

Aim: Create simple application to demonstrate inheritance

Hierarchial Inheritance

Code:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication20
{
class Program
{
static void Main(string[] args)
{
Principal g = new Principal();

g.Monitor();

Teacher d = new Teacher();

d.Monitor();

d.Teach();

Student s = new Student();

s.Monitor();

s.Learn();

Console.ReadKey();
}
class Principal
{

public void Monitor()


{

Console.WriteLine("Monitor");

class Teacher : Principal


{

public void Teach()


{

Console.WriteLine("Teach");

}
class Student : Principal
{

public void Learn()


{

Console.WriteLine("Learn");

}
}
}

Output:
PRACTICAL NO: 2(d)

Aim: Create simple application to demonstrate inheritance

Multilevel Inheritance

Code:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication20
{
class inheri : vehicle

public void Noise()

Console.WriteLine("All Vehicles Creates Noise !! ");

static void Main(string[] args)


{
inheri obj = new inheri();

obj.mode();

obj.feature();

obj.Noise();

Console.Read();
}
}
class Mode

public void mode()

Console.WriteLine("There are Many Modes of Transport !!");

class vehicle : Mode

public void feature()


{

Console.WriteLine("They Mainly Help in Travelling !!");

Output:
PRACTICAL NO: 2(e)

Aim: Create simple application to demonstrate constructor overloading.

Code:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication20
{
class GameScore
{
string user;
int age;
//Default Constructor
public GameScore()
{
user = "Steven";
age = 28;
Console.WriteLine("Previous User {0} and he was {1} year old", user, age);
}

//Parameterized Constructor
public GameScore(string name, int age1)
{
user = name;
age = age1;
Console.WriteLine("Current User {0} and he is {1} year old", user, age);
}
}

class Program
{
static void Main(string[] args)
{
GameScore gs = new GameScore(); //Default Constructor Called
GameScore gs1 = new GameScore("Clark", 35); //Overloaded Constructor.
Console.ReadLine();
}
}

Output:
PRACTICAL NO: 2(f)

Aim: Create simple application to demonstrate the use of interfaces.

Code:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication20
{
public interface ITransactions
{

void showTransaction();

double getamnt();

public class Transaction : ITransactions


{

private string Code;

private string date;

private double amnt;

public Transaction()
{

Code = " ";

date = " ";

amnt = 0.0;

public Transaction(string c, string d, double a)


{

Code = c;

date = d;

amnt = a;

public double getamnt()


{

return amnt;

}
public void showTransaction()
{

Console.WriteLine("Transaction: {0}", Code);

Console.WriteLine("Date: {0}", date);

Console.WriteLine("amnt: {0}", getamnt());

class example
{

static void Main(string[] args)


{

Transaction t1 = new Transaction("001", "24/06/2014", 87900.00);

Transaction t2 = new Transaction("002", "25/06/2014", 51900.00);

t1.showTransaction();

t2.showTransaction();

Console.ReadKey();

Output:
PRACTICAL NO: 2(g)

Aim: Create simple application to demonstrate the use of delegates and events.

Delegates

Code:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication20
{
public class TestDelegate
{
//Declaration
//Creating Delegates with no parameters and no return type.
public delegate void FirstDelegate();

public void fun1()


{
Console.WriteLine("I am Function 1");
}
public void fun2()
{
Console.WriteLine("I am Function 2");
}
public void fun3()
{
Console.WriteLine("I am Function 3");
}
}

class Program
{
static void Main(string[] args)
{
TestDelegate testdelegate = new TestDelegate();
//Instantiation
TestDelegate.FirstDelegate fd1 = new TestDelegate.FirstDelegate(testdelegate.fun1);
TestDelegate.FirstDelegate fd2 = new TestDelegate.FirstDelegate(testdelegate.fun2);
TestDelegate.FirstDelegate fd3 = new TestDelegate.FirstDelegate(testdelegate.fun3);

//Invocation
fd1();
fd2();
fd3();

Console.ReadKey();
}
}
}

Output:
PRACTICAL NO: 2(h)

Aim: Create simple application to demonstrate the use of delegates and events.

Events

Code:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication20
{
class Program
{
static void Main(string[] args)
{
AddTwoNumbers a = new AddTwoNumbers();
//Event gets binded with delegates
a.ev_OddNumber += new AddTwoNumbers.dg_OddNumber(EventMessage);
a.Add();
Console.Read();
}
//Delegates calls this method when event raised.
static void EventMessage()
{
Console.WriteLine("********Event Executed : This is Odd Number**********");
}
}
//This is Publisher Class
class AddTwoNumbers
{
public delegate void dg_OddNumber(); //Declared Delegate
public event dg_OddNumber ev_OddNumber; //Declared Events

public void Add()


{
int result;
result = 5 + 4;
Console.WriteLine(result.ToString());
//Check if result is odd number then raise event
if ((result % 2 != 0) && (ev_OddNumber != null))
{
ev_OddNumber(); //Raised Event
}
}
}
}

Output:
PRACTICAL NO: 2(i)

Aim: Create simple application to demonstrate the use of exception handling.

Code:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication20
{
class ExceptionTest
{
static double SafeDivision(double x, double y)
{
if (y == 0)
throw new System.DivideByZeroException();
return x / y;
}
static void Main()
{
// Input for test purposes. Change the values to see
// exception handling behavior.
double a = 98, b = 0;
double result = 0;

try
{
result = SafeDivision(a, b);
Console.WriteLine("{0} divided by {1} = {2}", a, b, result);
}
catch (DivideByZeroException e)
{
Console.WriteLine("Attempted divide by zero.");
}
Console.ReadLine();
}

}
Output:
PRACTICAL NO: 3 (A)
Aim: Create a simple web page with various server control to demonstrate setting and use of
their properties.

Code:

Server.aspx

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


Inherits="Server" %>

<!DOCTYPE html>

<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="Roll No"></asp:Label>


&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<asp:TextBox ID="txtRollno" runat="server"></asp:TextBox>
<br />
<br />
<asp:Label ID="Label2" runat="server" Text="Name"></asp:Label>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<asp:TextBox ID="txtName" runat="server"></asp:TextBox>
<br />
<br />
<asp:Label ID="Label3" runat="server" Text="Class"></asp:Label>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<asp:RadioButton ID="rdbfy" runat="server" GroupName="Groupclass" Text="FY" />
&nbsp;&nbsp;&nbsp;
<asp:RadioButton ID="rdbsy" runat="server" GroupName="Groupclass" Text="SY" />
&nbsp;&nbsp;&nbsp;&nbsp;
<asp:RadioButton ID="rdbty" runat="server" GroupName="Groupclass" Text="TY" />
<br />
<br />
<asp:Label ID="Label4" runat="server" Text="Course"></asp:Label>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True"
Height="29px" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged"
Width="126px">
<asp:ListItem>B.SC(IT)</asp:ListItem>
<asp:ListItem>B.Com</asp:ListItem>
<asp:ListItem>B.SC(CS)</asp:ListItem>
<asp:ListItem>BMS</asp:ListItem>
<asp:ListItem>BA</asp:ListItem>
</asp:DropDownList>
<br />
<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs
p;
<asp:Button ID="btnSubmit" runat="server" OnClick="btnSubmit_Click"
Text="Submit" />
<br />
<br />
<asp:Label ID="Label5" runat="server" Text="Label"></asp:Label>
<br />

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

Server.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 Server : System.Web.UI.Page


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

}
protected void btnSubmit_Click(object sender, EventArgs e)
{
string s;
if (rdbfy.Checked == true)
{
s = rdbfy.Text;
}
else if (rdbsy.Checked == true)
{

s = rdbsy.Text;
}
else
{
s = rdbty.Text;
Label5.Text += ("in "+s);
}

Label5.Text = "You have been enrolled in " + s + DropDownList1.SelectedItem;


}

protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)


{

}
}

Output:
PRACTICAL NO: 3 (B)
Aim: Demonstrate the use of Calendar Control to perform the following operations.

i) Display messages in a calendar control

Code:

Calendar.aspx

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


Inherits="Calendar" %>

<!DOCTYPE html>

<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" 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="#CCFFCC" />
<NextPrevStyle Font-Bold="True" Font-Size="8pt" ForeColor="White" />
<OtherMonthDayStyle ForeColor="#999999" />
<SelectedDayStyle BackColor="#00CC00" ForeColor="White" />
<TitleStyle BackColor="#333399" BorderStyle="Solid" Font-Bold="True" Font-
Size="12pt" ForeColor="White" Height="12pt" />
<TodayDayStyle BackColor="#99CCFF" ForeColor="White" />
</asp:Calendar>

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

Calendar.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 Calendar : 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.Day == 15)
e.Cell.Controls.Add(new LiteralControl("<br/> Holiday"));
}
}

Output:
PRACTICAL NO: 3 (B)
Aim: Demonstrate the use of Calendar Control to perform the following operations.

ii) Display vacation in calendar

Code:

Vacation.aspx

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


Inherits="vacation" %>

<!DOCTYPE html>

<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" 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>
<br />
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
<br />
<br />
<asp:Label ID="Label2" runat="server" Text="Label"></asp:Label>
<br />
<br />
<asp:Label ID="Label3" runat="server" Text="Label"></asp:Label>
<br />
<br />
<asp:Label ID="Label4" runat="server" Text="Label"></asp:Label>
<br />
<br />
<asp:Label ID="Label5" runat="server" Text="Label"></asp:Label>
<br />
<br />
<br />
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Result" />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs
p;
<asp:Button ID="Button2" runat="server" OnClick="Button2_Click" Text="Reset" />

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

Vacation.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 vacation : System.Web.UI.Page


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

}
protected void Calendar1_DayRender(object sender, DayRenderEventArgs e)
{
if (e.Day.Date.Day == 5 && e.Day.Date.Month == 9)
{
e.Cell.BackColor = System.Drawing.Color.Yellow;
Label lbl = new Label();
lbl.Text = "<br>Teachers Day!";
e.Cell.Controls.Add(lbl);
Image g1 = new Image();
g1.ImageUrl = "td.jpg";
g1.Height = 20;
g1.Width = 20;
e.Cell.Controls.Add(g1);
}
if (e.Day.Date.Day == 13 && e.Day.Date.Month == 9)
{
Calendar1.SelectedDate = new DateTime(2018, 9, 12);
Calendar1.SelectedDates.SelectRange(Calendar1.SelectedDate,
Calendar1.SelectedDate.AddDays(10));
Label lbl1 = new Label();
lbl1.Text = "<br>Ganpati!";
e.Cell.Controls.Add(lbl1);
}
}
protected void Button1_Click(object sender, EventArgs e)
{
Calendar1.Caption = "SAMBARE";
Calendar1.FirstDayOfWeek = FirstDayOfWeek.Sunday;
Calendar1.NextPrevFormat = NextPrevFormat.ShortMonth;
Calendar1.TitleFormat = TitleFormat.Month;
Label2.Text = "Todays Date"+Calendar1.TodaysDate.ToShortDateString();
Label3.Text = "Ganpati Vacation Start: 9-13-2018";
TimeSpan d = new DateTime(2018, 9, 13) - DateTime.Now;
Label4.Text = "Days Remaining For Ganpati Vacation:"+d.Days.ToString();
TimeSpan d1 = new DateTime(2018, 12, 31) - DateTime.Now;
Label5.Text = "Days Remaining for New Year:"+d1.Days.ToString();
if (Calendar1.SelectedDate.ToShortDateString() == "9-13-2018")
Label3.Text = "<b>Ganpati Festival Start</b>";
if (Calendar1.SelectedDate.ToShortDateString() == "9-23-2018")
Label3.Text = "<b>Ganpati Festival End</b>";
}
protected void Button2_Click(object sender, EventArgs e)
{
Label1.Text = "";
Label2.Text = "";
Label3.Text = "";
Label4.Text = "";
Label5.Text = "";
Calendar1.SelectedDates.Clear();
}
protected void Calendar1_SelectionChanged(object sender, EventArgs e)
{
Label1.Text = "Your Selected Date:" + Calendar1.SelectedDate.Date.ToString();
}
}
Output:
PRACTICAL NO: 3 (B)
Aim: Demonstrate the use of Calendar Control to perform the following operations.

iii) Selected day in a calendar control using style

Code:

Selectedday.aspx

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


Inherits="Selectedday" %>

<!DOCTYPE html>

<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" BackColor="White"


BorderColor="Black" BorderStyle="Solid" CellSpacing="1" Font-Names="Verdana" Font-
Size="9pt" ForeColor="Black" Height="250px" NextPrevFormat="ShortMonth"
OnDayRender="Calendar1_DayRender" 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>

Selectedday.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 Selectedday : System.Web.UI.Page


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

}
protected void Calendar1_DayRender(object sender, DayRenderEventArgs e)
{
if (e.Day.Date >= new DateTime(2018, 9, 9) && e.Day.Date <= new DateTime(2018, 9,
18))
{
e.Cell.BackColor = System.Drawing.Color.Aquamarine;
e.Cell.BorderColor = System.Drawing.Color.Black;
e.Cell.BorderWidth = new Unit(3);
}
if (e.Day.IsOtherMonth)
{
e.Cell.Controls.Clear();
}
}
}

Output:
PRACTICAL NO: 3 (B)
Aim: Demonstrate the use of Calendar Control to perform the following operations.

iv) Difference between two calendar dates

Code:

Datesdiff.aspx

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


Inherits="Datesdiff" %>

<!DOCTYPE html>

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


OnDayRender="Calendar1_DayRender"></asp:Calendar>
<br />
&nbsp;&nbsp;
<asp:Calendar ID="Calendar2" runat="server"></asp:Calendar>
<br />
<asp:Label ID="Label1" runat="server" Text="No of days is :"></asp:Label>
&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;
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" />

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

Datesdiff.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 Datesdiff : System.Web.UI.Page


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

}
protected void Calendar1_DayRender(object sender, DayRenderEventArgs e)
{
if (e.Day.Date >= new DateTime(2018,11,23) && (e.Day.Date <= new
DateTime(2018,11,30)))
{
e.Cell.BackColor = System.Drawing.Color.BlueViolet;
e.Cell.BorderColor = System.Drawing.Color.Black;
e.Cell.BorderWidth = new Unit(3);
}
}
protected void Button1_Click(object sender, EventArgs e)
{
TimeSpan t = Calendar2.SelectedDate - Calendar1.SelectedDate;
Label1.Text = t.Days.ToString();
}
}

Output:
PRACTICAL NO 3(c)

Aim: Demonstrate the use of Tree view control to perform the following
operations.

Tree view control and Data List

Code:

Stdetail.xml

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


<studentdetail>
<student>
<sid>1</sid>
<sname>Tushar</sname>
<sclass>TYIT</sclass>
</student>
<student>
<sid>2</sid>
<sname>Sonali</sname>
<sclass>TYCS</sclass>
</student>
<student>
<sid>3</sid>
<sname>Yashashree</sname>
<sclass>TYIT</sclass>
</student>
<student>
<sid>4</sid>
<sname>Vedshree</sname>
<sclass>TYCS</sclass>
</student>
</studentdetail>

Navigation.aspx

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


Inherits="Navigation" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:TreeView ID="TreeView1" runat="server" ImageSet="Arrows">
<HoverNodeStyle Font-Underline="True" ForeColor="Maroon" />
<Nodes>
<asp:TreeNode Text="File" Value="File">
<asp:TreeNode Text="Date" Value="Date">
<asp:TreeNode NavigateUrl="~/Calander.aspx" Text="Calander"
Value="Calander"></asp:TreeNode>
</asp:TreeNode>
<asp:TreeNode Text="PageTwo" Value="PageTwo">
<asp:TreeNode NavigateUrl="~/Welcome.aspx" Text="Welcome"
Value="Welcome"></asp:TreeNode>
</asp:TreeNode>
</asp:TreeNode>
</Nodes>
</asp:TreeView>
<br />
Fetch Datalist Using XML data :
<asp:DataList ID="DataList1" runat="server">
<ItemTemplate>
<table class = "table" border="1">
<tr>
<td>Roll Num : <%# Eval("sid") %><br />
Name : <%# Eval("sname") %><br />
Class : <%# Eval("sclass")%>
</td>
</tr>
</table>
</ItemTemplate>
</asp:DataList>

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

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

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


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

protected void BindData()


{
DataSet ds = new DataSet();
ds.ReadXml(Server.MapPath("stdetail.xml"));
if (ds != null && ds.HasChanges())
{
DataList1.DataSource = ds;
DataList1.DataBind();
}
else
{
DataList1.DataBind();
}
}
}

Output:
PRACTICAL NO 3(c)

Aim: Demonstrate the use of Tree view control to perform the following
operations.

ii) Tree view operations

Code:

Navigation.aspx

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


Inherits="Navigationop" %>

<!DOCTYPE html>

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

<asp:TreeView ID="TreeView1" runat="server"


OnSelectedNodeChanged="TreeView1_SelectedNodeChanged"
OnTreeNodeExpanded="TreeView1_TreeNodeExpanded">
<Nodes>
<asp:TreeNode ShowCheckBox="True" Text="Course" Value="Course">
<asp:TreeNode 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 ShowCheckBox="True" Text="B.Com" Value="B.Com">
<asp:TreeNode Text="FY" Value="FY"></asp:TreeNode>
<asp:TreeNode Text="SY" Value="SY"></asp:TreeNode>
</asp:TreeNode>
</asp:TreeNode>
</Nodes>
</asp:TreeView>

</div>
</form>
</body>
</html>
Navigation.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 Navigationop : 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_TreeNodeExpanded(object sender, TreeNodeEventArgs e)


{
Response.Write("The value collapsed was:" + e.Node.Value);
}
}

Output
Practical No : 4(a)

Aim: Create a registration form to demonstrate use of various validation controls.

Code:

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

<!DOCTYPE html>

<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="Enter Name"></asp:Label>


&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<asp:TextBox ID="txtName" runat="server" CausesValidation="True"></asp:TextBox>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="txtName"
ErrorMessage="Name should not be left blank..." ForeColor="Red"></asp:RequiredFieldValidator>
<br />
<br />
<asp:Label ID="Label2" runat="server" Text="Enter Age"></asp:Label>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb
sp;&nbsp;&nbsp;
<asp:TextBox ID="txtAge" runat="server"></asp:TextBox>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<asp:RangeValidator ID="RangeValidator1" runat="server" ControlToValidate="txtAge"
ErrorMessage="Age should be between 20 to 30" ForeColor="Red" MaximumValue="30"
MinimumValue="20"></asp:RangeValidator>
<br />
<br />
<asp:Label ID="Label3" runat="server" Text="Enter Email"></asp:Label>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb
sp;
<asp:TextBox ID="txtEmail" runat="server"></asp:TextBox>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server"
ControlToValidate="txtEmail" ErrorMessage="Enter email in proper fornat" ForeColor="Red"
ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"></asp:RegularExpressionValidator>
<br />
<br />
<asp:Label ID="Label4" runat="server" Text="Enter Password"></asp:Label>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<asp:TextBox ID="txtPass" runat="server"></asp:TextBox>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ControlToValidate="txtPass"
ErrorMessage="Please enter the password..." ForeColor="Red"></asp:RequiredFieldValidator>
<br />
<br />
<asp:Label ID="Label5" runat="server" Text="Re-enter Password"></asp:Label>
&nbsp;&nbsp;&nbsp;
<asp:TextBox ID="txtRepass" runat="server"></asp:TextBox>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<asp:CompareValidator ID="CompareValidator1" runat="server" ControlToCompare="txtPass"
ControlToValidate="txtRepass" ErrorMessage="Please reenter the password"
ForeColor="Red"></asp:CompareValidator>
<br />
<br />
<br />
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" />

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

Output:
Practical No : 4(b)

Aim: Create Web form to demonstrate the use of Adrotator Control.

Code:

adds.xml

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


<Advertisements>
<Ad>
<ImageUrl>ganesh.jpg</ImageUrl>
<NavigateUrl>http://www.1800flowers.com</NavigateUrl>
<AlternateText>
Order flowers, roses, gifts and more
</AlternateText>
<Impressions>20</Impressions>
<Keyword>flowers</Keyword>
</Ad>
<Ad>
<ImageUrl>butter-fly.jpg</ImageUrl>
<NavigateUrl>http://www.babybouquets.com.au</NavigateUrl>
<AlternateText>Order roses and flowers</AlternateText>
<Impressions>20</Impressions>
<Keyword>gifts</Keyword>
</Ad>
<Ad>
<ImageUrl>good-morning.jpg</ImageUrl>
<NavigateUrl>http://www.flowers2moscow.com</NavigateUrl>
<AlternateText>Send flowers to Russia</AlternateText>
<Impressions>20</Impressions>
<Keyword>russia</Keyword>
</Ad>
</Advertisements>

Addrotator.aspx

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

<!DOCTYPE html>

<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" Height="300" Width="200"


AdvertisementFile="~/adds.xml" />

</div>
</form>
</body>
</html>
Output:
PRACTICAL NO : 4(C)

Aim: Create Web form to demonstrate use of User Controls.

Code:

MyUserControl.ascx
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="MyUserControl.ascx.cs"
Inherits="MyUserControl" %>
<h3>This is User Contro1 </h3>
<table>
<tr>
<td>Name</td>
<td>
<asp:TextBox ID="txtName" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td>City</td>
<td><asp:TextBox ID="txtcity" runat="server"></asp:TextBox></td>
</tr>
<tr>
<td></td>
<td>
</td>
</tr>
<tr>
<td></td>
<td>
<asp:Button ID="txtSave" runat="server" Text="Save" onclick="txtSave_Click" />
</td>
</tr>
</table>
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
<br />

MyUserControl.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 MyUserControl : System.Web.UI.UserControl


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

}
protected void txtSave_Click(object sender, EventArgs e)
{
Label1.Text = "Your Name is " + txtName.Text + " and you are from " +txtcity.Text;
}
}
WebC.aspx

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


<%@ Register Src="~/MyUserControl.ascx" TagPrefix="uc" TagName="Student"%>
<!DOCTYPE html>

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

Output:
PRACTICAL NO: 5(a)

Aim: Create web form to demonstrate use of website navigation controls and
sitemap

Code:

Home.aspx

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


Inherits="Home" %>

<!DOCTYPE html>

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

<asp:Menu ID="Menu1" runat="server" Orientation="Horizontal"


DataSourceID="SiteMapDataSource1">
<Items>
<asp:MenuItem Text="Home" Value="Home">
<asp:MenuItem NavigateUrl="~/Second.aspx" Text="Second"
Value="Second"></asp:MenuItem>
<asp:MenuItem NavigateUrl="~/Third.aspx" Text="Third"
Value="Third"></asp:MenuItem>
</asp:MenuItem>
</Items>
</asp:Menu>

<asp:SiteMapDataSource ID="SiteMapDataSource1" runat="server" />

</div>

</form>
</body>

Second.aspx

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


Inherits="Second" %>

<!DOCTYPE html>
<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"
EnableTheming="false"></asp:SiteMapPath>
<br /> Welcome to online store
</div>
</form>
</body>
</html>

Third.aspx

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


Inherits="Third" %>

<!DOCTYPE html>

<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"
EnableTheming="false"></asp:SiteMapPath>
<br /> Hello welcome to the mobile shopping page...
</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="Home.aspx" title="Home" description="">
<siteMapNode url="Second.aspx" title="Second" description="" />
<siteMapNode url="Third.aspx" title="Third" description="" />
</siteMapNode>
</siteMap>

Output:
Practical 5(b)

Aim: Create a web application to demonstrate use of Master Page with applying
Styles and Themes for page beautification.

Code:

Masterpage.master
<!DOCTYPE html>

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

<p>
&nbsp;
</p>
<p>
&nbsp;
</p>
<p>
&nbsp;
</p>
</asp:ContentPlaceHolder>
</div>
</form>
</body>
</html>

Page2.aspx
<%@ Page Title="" Language="C#" MasterPageFile="~/MasterPage.master"
AutoEventWireup="true" CodeFile="Page2.aspx.cs" Inherits="Page2"
Theme="Theme" %>

<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="~/Page2.aspx">Next</asp:HyperLink>
</asp:Content>

Page3.aspx
<%@ Page Title="" Language="C#" MasterPageFile="~/MasterPage.master"
AutoEventWireup="true" CodeFile="Page3.aspx.cs" Inherits="Page3" %>

<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>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
</asp:Content>

Stylesheet.css
body {
background-color:blueviolet;
font:italic;
font-family: Cambria;
}

Theme.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 = orange/>

Output:
PRACTICAL 6 (a)
Aim: Create a web application to bind data in a multiline textbox by querying in
another textbox.
Code:
1. Create a webpage with one Button, one Multiline TextBox and one list box with
setting TextMode Property of text box to Multiline
2. Write the Database related code in code behind C# file
Web.confing
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.5.2" />
<httpRuntime targetFramework="4.5.2" />
</system.web>
<connectionStrings>
<add name="connStr" connectionString="Data
Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename='C:\Users\tushars\Documents\Visual
Studio2015\WebSites\Workshop\App_Data\Database.mdf';Integrated Security=True" />
</connectionStrings>
</configuration>

3. use the following code C# in 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;
using System.Data.SqlClient;
using System.Configuration;
public partial class DataBinding : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
string connStr =
ConfigurationManager.ConnectionStrings["connStr"].ConnectionString;
SqlConnection con = new SqlConnection(connStr);
con.Open();
SqlCommand cmd = new SqlCommand(TextBox1.Text, con);
SqlDataReader reader = cmd.ExecuteReader();
ListBox1.Items.Clear();
while (reader.Read())
{
//To add new blank line in the text area
for (int i = 0; i < reader.FieldCount ‐ 1; i++)
{
ListBox1.Items.Add(reader[i].ToString());
}
}
reader.Close();
con.Close();
}
}
Output:
PRACTICAL NO 6 (b)
Aim: Create a web application to display records by using database.

Code:

Default.aspx.cs

protected void Button1_Click(object sender, EventArgs e)


{
string connStr =
ConfigurationManager.ConnectionStrings["connStr"].ConnectionString;
SqlConnection con = new SqlConnection(connStr);
SqlCommand cmd = new SqlCommand("Select City, State from Customer", con);
con.Open();
SqlDataReader reader = cmd.ExecuteReader();
while (reader.Read())
{
Label1.Text += reader["City"].ToString() + " " + reader["State"].ToString() +
"<br>";
}
reader.Close();
con.Close();
}

Output:
PRACTICAL NO 7(a)
Aim: Create Web application to display data binding using dropdown list control.

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 Link : System.Web.UI.Page


{
SqlConnection cn = new SqlConnection("Data Source=PHCASC-PC;Initial
Catalog=college;Integrated Security=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";
ds = co.ExecuteReader();
DropDownList1.DataSource = ds;
DropDownList1.DataTextField = "name";
DropDownList1.DataBind();
}
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
TextBox1.Text = DropDownList1.Text;
}
}

Output
PRACTICAL NO 7(b)

Aim: Create a web application to display the phone number of an author using
database

Code:

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=PHCASC-PC;Initial
Catalog=college;Integrated Security=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();
}
protected void SqlDataSource1_Selecting(object sender,
SqlDataSourceSelectingEventArgs e)
{

}
}
Output:
PRACTICAL NO 8

Aim: Create a web application to demonstrate data binding using Details view

Code:

Details View

<%@ 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:DetailsView ID="DetailsView1" runat="server" AllowPaging="True"


AutoGenerateRows="False" DataSourceID="SqlDataSource1" Height="50px"
Width="125px">
<Fields>
<asp:BoundField DataField="name" HeaderText="name" SortExpression="name" />
<asp:BoundField DataField="phoneno" HeaderText="phoneno"
SortExpression="phoneno" />
</Fields>
</asp:DetailsView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:collegeConnectionString %>"
SelectCommand="SELECT * FROM [bookdet]"></asp:SqlDataSource>

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

Output
PRACTICAL NO 9

Aim: Create a web application to demonstrate data binding using Form view

Code:

Form View

<%@ 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:FormView ID="FormView1" runat="server" AllowPaging="True"


DataSourceID="SqlDataSource1">
<EditItemTemplate>
name:
<asp:TextBox ID="nameTextBox" runat="server" Text='<%# Bind("name") %>' />
<br />
phoneno:
<asp:TextBox ID="phonenoTextBox" runat="server" Text='<%# Bind("phoneno") %>' />
<br />
<asp:LinkButton ID="UpdateButton" runat="server" CausesValidation="True"
CommandName="Update" Text="Update" />
&nbsp;<asp:LinkButton ID="UpdateCancelButton" runat="server"
CausesValidation="False" CommandName="Cancel" Text="Cancel" />
</EditItemTemplate>
<InsertItemTemplate>
name:
<asp:TextBox ID="nameTextBox" runat="server" Text='<%# Bind("name") %>' />
<br />
phoneno:
<asp:TextBox ID="phonenoTextBox" runat="server" Text='<%# Bind("phoneno") %>' />
<br />
<asp:LinkButton ID="InsertButton" runat="server" CausesValidation="True"
CommandName="Insert" Text="Insert" />
&nbsp;<asp:LinkButton ID="InsertCancelButton" runat="server"
CausesValidation="False" CommandName="Cancel" Text="Cancel" />
</InsertItemTemplate>
<ItemTemplate>
name:
<asp:Label ID="nameLabel" runat="server" Text='<%# Bind("name") %>' />
<br />
phoneno:
<asp:Label ID="phonenoLabel" runat="server" Text='<%# Bind("phoneno") %>' />
<br />

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

Output
PRACTICAL NO 10 (A)

Aim: Create a web application to demonstrate reading and writing operation with xml.

Code:

XmlFile2.xml

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


<student>
<name> Amit</name>
<rollno> 01</rollno>
</student>

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

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


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

}
protected void Button1_Click(object sender, EventArgs e)
{
XmlReader read = XmlReader.Create(@"D:\Database example2\XMLFile2.xml");
while (read.Read())
{
if (read.NodeType.Equals(XmlNodeType.Element))
{
string s = Label1.Text + " ";
Label1.Text = s + read.Name;
}
}
read.Close();
}
protected void Button2_Click(object sender, EventArgs e)
{
XmlWriterSettings set = new XmlWriterSettings();
set.Indent = true;
XmlWriter wr = XmlWriter.Create(@"D:\Database example2\XMLFile.xml",set);
wr.WriteStartDocument();
wr.WriteComment("example of write to xml document");
wr.WriteStartElement("student");
wr.WriteEndElement();
}
}

Output:
PRACTICAL NO 10(c)

Aim: Create a web application to demonstrate the use of various AJAX controls.

Code:

Default.aspx

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


Inherits="_Default" %>

<!DOCTYPE html>

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

<asp:ScriptManager ID="ScriptManager1" runat="server">


</asp:ScriptManager>
<br />
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="SHOW
TIME" />
<asp:TextBox ID="TextBox1" runat="server" Width="200px"></asp:TextBox>
<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<br />
<asp:UpdateProgress ID="UpdateProgress1" runat="server">
<ProgressTemplate>
PLEASE WAIT FOR SOMETIME .....
</ProgressTemplate>
</asp:UpdateProgress>

</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)
{
System.Threading.Thread.Sleep(2000);
}
protected void Button1_Click(object sender, EventArgs e)
{
TextBox1.Text = DateTime.Now.ToLongTimeString();
}
}

Output:
Practical No: 11

Aim: Create a program using dll

Library file

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ClassLibrary1
{
public class Class1
{
public int add(int a, int b)
{
int c = a + b;
return c;
}
}
}

Console

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ClassLibrary1;

namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
ClassLibrary1.Class1 c = new Class1();
int t = c.add(1, 2);
Console.WriteLine("addition ={0}", t);
Console.ReadKey();
}
}
}

Output:

You might also like