Nothing Special   »   [go: up one dir, main page]

6417 - Sudesh Rajbhar - AWP

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 140

RAMNIRANJAN JHUNJHUNWALA COLLEGE GHATKOPAR (W),

MUMBAI - 400 086

DEPARTMENT OF INFORMATION TECHNOLOGY

2023 - 2024

t.Y. B. Sc.( I.T.) SEM v

Paper rjsuit503– advanced web programming

Name Rajbhar Sudesh Dinesh

Roll No. 6417


Hindi Vidya Prachar Samiti’s
RAMNIRANJAN JHUNJHUNWALA
COLLEGE
Ghatkopar (W), Mumbai-400 086

Certificate

This is to certify that Mr./Ms.Rajbhar Sudesh Dinesh ,Roll No 6417


of T.Y.B.Sc.(I.T.) class has completed the required number of experiments in
the subject of Advanced Web Programming in the Department of
Information Technology during the academic year 20 23- 20 24 .

Professor In-Charge Co-ordinator of IT Department

Prof. Bharati Bhole


Prof. Archana Bhide

College Seal & Date Examiner


Index
Practical Details Date
No

1 Working with basic C# and ASP.NET

a) Creating an application that obtains four different values 24/06/2023


from the user and displays the products.

b) Create an application to demonstrate the string operations. 24/06/2023

c) Create an application that receives the (Student Id, Student 25/06/2023


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.

2 Working with Object Oriented C# and ASP .NET

a) Create simple application to perform following operations 24/06/2023


i. Finding factorial Value
ii. Money Conversion
iii. Quadratic Equation
iv. Temperature Conversion

b) Create simple application to demonstrate use of following 24/06/2023


concepts &
i. Function Overloading 01/07/2023
ii. Inheritance (all types)
iii. Constructor overloading
iv. Interfaces

c) Create simple application to demonstrate use of following 01/07/2023


concepts &
i. Using Delegates and events 15/07/2023
ii. Exception handling

3 Working with Web Forms and Controls

a) Create a simple web page with various server controls to 01/07/2023


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

b) Demonstrate the use of Calendar control to perform 07/06/2023


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 control

c) Demonstrate the use of Treeview control performs 07/06/2023


following operations.
a. Treeview control and datalist
b. Treeview Operations

4 Working with Navigation, Beautification and Master Page.

a) Create a Registration form to demonstrate use of various 07/06/2023


Validation controls.

b) Create a Web Form to demonstrate use of Adrotator 22/07/2023


Control.

c) Create a Web Form to demonstrate use of User Controls. 22/07/2023

5 Working with Navigation, Beautification and Master page.

a) Create Web Form to demonstrate use of Website Navigation 22/07/2023


controls and Site Map.
i.Menu Control.
ii.Site Map Control

b) Create a web application to demonstrate use of Master page 15/07/2023


with applying Styles and Themes for page beautification.

c) Create a web application to demonstrate various states of 15/07/2023


ASP.NET Pages.
i.View State
ii.Query String

6 Working with Database

a) Create a web application bind data in a multiline textbox by 12/08/2023


querying in another textbox.

b) Demonstrate the use of Data list link control 12/08/2023

7 Working with Database


a) Create a web application to display Data Binding using 26/08/2023
dropdown list control.

b) Create a web application to display the phone no of an 26/08/2023


author using a database.

c) Create a web application for inserting and deleting records 26/08/2023


from a database. (Using Execute-Non Query).

8 Working with Data Controls

a) Create a web application to demonstrate data binding using 19/08/2023


DetailsView and FormView Control.

b) Create a web application to display Using Disconnected 19/08/2023


Data Access and Data binding using GridView.

9 Working with GridView control

a) Create a web application to demonstrate use of GridView 26/08/2023


button column and GridView events.

b) Create a web application to demonstrate GridView paging 26/08/2023


and Create own table format using GridView.

c) Create a web application to demonstrate use of GridView 09/09/2023


control template and GridView hyperlink.

10 Working with AJAX and XML

a) Create a web application to demonstrate reading and writing 02/09/2023


operation with XML.

b) Create a web application to demonstrate use of various Ajax 09/09/2023


controls.

11 Programs to create and use DLL 02/09/2023


PRACTICAL NO 1: Working with basic C# and ASP .NET

1)A)Create an application that obtains four int values from the user and displays the
product.
Source code:
using System;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
int num1, num2, num3, num4, prod,sum;
Console.Write("Enter number 1: ");
num1 = Int32.Parse(Console.ReadLine());
Console.Write("Enter number 2: ");
num2 = Convert.ToInt32(Console.ReadLine());
Console.Write("Enter number 3: ");
num3 = Convert.ToInt32(Console.ReadLine());
Console.Write("Enter number 4: ");
num4 = Convert.ToInt32(Console.ReadLine());
prod = num1 * num2 * num3 * num4;
sum= num1+ num2 +num3+num4;
Console.WriteLine(num1 + "*" + num2 + "*" + num3 + "*" + num4 + "=" + prod);
Console.WriteLine(num1 + "+" + num2 + "+" + num3 + "+" + num4 + "=" +
sum);
Console.ReadLine(); }
}
}

Output:

A)Using LOOP.
using System;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{

Console.Write("Enter number 1: ");


int num1 = Int32.Parse(Console.ReadLine());
Console.Write("Enter number 2: ");
int num2 = Convert.ToInt32(Console.ReadLine());
Console.Write("Enter number 3: ");
int num3 = Convert.ToInt32(Console.ReadLine());
Console.Write("Enter number 4: ");
int num4 = Convert.ToInt32(Console.ReadLine());
int[] ar = { num1, num2, num3, num4 };
int sum = 0;
int product = 1;
for (int i = 0;i<4;i++)
{
sum += ar[i];
}
for (int i = 0; i < 4; i++)
{
product += ar[i];
}
Console.WriteLine("Sum of numbers:"+sum);
Console.WriteLine("Product of Numbers:" + product);
Console.ReadLine(); }
}
}
Output:

1)B)Create an application to demonstrate string operations.


Source code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp1
{
internal class Program
{
static void Main(string[] args)
{
Console.WriteLine("Enter Your Name ");
String s = Console.ReadLine();
Console.WriteLine("To print Length of String = " + s.Length);
Console.WriteLine("To Print Lower Case = " + s.ToLower());
Console.WriteLine("To Print in Upper Case = " + s.ToUpper());
Console.WriteLine("To Insert the Element = " + s.Insert(9, "10"));
Console.WriteLine("To Replace The Element = " + s.Replace("y", "i"));
String s2 = String.Concat("TYIT_AWP 6417");
Console.WriteLine("Concatenate the string with TYIT_AWP_6417" + s);
Console.ReadLine();
}
}
}
Output:

1)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.

Source Code:
using System;
namespace ArrayOfStructs
{
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 < 5; 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 < 5; 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);
PRACTICAL NO 2: Working with Object Oriented C# and ASP .NET

2)A)i)Factorial
Source Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
public class Factorial
{
public static void Main(string[] args)
{
int i,fact=1,number;
Console.Write("Enter any Number: ");
number = int.Parse(Console.ReadLine());
for (i = 1; i <= number; i++)
{
fact = fact * i;
}
Console.Write("Factorial of " + number + " is: " + fact);
Console.ReadLine();
}
}
Output:
2)A)ii)Currency Converter

Source code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CurrencyConverter
{
class Program
{
static void Main(string[] args)
{
double inr, usd, exchangeRate;

Console.WriteLine("1. Convert INR to USD");


Console.WriteLine("2. Convert USD to INR");
Console.Write("Enter your choice (1 or 2): ");
int choice = int.Parse(Console.ReadLine());

if (choice == 1)
{
// Convert INR to USD
Console.Write("Enter the amount in INR: ");
inr = double.Parse(Console.ReadLine());

Console.Write("Enter the current exchange rate (1 INR to USD): ");


exchangeRate = double.Parse(Console.ReadLine());

usd = inr / exchangeRate;


Console.WriteLine("Converted amount in USD: " + usd.ToString("0.00"));
}
else if (choice == 2)
{
// Convert USD to INR
Console.Write("Enter the amount in USD: ");
usd = double.Parse(Console.ReadLine());

Console.Write("Enter the current exchange rate (1 USD to INR): ");


exchangeRate = double.Parse(Console.ReadLine());

inr = usd * exchangeRate;


Console.WriteLine("Converted amount in INR: " + inr.ToString("0.00"));
}
else
{
Console.WriteLine("Invalid choice!");
}

Console.ReadLine();
}
}
}
Output:

Source Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Currency
{
internal class Program
{
static void Main(string[] args)
{
Console.WriteLine("Enter the Currency in INR ");
double currency = Double.Parse(Console.ReadLine());
Console.WriteLine("1.USD " + "\n" + "2.EUR " + "\n");
while(true)
{
double currency1;
Console.WriteLine("Enter your choice");
String Choice= Console.ReadLine();
if(Choice=="USD")
{
currency1 = currency * 0.013;
Console.WriteLine(currency1);
}
else if(Choice=="EURO")
{
currency1 = currency * 0.012;
Console.WriteLine(currency1);
}
else if(Choice!="USD"||Choice!="EURO")
{
Console.WriteLine("hAVE YOU TYPED WRONG ,TYPE AGAIN:");
continue;
}
Console.WriteLine("do you wish to continue");
String s = Console.ReadLine();
if (s=="yes"&& s=="YES")
{
continue;
}
else if(s=="no"&& s=="NO")
{
break;
} } } }}

Output:
2)A)iii)Quadratic equation.
Source Code:

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

namespace ConsoleApp2
{
internal class Program
{

static void Main(string[] args)


{
double a, b, c;
double disc, deno, x1, x2;
Console.WriteLine("ENTER THE VALUES OF A,B,C...");
a = Convert.ToDouble(Console.ReadLine());
b = Convert.ToDouble(Console.ReadLine());
c = Convert.ToDouble(Console.ReadLine());
if (a == 0)
{
x1 = -c / b;
Console.WriteLine("The roots are Linear:", x1);
}
else
{
disc = (b * b) - (4 * a * c);
deno = 2 * a;
if (disc > 0)
{
Console.WriteLine("THE ROOTS ARE REAL AND DISTINCT ROOTS");
x1 = (-b / deno) + (Math.Sqrt(disc) / deno);
x2 = (-b / deno) - (Math.Sqrt(disc) / deno);
Console.WriteLine("THE ROOTS ARE... " + x1 + " and " + x2);
}
else if (disc == 0)
{
Console.WriteLine("THE ROOTS ARE REPEATED ROOTS");
x1 = -b / deno;
Console.WriteLine("THE ROOT IS... : " + x1);
}
else
{
Console.WriteLine("THE ROOTS ARE IMAGINARY ROOTS\n");
x1 = -b / deno;
x2 = ((Math.Sqrt((4 * a * c) - (b * b))) / deno);
Console.WriteLine("THE ROOT 1: " + x1 + "+i" + x2);
Console.WriteLine("THE ROOT 2:" + x1 + "-i" + x2);
}
}
Console.ReadLine();

}
}
}

Output:
2)A)iv)Temperature Converter

Source Code:
using System;

class TemperatureConverter
{
static void Main()
{
Console.WriteLine("Temperature Conversion:");
Console.WriteLine("1. Celsius to Fahrenheit");
Console.WriteLine("2. Fahrenheit to Celsius");
Console.Write("Enter your choice (1 or 2): ");
int choice = Convert.ToInt32(Console.ReadLine());

if (choice == 1)
{
Console.Write("Enter the temperature in Celsius: ");
double celsius = Convert.ToDouble(Console.ReadLine());
double fahrenheit = CelsiusToFahrenheit(celsius);
Console.WriteLine("Temperature in Fahrenheit: " + fahrenheit);
}
else if (choice == 2)
{
Console.Write("Enter the temperature in Fahrenheit: ");
double fahrenheit = Convert.ToDouble(Console.ReadLine());
double celsius = FahrenheitToCelsius(fahrenheit);
Console.WriteLine("Temperature in Celsius: " + celsius);
}
else
{
Console.WriteLine("Invalid choice. Please enter 1 or 2.");
}
Console.ReadLine();
}

static double CelsiusToFahrenheit(double celsius)


{
return (celsius * 9 / 5) + 32;
}

static double FahrenheitToCelsius(double fahrenheit)


{
return (fahrenheit - 32) * 5 / 9;
}}
Output:
2)B)i)Method overloading.

Source Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

public class Calculator


{
public int Add(int num1, int num2)
{
return num1 + num2;
}

public double Add(double num1, double num2)


{
return num1 + num2;
}

public string Add(string str1, string str2)


{
return str1 + str2;
}
}

public class Program


{
public static void Main(string[] args)
{
Calculator calculator = new Calculator();

int sumInt = calculator.Add(5, 10);


Console.WriteLine("Sum of integers: " + sumInt);

double sumDouble = calculator.Add(2.5, 3.7);


Console.WriteLine("Sum of doubles: " + sumDouble);

string concatenatedString = calculator.Add("Hello", "World");


Console.WriteLine("Concatenated string: " + concatenatedString);
}
}

Output:
2)B)ii) INHERITANCES.

● Single inheritance:
Source Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Inheritance
{
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:
● Multilevel Inheritance.

using System;

namespace Practical2
{
class A
{
public void funcA()
{
Console.WriteLine("Class A Function is invoked");
}
}

class B : A
{
public void funcB()
{
Console.WriteLine("Class B Function is invoked");
}
}

class C : B
{
public void funcC()
{
Console.WriteLine("Class C Function is invoked");
}
}

internal class MultiLevelInheritance


{
public static void Main(string[] args)
{
C c = new C();
c.funcC();
c.funcB();
c.funcA();
}
}
}
● Hierarchical Inheritance.

Source Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp2
{ class A
{
public void a()
{
Console.WriteLine("Method a() from class A called..");
}}
class B : A
{
public void b()
{
a();
Console.WriteLine("Method b() from class B called..");
}}
class C : A
{
public void c()
{
a();
Console.WriteLine("Method c() from class C called..");
}}
internal class Program
{
static void Main(string[] args)
{ C c_obj = new C();
Console.WriteLine("hierarchical inheritance");
c_obj.c();
Console.ReadLine();
}}}
● Multiple Inheritance.

Source code:

using System;
namespace MultipleInheritance
{class Program
{
static void Main(string[] args)
{MultipleInheritanceTest obj = new MultipleInheritanceTest();
obj.Test();

Interface1 i1 = obj;
i1.Show();

((Interface2)obj).Show();

Console.ReadKey();
}}

public interface Interface1


{
void Test();
void Show();
}
public interface Interface2
{
void Test();
void Show(); }

public class MultipleInheritanceTest : Interface1, Interface2


{public void Test()
{Console.WriteLine("Test Method is Implemented in Child Class"); }

void Interface1.Show()
{Console.WriteLine("Interface1 Show Method is Implemented in Child Class");
}
void Interface2.Show()
{
Console.WriteLine("Interface2 Show Method is Implemented in Child Class");
} }}

2)B)iii)Constructor Overloading.

Source Code:
using System;

public class Person


{
private string name;
private int age;

public Person()
{
name = "Unknown";
age = 0;
}

public Person(string name)


{
this.name = name;
age = 0;
}

public Person(string name, int age)


{
this.name = name;
this.age = age;
}

public void Display()


{
Console.WriteLine("Name: " + name);
Console.WriteLine("Age: " + age);
Console.WriteLine();
}
}
public class Program
{
public static void Main(string[] args)
{
Person person1 = new Person();
person1.Display();

Person person2 = new Person("John");


person2.Display();

Person person3 = new Person("Jane", 25);


person3.Display();
}
}
Output:
2)B)iv) Interfaces

Source Code:

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

namespace Inheritance
{
internal class Program
{
class A
{
public void a()
{
Console.WriteLine("Method a() from class A called..");
}

}
interface B
{
void b();

}
class C : A,B
{
public void c()
{
Console.WriteLine("Method c() from class C called..");
}
public void b()
{
Console.WriteLine("Method b() from class B called..");
}

}
static void Main(string[] args)
{
C obj_c = new C();
Console.WriteLine("Multiple Inheritance..\n");
obj_c.c();
obj_c.b();
Console.ReadLine();
}
}
}
2)C)i)Using Delegates and Events.

Source Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp4
{
internal class Program
{

// "addnum" and "subnum" are two delegate names


public delegate void addnum(int x,int y);
public delegate void subnum(int x, int y);

public void sum(int x, int y)


{
Console.Write("\n");
Console.WriteLine(x + " + " + y + "=" + (x + y));
}
public void sub(int x, int y)
{
Console.WriteLine(x + " - " + y + "=" + (x - y));
}

static void Main(string[] args)


{
int num1, num2,div;
Console.Write("Enter Number 1 : ");
num1 = Convert.ToInt32(Console.ReadLine());
Console.Write("Enter Number 2 : ");
num2 = Convert.ToInt32(Console.ReadLine());

Program obj = new Program();

// instantiating the delegates


addnum objsum = new addnum(obj.sum);
subnum objsub = new subnum(obj.sub);

objsum(num1, num2);
objsub(num1, num2);

Console.ReadLine();
}
}
}

Output:
2)C)ii) Exception handling
Source Code :

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

namespace ConsoleApp4
{
internal class Program
{

static void Main(string[] args)


{
int num1, num2,div;
Console.Write("Enter Number 1 : ");
num1 = Convert.ToInt32(Console.ReadLine());
Console.Write("Enter Number 2 : ");
num2 = Convert.ToInt32(Console.ReadLine());
try
{
div = num1 / num2;
Console.Write("Division : "+div);

}
catch (ArithmeticException e)
{
Console.WriteLine("Can Not Devide By Zero..");
}
Console.ReadLine();
}
}
}
PRACTICAL NO 3: Working with Web Forms and Controls

3)A)Create a simple web page with various server controls to demonstrate setting and
use of their properties. (Example: AutoPostBack)
Source code:

.aspx:

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


Inherits="prac3.webform1" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body id="Name">
<form id="form1" runat="server">
<div>
Student Registation Form_6417<br />
<br />
<br />
<asp:Label ID="Label1" runat="server" Text="NAME"></asp:Label>
<asp:TextBox ID="NAME_TB" runat="server"
> <br />
<asp:Label ID="Label2" runat="server" Text="ROLL NO"></asp:Label>
<asp:TextBox ID="ROLLNO_TB" runat="server"
> <br />
<asp:Label ID="Label3" runat="server" Text="SECTION"></asp:Label>
<asp:TextBox ID="TextBox3" runat="server"></asp:TextBox>
<br />
<br />
<br />
Language Known<asp:RadioButtonList ID="lung_RBL" runat="server">
<asp:ListItem>Java</asp:ListItem>
<asp:ListItem>Python</asp:ListItem>
<asp:ListItem>C++</asp:ListItem>
</asp:RadioButtonList>
<br />
<br />
Course <asp:DropDownList ID="DropDownList1" runat="server">
<asp:ListItem>BSC-IT</asp:ListItem>
</asp:DropDownList>
<br />
<br />
Student Information:<br />
<br />
<asp:Label ID="Name_lbl" runat="server"></asp:Label>
<br />
<asp:Label ID="Roll_lbl" runat="server"></asp:Label>
<br />
<asp:Label ID="Section_lbl" runat="server"></asp:Label>
<br />
<asp:Label ID="Lang_lbl" runat="server"></asp:Label>
<br />
<asp:Label ID="Course_lbl" runat="server"></asp:Label>
<br />
<br />
<br />
<asp:Button ID="Button1" runat="server" Text="Sumit" />
</div>
</form>
</body>
</html>

Aspx.cs:

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

namespace prac3
{
public partial class webform1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

protected void Button1_Click(object sender, EventArgs e)


{

Name_lbl.Text = "Name : " + NAME_TB.Text;


Roll_lbl.Text = "Roll No " + ROLLNO_TB.Text;
Section_lbl.Text = "Div :" + TextBox3.Text;
Lang_lbl.Text = "languages known is :\t" + " " + lung_RBL.SelectedValue;
Course_lbl.Text = "Course is " + DropDownList1.SelectedItem;

protected void TextBox1_TextChanged(object sender, EventArgs e)


{

protected void TextBox2_TextChanged(object sender, EventArgs e)


{

}
}
}

Design:
3)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

webform1.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs"
Inherits="WebApplication_CalendarControl.WebForm1" %>

<!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"
> > </div>
<br />
Today's Date: <asp:Label ID="Today_lb" runat="server"
Text="Today_Label"></asp:Label>
<br />
Selected Date: <asp:Label ID="Selected_lb" runat="server"
Text="Selected_Label"></asp:Label>
<br />
Days Till Selected Date: <asp:Label ID="TillSelected_lb" runat="server"
Text="DaysTillSelected_Label"></asp:Label>
<br />
Diwali Date: <asp:Label ID="Diwali_lb" runat="server" Text="Label"></asp:Label>
<br />
Days till Diwali Date: <asp:Label ID="TillDiwali_lb" runat="server"
Text="Label"></asp:Label>
</form>
</body>
</html>
Webform.aspx.cs
using System;
using System.Drawing;
using System.Web.UI.WebControls;

namespace WebApplication_CalendarControl
{
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Diwali_lb.Text = new DateTime(2023, 11, 10).ToString("dd/MM/yyyy");
TillDiwali_lb.Text = new DateTime(2023, 11,
10).Subtract(DateTime.Today).Days.ToString();

protected void Calendar1_SelectionChanged(object sender, EventArgs e)


{
Today_lb.Text = DateTime.Today.ToString("dd/MM/yyyy");
Selected_lb.Text = Calendar1.SelectedDate.ToString("dd/MM/yyyy");
TillSelected_lb.Text =
Calendar1.SelectedDate.Subtract(DateTime.Today).Days.ToString();
}

protected void Calendar1_Render(object sender, DayRenderEventArgs e)


{
if (e.Day.IsSelected)
{
e.Cell.BackColor = Color.Cyan;
}
}
}
}
3)C).Demonstrate the use of Treeview control perform following operations.
i) Treeview control and datalist ii) Treeview operations

i) Treeview control and datalist


Treeview.aspx:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="treeview.aspx.cs"
Inherits="prac3_3.WebForm1" %>
<!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" ShowLines="True">
<Nodes>
<asp:TreeNode Text="UnderGraduate" Value="UnderGraduate">
<asp:TreeNode Text="BSC-IT" Value="BSC-IT"></asp:TreeNode>
<asp:TreeNode Text="B.COM" Value="B.COM"></asp:TreeNode>
<asp:TreeNode Text="BBA" Value="BBA"></asp:TreeNode>
</asp:TreeNode>
<asp:TreeNode Text="PostGraduate" Value="PostGraduate">
<asp:TreeNode Text="MSC-IT" Value="MSC-IT"></asp:TreeNode>
<asp:TreeNode Text="M.COM" Value="M.COM"></asp:TreeNode>
<asp:TreeNode Text="MBA" Value="MBA"></asp:TreeNode>
</asp:TreeNode>
</Nodes>
</asp:TreeView>
<asp:XmlDataSource runat="server" DataFile="~/XMLFile1.xml"
ID="ctl01"></asp:XmlDataSource>
<asp:DataList ID="DataList1" runat="server">
<ItemTemplate>
Name : <%# Eval ("name") %> <br />
ROll no : <%# Eval ("roll") %><br />
class : <%# Eval ("class") %><br />
</ItemTemplate>
</asp:DataList>
</div>
<div>&nbsp;</div>
</form>
</body>
</html>
Treeview.aspx.cs:
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace prac3_3
{
public partial class WebForm1 : 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("XMLFile1.xml"));
if (ds != null && ds.HasChanges())
{
DataList1.DataSource = ds;
DataList1.DataBind();
}
else
{
DataList1.DataBind();
}

}
}
}
ii. Treeview Operations
WebForm1.aspx

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


Inherits="WebApplication3.WebForm1" %>

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


OnTreeNodeCollapsed
="TreeView1_TreeNodeCollapsed">
<Nodes>
<asp:TreeNode Text="BSc-IT" Value="BSc-IT" ShowCheckBox="True">
<asp:TreeNode Text="FYIT" Value="FYIT"
ShowCheckBox="True"></asp:TreeNode>
<asp:TreeNode Text="SYIT" Value="SYIT"
ShowCheckBox="True"></asp:TreeNode>
<asp:TreeNode Text="TYIT" Value="TYIT"
ShowCheckBox="True"></asp:TreeNode>
</asp:TreeNode>
<asp:TreeNode Text="B.com" Value="B.com" ShowCheckBox="True">
<asp:TreeNode Text="FYB.com" Value="FYB.com"
ShowCheckBox="True"></asp:TreeNode>
<asp:TreeNode Text="SYB.com" Value="SYB.com"
ShowCheckBox="True"></asp:TreeNode>
<asp:TreeNode Text="TYB.com" Value="TYB.com"
ShowCheckBox="True"></asp:TreeNode>
</asp:TreeNode>
</Nodes>
</asp:TreeView>
<br />

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

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

namespace WebApplication3
{
public partial class WebForm1 : 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);
}

}
}
PRACTICAL NO 4.Working with Form Controls

4)A)Create a registration form to demonstrate use of various Validation controls.


webform1.aspx
<%@ Page Language="C#" AutoEventWireup="true"
CodeBehind="WebForm1.aspx.cs" Inherits="prac4.WebForm1" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
Name :
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server"
ControlToValidate="TextBox1" ErrorMessage="Name is required!! please enter
name.." ForeColor="Red"></asp:RequiredFieldValidator>
<br />
<br />
Age :
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server"
ControlToValidate="TextBox2" ErrorMessage="Age is required!! please enter age.."
ForeColor="Red"></asp:RequiredFieldValidator>
<asp:RangeValidator ID="RangeValidator1" runat="server"
ErrorMessage="Enter Valid Age !!" ForeColor="Red" MaximumValue="100"
MinimumValue="15" Type="Integer"
ControlToValidate="TextBox2"></asp:RangeValidator>
<br />
<br />
Email :
<asp:TextBox ID="TextBox3" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server"
ControlToValidate="TextBox3" ErrorMessage="Email is required!! please enter
Email.." ForeColor="Red"></asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="RegularExpressionValidator1"
runat="server" ControlToValidate="TextBox3" ErrorMessage=" Please Enter Valid
Email!! use [@, .]" ForeColor="Red" ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\
w+)*\.\w+([-.]\w+)*"></asp:RegularExpressionValidator>
<br />
<br />
Password :
<asp:TextBox ID="TextBox4" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator4" runat="server"
ControlToValidate="TextBox4" ErrorMessage="Password is required!! "
ForeColor="Red" Type="Integer"></asp:RequiredFieldValidator>
<br />
<br />
Confirm password :
<asp:TextBox ID="TextBox5" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator5" runat="server"
ControlToValidate="TextBox5" ErrorMessage="Please Confirm the password!!!"
ForeColor="Red" Type="Integer"></asp:RequiredFieldValidator>
<asp:CompareValidator ID="CompareValidator1" runat="server"
ControlToCompare="TextBox4" ControlToValidate="TextBox5"
ErrorMessage="Please enter valid password !!check password again.."
ForeColor="Red" Type="Integer"></asp:CompareValidator>
<br />
<br />
<asp:Button ID="Button1" runat="server" Text="submit"
/>
<br />
<asp:ValidationSummary ID="ValidationSummary1" runat="server" />
<br />
<asp:Label ID="Label1" runat="server"></asp:Label>
<br />
</div>
</form>
</body>
</html>

Webform1.aspx.cs:

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

namespace prac4
{
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

protected void Button1_Click(object sender, EventArgs e)


{

if (Page.IsValid)
{

Label1.Text = "Thank You";


}
else
{
Label1.Text = "The text must be exactly 8 characters long!";
}
}
void ServerValidation(object source, ServerValidateEventArgs e)
{
if (e.Value.Length == 8)
e.IsValid = true;
else
e.IsValid = false;
}
}

Web.config:
<?xml version="1.0" encoding="utf-8"?>
<!--
For more information on how to configure your ASP.NET application, please visit
https://go.microsoft.com/fwlink/?LinkId=169433
-->
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.7.2" />
<httpRuntime targetFramework="4.7.2" />
</system.web>
<appSettings>
<add key="ValidationSettings:UnobtrusiveValidationMode"
value="None" />
</appSettings>

<system.codedom>
<compilers>
<compiler language="c#;cs;csharp" extension=".cs"
type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider,
Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=2.0.1.0,
Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4"
compilerOptions="/langversion:default /nowarn:1659;1699;1701" />
<compiler language="vb;vbs;visualbasic;vbscript" extension=".vb"
type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.VBCodeProvider,
Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=2.0.1.0,
Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4"
compilerOptions="/langversion:default /nowarn:41008 /define:_MYTYPE=\&quot;Web\
&quot; /optionInfer+" />
</compilers>
</system.codedom>
</configuration>

Output:
4)B)Create a Web Form to demonstrate use of Adrotator Control.

XmlFile1.xml:

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


<Advertisements>
<Ad>
<ImageUrl>pikachu.jpg</ImageUrl>
<NavigateUrl>https://www.pokemon.com/us/pokedex/pikachu</NavigateUrl>
<AlternateText>
Pikachu from Pokemon
</AlternateText>
<Impressions>1</Impressions>
<Keyword>ASH KETCHUM</Keyword>
</Ad>
<Ad>
<ImageUrl>eren.jpg</ImageUrl>

<NavigateUrl>https://attackontitan.fandom.com/wiki/Eren_Yeager</NavigateUrl>
<AlternateText>Eren yeager from attack on titan</AlternateText>
<Impressions>2</Impressions>
<Keyword>AOT</Keyword>
</Ad>
<Ad>
<ImageUrl>tanjiro.jpg</ImageUrl>
<NavigateUrl>https://kimetsu-no-yaiba.fandom.com/wiki/Tanjiro_Kamado</
NavigateUrl>
<AlternateText>Tanjiro from demon slayer</AlternateText>
<Impressions>3</Impressions>
<Keyword>DEMON SLAYER</Keyword>
</Ad>
</Advertisements>

Adrotator.aspx:

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


Inherits="WebApplication1.adrotator" %>

<!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" DataSourceID="XmlDataSource1" />
<asp:XmlDataSource ID="XmlDataSource1" runat="server"
DataFile="~/XMLFile1.xml"></asp:XmlDataSource>
</div>
</form>
</body>
</html>

Web.config:

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


<!--
For more information on how to configure your ASP.NET application, please visit
https://go.microsoft.com/fwlink/?LinkId=169433
-->
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.7.2" />
<httpRuntime targetFramework="4.7.2" />
</system.web>
<system.codedom>
<compilers>
<compiler language="c#;cs;csharp" extension=".cs"
type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider,
Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=2.0.1.0, Culture=neutral,
PublicKeyToken=31bf3856ad364e35" warningLevel="4"
compilerOptions="/langversion:default /nowarn:1659;1699;1701" />
<compiler language="vb;vbs;visualbasic;vbscript" extension=".vb"
type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.VBCodeProvider,
Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=2.0.1.0, Culture=neutral,
PublicKeyToken=31bf3856ad364e35" warningLevel="4"
compilerOptions="/langversion:default /nowarn:41008 /define:_MYTYPE=\&quot;Web\
&quot; /optionInfer+" />
</compilers>
</system.codedom>
</configuration>
Output:

4(c)Create Web Form to demonstrate use of User Controls.

Web UserControl1.ascx:
<%@ Control Language="C#" AutoEventWireup="true"
CodeBehind="WebUserControl1.ascx.cs" Inherits="practical4.WebUserControl1" %>
<h3>6417_Sudesh User control </h3>
<table>
<tr>
<td>
<fieldset>
<asp:Label ID="Label1" runat="server" ></asp:Label>
</fieldset>
</td>
</tr>
<tr>
<td>
<asp:Label ID="Label2" runat="server" Text="Name"></asp:Label>
</td>
<td>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td>
<asp:Label ID="Label3" runat="server" Text="Address"></asp:Label>
</td>
<td>
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td>
<asp:Label ID="Label4" runat="server" Text="Phone"></asp:Label>
</td>
<td>
<asp:TextBox ID="TextBox3" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td>
<asp:Label ID="Label5" runat="server" Text="Email"></asp:Label>

</td>
<td>
<asp:TextBox ID="TextBox4" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td></td>
<td></td>
</tr>
<tr>
<td></td>
<td>
<asp:Button ID="txtSubmit" runat="server" Text="Submit"
/>
</td>
</table>

Design:

WebForm1.aspx:

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


Inherits="practical4.WebForm1" %>

<%@ Register Src="~/WebUserControl1.ascx" TagPrefix="uc1"


TagName="WebUserControl1" %>

<!DOCTYPE html>

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

WebUserControl1.aspx.cs:

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

namespace practical4
{
public partial class WebUserControl1 : System.Web.UI.UserControl
{
private string _header;
public string strURL;

public string Header


{
get { return _header; }
set { _header = value; }
}
protected void Page_Load(object sender, EventArgs e)
{
Label1.Text = _header;
}
protected void txtSubmit(object sender, EventArgs e)
{

response.Redirect();
}
}
}
PRACTICAL NO 5:Working with Navigation, Beautification and Master
page.

5)A)Create Web Form to demonstrate use of Website Navigation controls and Site Map.

web.sitemap:
<%@ Page Title="" Language="C#" MasterPageFile="~/Site1.Master"
AutoEventWireup="true" CodeBehind="WebForm2.aspx.cs"
Inherits="practical5.WebForm2" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1"
runat="server">
<h1>ABOUT Page</h1>
<p>
<asp:SiteMapDataSource ID="SiteMapDataSource1" runat="server" />
This is About Page</p>
<img src="img/About.png" />

</asp:Content>

Master:
<%@ Master Language="C#" AutoEventWireup="true"
CodeBehind="Site1.Master.cs" Inherits="practical5.Site1" %>
<!DOCTYPE html>
<html>
<head runat="server">
<title></title>
<asp:ContentPlaceHolder ID="head" runat="server">
</asp:ContentPlaceHolder>
</head>
<body>
<header>
<h1>WEB-APP</h1>
<ul>
<li><a href="WebForm1.aspx">Home</a></li>
<li><a href="WebForm2.aspx">About</a></li>
</ul>
</header>
<form id="form1" runat="server">
<div>
<asp:SiteMapDataSource ID="SiteMapDataSource1" runat="server" />
<asp:Menu ID="Menu1" runat="server"
DataSourceID="SiteMapDataSource1"></asp:Menu>

<asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server">

<h1>This is header page</h1>


<p>About</p>
<image>
<img src="img/About.png" /></image>
</asp:ContentPlaceHolder>
</div>

</form>
<footer>&copy; 6417_Sudesh</footer>

</body>
</html>

Output:
5)B)Create Web Form to demonstrate use of Website Navigation controls and Site Map.
Site1.Master:
<%@ Master Language="C#" AutoEventWireup="true" CodeBehind="Site1.Master.cs"
Inherits="practical5.Site1" %>

<!DOCTYPE html>

<html>
<head runat="server">
<title></title>
<asp:ContentPlaceHolder ID="head" runat="server">
</asp:ContentPlaceHolder>
</head>
<body>

<header>
<h1>WEB-APP</h1>

<ul>

<li><a href="WebForm1.aspx">Home</a></li>
<li><a href="WebForm2.aspx">About</a></li>

</ul>

</header>

<form id="form1" runat="server">


<div>
<asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server">

<h1>This is header page</h1>


<p>About</p>
<image></image>
</asp:ContentPlaceHolder>
</div>
</form>
<footer>&copy; 6417_Sudesh</footer>

</body>
</html>
WebForm1.aspx:
<%@ Page Title="" Language="C#" MasterPageFile="~/Site1.Master"
AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="practical5.WebForm1"
%>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">

<h1>Home Page</h1>
<p>This is Home Page</p>
<img src="img/home.jpg" />

</asp:Content>

WebForm2.aspx:
<%@ Page Title="" Language="C#" MasterPageFile="~/Site1.Master"
AutoEventWireup="true" CodeBehind="WebForm2.aspx.cs" Inherits="practical5.WebForm2"
%>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
<h1>ABOUT Page</h1>
<p>This is About Page</p>
<img src="img/About.png" />
</asp:Content>
Output:
5)C)Create a web application to demonstrate various states of ASP.NET Pages.

1)Viewstate
WebForm3.aspx:

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

namespace practical5
{
public partial class WebForm3 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

protected void Button1_Click(object sender, EventArgs e)


{
ViewState["name"] = TextBox1.Text;
ViewState["password"] = TextBox2.Text;
TextBox1.Text = TextBox2.Text = string.Empty;
}

protected void Button2_Click(object sender, EventArgs e)


{
if (ViewState["name"] != null)
{
TextBox1.Text = ViewState["name"].ToString();
}
if (ViewState["pass"] != null)
{
TextBox2.Text = ViewState["pass"].ToString();
}

}
}
}

Page level State management technique.


Application level-whole

2)QueryString
WebForm4.aspx:
WebForm4.aspx:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm4.aspx.cs"
Inherits="practical5.WebForm4" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
QUERY STRING 6417_SUDESH:<br />
<br />
USERNAME:&nbsp;&nbsp;&nbsp;&nbsp;
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<br />
<br />
PASSWORD:&nbsp;&nbsp;&nbsp;
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
<br />
<br />
<asp:Button ID="Button1" runat="server" Text="Submit" />
<br />
<br />
</div>
</form>
</body>
</html>

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

namespace practical5
{
public partial class WebForm4 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

protected void Button1_Click(object sender, EventArgs e)


{
Response.Redirect("WebForm5.aspx?UserName" + TextBox1.Text + "&Password" +
TextBox2.Text);
}
}
}

WebForm5.aspx:

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


Inherits="practical5.WebForm5" %>

<!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" BackColor="#FFFF66" ForeColor="Red"
Text="Query String"></asp:Label>
<br />
<asp:Label ID="Label2" runat="server" Text="Label"></asp:Label>
<br />
</div>
</form>
</body>
</html>

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

namespace practical5
{
public partial class WebForm5 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
String Username;
Username=Request.QueryString["username"];
String Password;
Password =Request.QueryString["password"];

Label2.Text = "Welcome" + Username;


}
}
}

Output:
PRACTICAL NO : 6 Working with Database.
6)A) Create a web application that binds data in a multiline textbox by
querying in another textbox.

WebForm2.aspx:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm2.aspx.cs"
Inherits="Practical6.WebForm2" %>
<!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="name" runat="server" Text="Name"></asp:Label>
<asp:TextBox ID="name_TB" runat="server"></asp:TextBox>
<br />
<br />
<asp:Button ID="show_button" runat="server" Text="show"
/>
<br />
<br />
<asp:TextBox ID="output" runat="server" TextMode="MultiLine" Height="45px"
Width="100px"></asp:TextBox>
</div>
</form>
</body>
</html>
WebForm2.aspx.cs:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;
using System.Data.Sql;

namespace prac6
{
public partial class WebForm2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

protected void show_button_Click(object sender, EventArgs e)


{
SqlConnection con = new SqlConnection("Data Source=PC-63;Initial
Catalog=NewDB6417;Integrated Security=True");
con.Open();
String str = "Select * from [Employee] where Name='"+ name_TB.Text+"'";
SqlCommand cmd = new SqlCommand(str, con);
SqlDataReader rdr = cmd.ExecuteReader();
while(rdr.Read())
{
output.Text = "ID:" + rdr[0].ToString() + "\n Name" + rdr[1].ToString() + "\n
Salary:" + rdr[2].ToString();
}
}

protected void output_TextChanged(object sender, EventArgs e)


{

protected void name_TB_TextChanged(object sender, EventArgs e)


{

}
}
}
SQL Management Studio:
.
OUTPUT:

6)B)Demonstrate the use of Data list link control.

WebForm1.aspx:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs"
Inherits="Practical6.WebForm1" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:DataList ID="DataList1" runat="server">
<ItemTemplate>
ID :
<asp:Label ID="ID_Label" runat="server" Text='<%# Eval("ID") %>' />
<br />

Name :
<asp:Label ID="name_Label" runat="server" Text='<%# Eval("Name") %>' />
<br />

Salary :
<asp:Label ID="salary_Label" runat="server" Text='<%# Eval("Salary") %>' />
<br />
<br />
</ItemTemplate>
</asp:DataList>
</div>
</form>
</body>
</html>
PRACTICAL NO 7 - Working with Database

7)A) Create a web application to display Data Binding using dropdown list
control.
Source code :

webform1.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs"
Inherits="PRAC7.WebForm1" %>

<!DOCTYPE html>

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

<asp:DropDownList ID="DropDownList1" runat="server">


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

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

</div>
</form>
</body>
</html>
webform.aspx.cs
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Data.Sql;
using System.Web.Configuration;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Reflection.Emit;

namespace PRAC7
{
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{

SqlConnection con = new SqlConnection(" Data Source=PC-63;Initial


Catalog=NewDB6417;Integrated Security=True");
con.Open();
string str = "select * from Employee";
SqlCommand cmd = new SqlCommand(str, con);
SqlDataReader rdr = cmd.ExecuteReader();
DropDownList1.DataSource = rdr;
DropDownList1.DataTextField = "id";
DropDownList1.DataValueField = "name";

DropDownList1.DataBind();
}
}

protected void Button1_Click(object sender, EventArgs e)


{
Label1.Text = "Name for Selected Id : " + DropDownList1.SelectedValue;
}
}
}
output

7)B) Create a web application to display the phone no of an author using a database.
Source code
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs"
Inherits="PRAC7.WebForm1" %>

<!DOCTYPE html>

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

<asp:DropDownList ID="DropDownList1" runat="server">


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

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

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

using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Data.Sql;
using System.Web.Configuration;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Reflection.Emit;

namespace PRAC7
{
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{

SqlConnection con = new SqlConnection(" Data Source=PC-63;Initial


Catalog=NewDB6417;Integrated Security=True");
con.Open();
string str = "select * from Authors ";
SqlCommand cmd = new SqlCommand(str, con);
SqlDataReader rdr = cmd.ExecuteReader();
DropDownList1.DataSource = rdr;
DropDownList1.DataTextField = "Author";
DropDownList1.DataValueField = "Phone";

DropDownList1.DataBind();
}
}

protected void Button1_Click(object sender, EventArgs e)


{
Label1.Text = "Phone Number of Selected Author : " + DropDownList1.SelectedValue;
}
}
}
output
7)C) Create a web application for inserting and deleting records from a database.
(Using Execute-Non Query).

Source code :
webform1.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs"
Inherits="PRAC7.WebForm1" %>

<!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="Insert & Delete Operation on Database"
Font-Bold="True" Font-Size="16pt" ForeColor="#333333"></asp:Label>
<br />
<asp:Label ID="Label2" runat="server" Text="ID : " Font-Size="14pt"></asp:Label>
<asp:TextBox ID="id_TB" runat="server"></asp:TextBox>
<br />
<asp:Label ID="Label3" runat="server" Text="Name : "
Font-Size="14pt"></asp:Label>
<asp:TextBox ID="name_TB" runat="server"></asp:TextBox>
<br />
<asp:Label ID="Label4" runat="server" Text="Salary : "
Font-Size="14pt"></asp:Label>
<asp:TextBox ID="salary_TB" runat="server"></asp:TextBox>
<br />
<br />
<asp:Button ID="insert_Btn" runat="server" Text="Insert" >Font-Bold="True" Font-Size="14pt" ForeColor="#33CC33" />
&nbsp;&nbsp;&nbsp;&nbsp;
<asp:Button ID="delete_Btn" runat="server" Text="Delete"
Font-Bold="True" Font-Size="14pt" ForeColor="Red" />

<br />
<br />
<asp:Label ID="message" runat="server" Font-Size="13pt"></asp:Label>
<br />
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
DataSourceID="SqlDataSource1">
<Columns>
<asp:BoundField DataField="ID" HeaderText="id" SortExpression="id" />
<asp:BoundField DataField="Name" HeaderText="name"
SortExpression="name" />
<asp:BoundField DataField="Salary" HeaderText="salary"
SortExpression="salary" />
</Columns>
</asp:GridView>

<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="Data


Source=PC-63;Initial Catalog=NewDB6417;Integrated Security=True"
SelectCommand="SELECT * FROM [Employee]"
ProviderName="System.Data.SqlClient"></asp:SqlDataSource>

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

webform1.aspx.cs
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Data.Sql;
using System.Web.Configuration;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Services.Description;

namespace PRAC7
{
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{

SqlConnection con = new SqlConnection("Data Source=PC-63;Initial


Catalog=NewDB6417;Integrated Security=True ");
con.Open();
string str = "select * from Employee";
SqlCommand cmd = new SqlCommand(str, con);
SqlDataReader rdr = cmd.ExecuteReader();
GridView1.DataBind();
rdr.Close();
con.Close();

}
}

protected void insert_Btn_Click(object sender, EventArgs e)


{
string id = id_TB.Text;
string name = name_TB.Text;
string salary = salary_TB.Text;
SqlConnection con = new SqlConnection(" Data Source=PC-63;Initial
Catalog=NewDB6417;Integrated Security=True");
con.Open();

string str = "INSERT INTO [ ] VALUES(" + id + ", '" + name + "', " + salary + ")";
SqlCommand cmd = new SqlCommand(str, con);
cmd.ExecuteNonQuery();

message.Text = "Data Inserted Successfully";


GridView1.DataBind();
con.Close();

protected void delete_Btn_Click(object sender, EventArgs e)


{
string id = id_TB.Text;
SqlConnection con = new SqlConnection(" ");
con.Open();
string str = "delete from where id = (" + id + ")";
SqlCommand cmd = new SqlCommand(str, con);
cmd.ExecuteNonQuery();
message.Text = "Data Deleted Successfully";
GridView1.DataBind();
con.Close();

}
}
}
Output
Deleting the 6514 record:

6415 record deleted:


Inserting A record in the database:
PRACTICAL NO 8 - Working with Data Controls

8)A) Create a web application to demonstrate data binding using DetailsView and
FormView Control.
<%@ Page Language="C#" AutoEventWireup="true"
CodeBehind="DetailsView6417.aspx.cs" Inherits="practical7.DetailsView6417" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
BackColor="#DEBA84" BorderColor="#DEBA84" BorderStyle="None" BorderWidth="1px"
CellPadding="3" CellSpacing="2" DataKeyNames="ID" DataSourceID="SqlDataSource1">
<Columns>
<asp:CommandField ShowSelectButton="True" />
<asp:BoundField DataField="ID" HeaderText="ID" SortExpression="ID" />
<asp:BoundField DataField="Name" HeaderText="Name"
SortExpression="Name" />
</Columns>
<FooterStyle BackColor="#F7DFB5" ForeColor="#8C4510" />
<HeaderStyle BackColor="#A55129" Font-Bold="True" ForeColor="White" />
<PagerStyle ForeColor="#8C4510" HorizontalAlign="Center" />
<RowStyle BackColor="#FFF7E7" ForeColor="#8C4510" />
<SelectedRowStyle BackColor="#738A9C" Font-Bold="True" ForeColor="White" />
<SortedAscendingCellStyle BackColor="#FFF1D4" />
<SortedAscendingHeaderStyle BackColor="#B95C30" />
<SortedDescendingCellStyle BackColor="#F1E5CE" />
<SortedDescendingHeaderStyle BackColor="#93451F" />
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$
ConnectionStrings:NewDB6417ConnectionString %>" SelectCommand="SELECT [ID],
[Name] FROM [Employee]"></asp:SqlDataSource>
</div>
<asp:DetailsView ID="DetailsView1" runat="server" AutoGenerateRows="False"
BackColor="#DEBA84" BorderColor="#DEBA84" BorderStyle="None" BorderWidth="1px"
CellPadding="3" CellSpacing="2" DataSourceID="SqlDataSource2" Height="50px"
Width="125px">
<EditRowStyle BackColor="#738A9C" Font-Bold="True" ForeColor="White" />
<Fields>
<asp:BoundField DataField="ID" HeaderText="ID" SortExpression="ID" />
<asp:BoundField DataField="Name" HeaderText="Name"
SortExpression="Name" />
<asp:BoundField DataField="Salary" HeaderText="Salary" SortExpression="Salary"
/>
</Fields>
<FooterStyle BackColor="#F7DFB5" ForeColor="#8C4510" />
<HeaderStyle BackColor="#A55129" Font-Bold="True" ForeColor="White" />
<PagerStyle ForeColor="#8C4510" HorizontalAlign="Center" />
<RowStyle BackColor="#FFF7E7" ForeColor="#8C4510" />
</asp:DetailsView>
<asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$
ConnectionStrings:NewDB6417ConnectionString %>" SelectCommand="SELECT * FROM
[Employee] WHERE ([ID] = @ID)">
<SelectParameters>
<asp:ControlParameter ControlID="GridView1" PropertyName="SelectedValue"
Name="ID" Type="Int32" />
</SelectParameters>
</asp:SqlDataSource>
<br />
<asp:FormView ID="FormView1" runat="server" BackColor="#DEBA84"
BorderColor="#DEBA84" BorderStyle="None" BorderWidth="1px" CellPadding="3"
CellSpacing="2" DataSourceID="SqlDataSource1" GridLines="Both">
<EditItemTemplate>
ID:
<asp:TextBox ID="IDTextBox" runat="server" Text='<%# Bind("ID") %>' />
<br />
Name:
<asp:TextBox ID="NameTextBox" runat="server" Text='<%# Bind("Name") %>' />
<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>
<EditRowStyle BackColor="#738A9C" Font-Bold="True" ForeColor="White" />
<FooterStyle BackColor="#F7DFB5" Font-Names="sans-serif"
ForeColor="#8C4510" />
<FooterTemplate>
<asp:DetailsView ID="DetailsView1" runat="server" AutoGenerateRows="False"
BackColor="#DEBA84" BorderColor="#DEBA84" BorderStyle="None" BorderWidth="1px"
CellPadding="3" CellSpacing="2" DataSourceID="SqlDataSource2" Height="50px"
Width="125px">
<EditRowStyle BackColor="#738A9C" Font-Bold="True" ForeColor="White" />
<Fields>
<asp:BoundField DataField="ID" HeaderText="ID" SortExpression="ID" />
<asp:BoundField DataField="Name" HeaderText="Name"
SortExpression="Name" />
<asp:BoundField DataField="Salary" HeaderText="Salary" SortExpression="Salary"
/>
</Fields>
<FooterStyle BackColor="#F7DFB5" ForeColor="#8C4510" />
<HeaderStyle BackColor="#A55129" Font-Bold="True" ForeColor="White" />
<PagerStyle ForeColor="#8C4510" HorizontalAlign="Center" />
<RowStyle BackColor="#FFF7E7" ForeColor="#8C4510" />
</asp:DetailsView>
<br />
THANK YOU....
</FooterTemplate>
<HeaderStyle ForeColor="White" BackColor="#A55129" Font-Bold="True" />
<HeaderTemplate>
Student Information
</HeaderTemplate>
<InsertItemTemplate>
ID:
<asp:TextBox ID="IDTextBox" runat="server" Text='<%# Bind("ID") %>' />
<br />
Name:
<asp:TextBox ID="NameTextBox" runat="server" Text='<%# Bind("Name") %>' />
<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>
ID:
<asp:Label ID="IDLabel" runat="server" Text='<%# Bind("ID") %>' />
<br />
Name:
<asp:Label ID="NameLabel" runat="server" Text='<%# Bind("Name") %>' />
<br />
</ItemTemplate>
<PagerStyle ForeColor="#8C4510" HorizontalAlign="Center" />
<PagerTemplate>1</PagerTemplate>
<RowStyle BackColor="#FFF7E7" ForeColor="#8C4510" />
</asp:FormView>
</form>
</body>
</html>

Select a GridView|:
Configure:
Add a DetailsView:
Configure using where:

Change Properties of GridView:


Change code of SqlDataSource2:
<asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$
ConnectionStrings:NewDB6417ConnectionString %>" SelectCommand="SELECT * FROM
[Employee] WHERE ([ID] = @ID)">
<SelectParameters>
<asp:ControlParameter ControlID="GridView1" PropertyName="SelectedValue"
Name="ID" Type="Int32" />
</SelectParameters>
</asp:SqlDataSource>
OUTPUT:

Add FormView:
Code change in formview:

<asp:FormView ID="FormView1" runat="server" BackColor="#DEBA84"


BorderColor="#DEBA84" BorderStyle="None" BorderWidth="1px" CellPadding="3"
CellSpacing="2" DataSourceID="SqlDataSource1" GridLines="Both">

<EditItemTemplate>
ID:
<asp:TextBox ID="IDTextBox" runat="server" Text='<%# Bind("ID") %>' />
<br />
Name:
<asp:TextBox ID="NameTextBox" runat="server" Text='<%# Bind("Name") %>' />
<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>
<EditRowStyle BackColor="#738A9C" Font-Bold="True" ForeColor="White" />
<FooterStyle BackColor="#F7DFB5" Font-Names="sans-serif"
ForeColor="#8C4510" />
<FooterTemplate>

<asp:DetailsView ID="DetailsView1" runat="server" AutoGenerateRows="False"


BackColor="#DEBA84" BorderColor="#DEBA84" BorderStyle="None" BorderWidth="1px"
CellPadding="3" CellSpacing="2" DataSourceID="SqlDataSource2" Height="50px"
Width="125px">
<EditRowStyle BackColor="#738A9C" Font-Bold="True" ForeColor="White" />
<Fields>
<asp:BoundField DataField="ID" HeaderText="ID" SortExpression="ID" />
<asp:BoundField DataField="Name" HeaderText="Name"
SortExpression="Name" />

<asp:BoundField DataField="Salary" HeaderText="Salary" SortExpression="Salary"


/>
</Fields>
<FooterStyle BackColor="#F7DFB5" ForeColor="#8C4510" />
<HeaderStyle BackColor="#A55129" Font-Bold="True" ForeColor="White" />
<PagerStyle ForeColor="#8C4510" HorizontalAlign="Center" />
<RowStyle BackColor="#FFF7E7" ForeColor="#8C4510" />
</asp:DetailsView>

<br />
THANK YOU....
</FooterTemplate>
<HeaderStyle ForeColor="White" BackColor="#A55129" Font-Bold="True" />
<HeaderTemplate>
Student Information
</HeaderTemplate>
<InsertItemTemplate>

ID:
<asp:TextBox ID="IDTextBox" runat="server" Text='<%# Bind("ID") %>' />
<br />
Name:
<asp:TextBox ID="NameTextBox" runat="server" Text='<%# Bind("Name") %>' />
<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>
ID:
<asp:Label ID="IDLabel" runat="server" Text='<%# Bind("ID") %>' />
<br />
Name:
<asp:Label ID="NameLabel" runat="server" Text='<%# Bind("Name") %>' />
<br />
</ItemTemplate>

<PagerStyle ForeColor="#8C4510" HorizontalAlign="Center" />


<PagerTemplate>1</PagerTemplate>

<RowStyle BackColor="#FFF7E7" ForeColor="#8C4510" />


</asp:FormView>

Output:
BEFORE SELECTION/AFTER SELECTION:

8)B) Create a web application to display Using Disconnected Data Access and
Data binding using GridView.
Source Code:
DisconnectedDB.aspx:

<%@ Page Language="C#" AutoEventWireup="true"


CodeBehind="DisconnectedDB.aspx.cs" Inherits="practical7.DisconnectedDB" %>

<!DOCTYPE html>

<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="Show Fetched Data" />
<br />
<br />
<br />
<asp:GridView runat="server" AutoGenerateColumns="False" DataKeyNames="ID"
DataSourceID="SqlDataSource1"
> <Columns>
<asp:BoundField DataField="ID" HeaderText="ID" SortExpression="ID" />
<asp:BoundField DataField="Name" HeaderText="Name"
SortExpression="Name" />
<asp:BoundField DataField="Salary" HeaderText="Salary"
SortExpression="Salary" />
</Columns>

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

Disconnected.aspx.cs:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;
using System.Data.Sql;
namespace practical7
{
public partial class DisconnectedDB : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

protected void Unnamed1_SelectedIndexChanged(object sender, EventArgs e)


{
}
protected void Button1_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection("Data Source=PC-63;Initial
Catalog=NewDB6417;Integrated Security=True");
GridView1.Visible = true;
con.Open();
String str = "Select * from [Employees]";
SqlDataAdapter ad = new SqlDataAdapter(str,con);
DataSet ds = new DataSet();
ad.Fill(ds,"Employees");
GridView1.DataSource = ds;
GridView1.DataBind();
con.Close();
}
}
Output:
Disconnected DB:
Configure the datasource AND Keyname:

Comment the line:& remove the datasource:


<!-- <asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:NewDB6417ConnectionString %>"
SelectCommand="SELECT * FROM [Employee]"></asp:SqlDataSource>-->
PRACTICAL NO 9 - Working with GridView control

a) 9)A) Create a web application to demonstrate use of GridView button column and
GridView events.
Source code
Webform.aspx

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


Inherits="Gridview.Webform" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false"
CellPadding="4" ForeColor="#333333"
GridLines="None">
<AlternatingRowStyle BackColor="White" />
<Columns>
<asp:TemplateField HeaderText="Name" ItemStyle-Width="150">
<ItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" Text='<%# Eval("Name") %>'>

</asp:TextBox>
</ItemTemplate>

<ItemStyle Width="150px"></ItemStyle>
</asp:TemplateField>
<asp:BoundField DataField="Country" HeaderText="Country" />
<asp:TemplateField>
<ItemTemplate>
<asp:Button ID="Button1" runat="server" Text="Select"
CommandName="Select" CommandArgument="<%# Container.DataItemIndex %>" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
<EditRowStyle BackColor="#2461BF" />
<FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
<RowStyle BackColor="#EFF3FB" />
<SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True"
ForeColor="#333333" />
<SortedAscendingCellStyle BackColor="#F5F7FB" />
<SortedAscendingHeaderStyle BackColor="#6D95E1" />
<SortedDescendingCellStyle BackColor="#E9EBEF" />
<SortedDescendingHeaderStyle BackColor="#4870BE" />
</asp:GridView>
<div>
</div>
</form>
</body>
</html>

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

namespace Gridview
{
public partial class Webform : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if(!this.IsPostBack)
{
DataTable dt =new DataTable();
dt.Columns.AddRange(new DataColumn[2] { new DataColumn("Name"), new
DataColumn("Country") });
dt.Rows.Add("Sudesh", "India");
dt.Rows.Add("Dinesh", "Pakistan");
dt.Rows.Add("Ramesh", "China");
dt.Rows.Add("Rajesh", "Germany");
dt.Rows.Add("Mahesh", "Canada");
dt.Rows.Add("Kamlesh", "USA");
GridView1.DataSource = dt;
GridView1.DataBind();

}
}

protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs


e)
{
if(e.CommandName=="Select")
{
int RowIndex = Convert.ToInt32(e.CommandArgument);
GridViewRow row = GridView1.Rows[RowIndex];
string name = (row.FindControl("TextBox1") as TextBox).Text;
string country = row.Cells[1].Text;
ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert('Name:" + name +
"\\n Country:"+country + "')", true);
}
}
}
}

Design:
Output
b) 9)B) Create a web application to demonstrate GridView paging and Create own
table format using GridView.

WebForm1.aspx.

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


Inherits="Gridview.WebForm1" %>

<!DOCTYPE html>

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

<asp:GridView ID="GridView1" runat="server" AllowPaging="True"


AutoGenerateColumns="False"
Font-Names="Comic Sans MS">
<Columns>
<asp:BoundField DataField="ID" HeaderText="ID" />
<asp:BoundField DataField="Name" HeaderText="Name" />
</Columns>
</asp:GridView>

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

namespace Gridview
{
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
LoadGridData();
}
private void LoadGridData()
{
DataTable dt =new DataTable();
dt.Columns.Add("ID");
dt.Columns.Add("Name");
for (int i=0; i < 10; i++)
{
DataRow dr= dt.NewRow();
dr["ID"] = i +1;
dr["Name"] = "Student" + (i + 1);
dt.Rows.Add(dr);
}
GridView1.DataSource = dt;
GridView1.DataBind();

}
protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs
e)
{
GridView1.PageIndex= e.NewPageIndex;
LoadGridData();
}
}
}
HeaderText & datafield:
Output
c) 9) C)Create a web application to demonstrate use of GridView control template
and GridView hyperlink.
Source code
PRAC9C.PRAC:

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


Inherits="PRAC9C.PRAC9" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
> <Columns>
<asp:HyperLinkField DataNavigateUrlFields="ID" DataTextField="Name"
HeaderText="Name" DataNavigateUrlFormatString="~\WebForm2.aspx?ID={0}" />

<asp:BoundField DataField="ID" HeaderText="ID" />

<asp:BoundField DataField="Country" HeaderText="Country" />

<asp:TemplateField>

<ItemTemplate>
<asp:Button ID="Button1" runat="server" Text="Select"
CommandName="Select" CommandArgument="<%#Container.DataItemIndex %>" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</div>
</form>
</body>
</html>
PRAC9.aspx.cs
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace PRAC9C
{
public partial class PRAC9 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
DataTable dt = new DataTable();
dt.Columns.AddRange(new DataColumn[3] { new DataColumn("ID"), new
DataColumn("Name"), new DataColumn("Country") });
dt.Rows.Add("6417", "SUDESH", "India");
dt.Rows.Add("6423", "RAMESH", "US");
dt.Rows.Add("6424", "HIMESH", "Spain");
dt.Rows.Add("6432", "RAJESH", "India");
dt.Rows.Add("6403", "BIMLESH", "UK");
dt.Rows.Add("6415", "SANDESH", "Pakistan");
GridView1.DataSource = dt;
GridView1.DataBind();
}

protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs


e)
{
if (e.CommandName == "Select")
{
int rowIndex = Convert.ToInt32(e.CommandArgument);
GridViewRow row = GridView1.Rows[rowIndex];
string ID = row.Cells[1].Text;
string Country = row.Cells[2].Text;
ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert('ID: " + ID + " \\
nCountry : " + Country + "')", true);
}

}
}
}

Webform2.aspx:

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


Inherits="PRAC9C.WebForm2" %>

<!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="Hello and Welcome"></asp:Label><br
/><br /><br />

<img src="https://thumbs.dreamstime.com/b/aspx-file-format-icon-extension-line-
189463972.jpg" />

</div>
</form>
</body>
</html>
Output:
PRACTICAL NO 10 - Working with AJAX and XML

a) 10)A)Create a web application to demonstrate reading and writing operations


with XML.
Source code
6417_Prac10a.aspx

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="6417_Prac10a.aspx.cs"


Inherits="WebApplication2._6417_Prac10a" %>

<!DOCTYPE html>

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

<asp:Button ID="read_btn" runat="server" Text="Read XML"


/>
<br />

<asp:ListBox ID="ListBox1" runat="server"></asp:ListBox>


<asp:XmlDataSource ID="XmlDataSource1" runat="server"
DataFile="~/myFile.xml"></asp:XmlDataSource>
<br/> <br /><br/>
<asp:Button ID="write_btn" runat="server" Text="Write XML"
/>

</div>
</form>
</body>
</html>
6417_Prac10a.aspx.cs
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Xml;

namespace WebApplication2
{
public partial class _6417_Prac10a : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}

protected void read_btn_Click(object sender, EventArgs e)


{
string xml = "C:\\Users\\SUDESH\\source\\repos\\XMLandFormView\\myFile.xml";
XmlReader rd = XmlReader.Create(xml);
while (rd.Read())
{
switch (rd.NodeType)
{
case XmlNodeType.Element:
ListBox1.Items.Add("<" + rd.Name + ">");
break;
case XmlNodeType.Text:
ListBox1.Items.Add("<" + rd.Value + ">");
break;
case XmlNodeType.EndElement:
ListBox1.Items.Add("</" + rd.Name + ">");
break;
} }
rd.Close();
}
protected void write_btn_Click(object sender, EventArgs e)
{
XmlTextWriter tw = new XmlTextWriter("C:\\Users\\SUDESH\\source\\repos\\
XMLandFormView\\myFile.xml", null);
tw.WriteStartDocument();
tw.WriteStartElement("Student");
tw.WriteStartElement("Name", "");
tw.WriteString("Sudesh");
tw.WriteEndElement();
tw.WriteStartElement("Roll_no", "");
tw.WriteString("6417");
tw.WriteEndElement();
tw.WriteEndElement();
tw.WriteEndDocument();
tw.Close();
} }}

output

myFile.xml:
b) 10)B)Create a web application to demonstrate use of various Ajax controls.

1.Update panel
Source code
UpdatePanel.aspx

<%@ Page Language="C#" AutoEventWireup="true"


CodeBehind="6417_Updatepanel.aspx.cs" Inherits="_6417_prac10b._6417_Updatepanel"
%>

<!DOCTYPE html>

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

</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ScriptManager ID="ScriptManager1" runat="server" />
<br />

<fieldset>
6417_FIRST PANEL:<asp:UpdatePanel runat="server" ID="UpdatePanel"
UpdateMode="Conditional">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="UpdateBtn2" EventName="Click" />
</Triggers>
<ContentTemplate>
<asp:Label runat="server" ID="Label1" />
<asp:Button runat="server" ID="UpdateBtn1" > Text="Update" />
<br />

<br />
</ContentTemplate>
</asp:UpdatePanel>
</fieldset>

<fieldset>
6417_SECOND PANEL:
<!--Second panel-->
<asp:UpdatePanel runat="server" ID="UpdatePanel1" UpdateMode="Conditional">
<ContentTemplate>
<asp:Label runat="server" ID="Label2" />
<asp:Button runat="server" ID="UpdateBtn2" >Text="Update" />
</ContentTemplate>
</asp:UpdatePanel>
</fieldset>

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

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

namespace _6417_prac10b
{
public partial class _6417_Updatepanel : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

protected void UpdateBtn_Click(object sender, EventArgs e)


{
Label1.Text = DateTime.Now.ToString();
Label2.Text = DateTime.Now.ToString();
}
}
}
Output:
2.Timer Control.

Timer.aspx

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


Inherits="_6417_prac10b.Timer" %>

<!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>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:Panel ID="Panel1" runat="server" BackColor="#FFFF99"
BorderStyle="Ridge" BorderColor="#FF3300" BorderWidth="5">
<center>
<asp:Label ID="label2" runat="server" BackColor="#CCFFFF"
Text="Label" Font-Bold="False" Font-Names="Algerian"
ForeColor="#FF3300"></asp:Label>
<asp:Timer ID="timer1" runat="server" Interval="1000"></asp:Timer>
</center>
</asp:Panel>
</ContentTemplate>
</asp:UpdatePanel>
</div>
</form>
</body>
</html>

Timer.aspx.cs

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

namespace _6417_prac10b
{
public partial class Timer : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
label2.Text = "6417_Page Refreshed at:" + DateTime.Today.ToLongDateString() +
"Time: " + DateTime.Now.ToLongTimeString();
}
}
}

OUTPUT:

3. Update Progress Timer Control.


UpdatePRogTimer.aspx:
<%@ Page Language="C#" AutoEventWireup="true"
CodeBehind="UpdatePRogTimer.aspx.cs" Inherits="_6417_prac10b.UpdatePRogTimer" %>

<!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>
<asp:UpdateProgress ID="UpdateProgress1" runat="server">
<ProgressTemplate>
<asp:Label ID="Label2" runat="server" Text="Time is Updated."
ForeColor="#CC33FF"></asp:Label>
</ProgressTemplate>
</asp:UpdateProgress>
<fieldset>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
6417 Update Progress
<br />
<asp:Label ID="Label1" runat="server" Font-Bold="True" Font-
Names="Bahnschrift" ForeColor="#FFFF99" ></asp:Label>
<br />
<asp:Button ID="Button1" runat="server" Text="Time to Refresh "
BackColor="#FFFF99" BorderColor="Red" BorderStyle="Dotted" Font-
Names="Bahnschrift" />
</ContentTemplate>
</asp:UpdatePanel>
</fieldset>

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

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

namespace _6417_prac10b
{
public partial class UpdatePRogTimer : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
System.Threading.Thread.Sleep(10000);
Button1.Text = DateTime.Now.ToString();
}
}
}

Output:
PRACTICAL NO 11 - Programs to create and use DLL

11) A) Create a web application to create a calculator using dll.

6417_dll.aspx:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="6417_dll.aspx.cs"
Inherits="_6417_Sudesh_dll._6417_dll" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>CALCULATOR</title>
<style>
button {
width: 100%;
box-sizing: border-box; /* Ensure padding and borders don't affect the width */
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div>
<fieldset>
<table>
<tr>
<td>
<asp:Label ID="Label1" runat="server" Text="Calculator"></asp:Label>
</td>
</tr>
<tr>
<td>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
</td>
<td>
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
</td>
</tr>

<tr>
<td>
<asp:Button ID="add_btn" runat="server" Text="ADD"
/>
</td>
<td>
<asp:Button ID="sub_btn" runat="server" Text="SUB"
/>
</td>
</tr>
<tr>
<td>
<asp:Button ID="mul_btn" runat="server" Text="MUL"
/>
</td>

<td>
<asp:Button ID="div_btn" runat="server" Text="DIV"
/>
</td>
</tr>

<tr>
<td>
<asp:Label ID="out_lbl" runat="server" Text=""></asp:Label>
</td>
</tr>

</table>
</fieldset>

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

6417_dll.aspx.cs:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using prac11_dll;
namespace _6417_Sudesh_dll
{
public partial class _6417_dll : System.Web.UI.Page
{

double a, b, output;
Class1 cf = new Class1();

protected void sub_btn_Click(object sender, EventArgs e)


{
a = Convert.ToDouble(TextBox1.Text);
b = Convert.ToDouble(TextBox2.Text);

output = cf.sub(a, b);


out_lbl.Text = "Answer : " + output;
}

protected void mul_btn_Click(object sender, EventArgs e)


{
a = Convert.ToDouble(TextBox1.Text);
b = Convert.ToDouble(TextBox2.Text);

output = cf.mul(a, b);


out_lbl.Text = "Answer : " + output;
}

protected void div_btn_Click(object sender, EventArgs e)


{
a = Convert.ToDouble(TextBox1.Text);
b = Convert.ToDouble(TextBox2.Text);

output = cf.div(a, b);


out_lbl.Text = "Answer : " + output;
}

protected void add_btn_Click(object sender, EventArgs e)


{
a = Convert.ToDouble(TextBox1.Text);
b = Convert.ToDouble(TextBox2.Text);

output = cf.add(a, b);


out_lbl.Text = "Answer : " + output;
}
protected void Page_Load(object sender, EventArgs e)
{
}
}
}

Reference dll file:


Class1.cs:

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

namespace prac11_dll
{
public class Class1
{
public double add(double a, double b)
{
return a + b;
}
public double sub(double a, double b)
{
return a - b;
}
public double mul(double a, double b)
{
return a * b;
}
public double div(double a, double b)
{
return a / b;
}
}
}
ADD:

SUB:

DIV:
MUL:

You might also like