100% found this document useful (1 vote)
281 views

Final Awp

The document describes several C# and ASP.NET programming assignments. It includes code examples for: 1) Creating an application to get 4 integer values from the user and display their product. 2) Creating a web application to demonstrate various string operations like length, substring, uppercase etc. 3) Creating an application to get student details like ID, name, course, and DOB from multiple students and display the details. 4) Creating applications to generate Fibonacci series, test for prime numbers, test for vowels, use foreach loops with arrays, and reverse and find digit sum of a number.

Uploaded by

Lucky Lucky
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
281 views

Final Awp

The document describes several C# and ASP.NET programming assignments. It includes code examples for: 1) Creating an application to get 4 integer values from the user and display their product. 2) Creating a web application to demonstrate various string operations like length, substring, uppercase etc. 3) Creating an application to get student details like ID, name, course, and DOB from multiple students and display the details. 4) Creating applications to generate Fibonacci series, test for prime numbers, test for vowels, use foreach loops with arrays, and reverse and find digit sum of a number.

Uploaded by

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

AWP JOURNAL B.N.

N COLLEGE

PRACTICAL 1
Aim: Working with basic C# and ASP .NET
A: Create an application that obtains four int values from the user and displays the product.
INPUT:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace pract1_a {
class Product{
static void Main(string[] args) {
int a, b, c, d, product;
Console.WriteLine("Enter four integers");
a = Convert.ToInt32(Console.ReadLine());
b = Convert.ToInt32(Console.ReadLine());
c = Convert.ToInt32(Console.ReadLine());
d = Convert.ToInt32(Console.ReadLine());
product = a * b * c * d;
Console.WriteLine("Product="+product);
Console.ReadKey();
}
}
}

OUTPUT:

1
AWP JOURNAL B.N.N COLLEGE

B: Create an application to demonstrate string operations.

Design:

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

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<body><form id="form1" runat="server"><div>
<asp:Label ID="Label1" runat="server" Text="Enter String: "></asp:Label>
&nbsp;<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox><br /><br />
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Result:" />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<asp:Button ID="Button2" runat="server" OnClick="Button2_Click" Text="Reset:" /><br /><br />
<asp:Label ID="Label2" runat="server" Text="Label"></asp:Label><br />
<asp:Label ID="Label3" runat="server" Text="Label"></asp:Label><br />
<asp:Label ID="Label4" runat="server" Text="Label"></asp:Label><br />
<asp:Label ID="Label5" runat="server" Text="Label"></asp:Label><br />
<asp:Label ID="Label6" runat="server" Text="Label"></asp:Label><br />
<asp:Label ID="Label7" runat="server" Text="Label"></asp:Label><br />
<asp:Label ID="Label8" runat="server" Text="Label"></asp:Label><br />
<asp:Label ID="Label9" runat="server" Text="Label"></asp:Label><br />
<asp:Label ID="Label10" runat="server" Text="Label"></asp:Label><br />
<asp:Label ID="Label11" runat="server" Text="Label"></asp:Label></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 PPrac2{
public partial class WebForm1 : System.Web.UI.Page{
protected void Page_Load(object sender, EventArgs e){
}
2
AWP JOURNAL B.N.N COLLEGE

protected void Button1_Click(object sender, EventArgs e){


string s = TextBox1.Text;
Label2.Text = "String Length: " + s.Length;
Label3.Text = "Substring: " + s.Substring(4, 3);
Label4.Text = "Upper String: " + s.ToUpper();
Label5.Text = "Lower String: " + s.ToLower();
string rev = "";
for (int i = s.Length - 1; i >= 0; i--){
rev = rev + s[i];
}
Label6.Text = "Reverse String: " + rev.ToString();
Label7.Text = "Replace 's' by 't' in String: " + s.Replace('s', 't');
Label8.Text = "Insert 'u' in String: " + s.Insert(3, "u");
Label9.Text = "String Truncate: " + s.Trim();
Label10.Text = "Remove String: " + s.Remove(4);
Label11.Text = "Index of String: " + s.IndexOf('e');
}
protected void Button2_Click(object sender, EventArgs e){
Label1.Text = "";
Label2.Text = "";
Label3.Text = "";
Label4.Text = "";
Label5.Text = "";
Label6.Text = "";
Label7.Text = "";
Label8.Text = "";
Label9.Text = "";
Label10.Text = "";
TextBox1.Text = "";
}}}

OUTPUT:

3
AWP JOURNAL B.N.N COLLEGE

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.

INPUT:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace student{
class Program
{
struct stud
{
public String stud_name, stud_id, c_name; public int date, month, year;}
static void Main(string[] args)
{
stud[] s = new stud[5];
for (int i = 0; i < 5; i++)
{
Console.WriteLine("Enter student id");
s[i].stud_id = Console.ReadLine();
Console.WriteLine("Enter student name");
s[i].stud_name = Console.ReadLine();
Console.WriteLine("Enter course name");
s[i].c_name = Console.ReadLine();
Console.WriteLine("Enter date of birth \n Enter the date(1- 31)");
s[i].date = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Enter the month(1-12)");
s[i].month = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Enter the year");
s[i].year = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Enter student list:");
}
for (int i = 0; i < 5; i++){
Console.WriteLine("Student ID=" + s[i].stud_id);
Console.WriteLine("Student name=" + s[i].stud_name);
Console.WriteLine("Course name=" + s[i].c_name);
Console.WriteLine("Birth date=" + s[i].date + "-" + s[i].month + "-" + s[i].year);
}
Console.ReadKey();
}
}
}

4
AWP JOURNAL B.N.N COLLEGE

OUTPUT:

5
AWP JOURNAL B.N.N COLLEGE

D: Create an application to demonstrate following operations


I: Generate Fibonacci series.
INPUT:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Prac1_d_1{
class Program{
static void Main(string[] args){
int num1 = 0;
int num2 = 1;
int num3;
Console.WriteLine(num1 + " " + num2);
for (int i = 0; i < 10; i++){
num3 = num1 + num2;
num1 = num2; num2 = num3;
Console.WriteLine(num3);
Console.WriteLine(" ");
}
Console.ReadKey();
}}}
OUTPUT:

II: Test for prime numbers:


INPUT:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Prac1_d_2{
class Program{
static void Main(string[] args){
int num, counter;
Console.WriteLine("Enter a number:");
num = Convert.ToInt32(Console.ReadLine());
for (counter = 2; counter <= num / 2; counter++){
6
AWP JOURNAL B.N.N COLLEGE

if ((num % counter) == 0){


break;
}}
if (num == 1){
Console.WriteLine(num + " is neither prime nor composite");
}
else if (counter <= (num / 2)){
Console.WriteLine(num + " is not prime number");
}
else{
Console.WriteLine(num + " is prime number");
}
Console.ReadLine();
}}}

OUTPUT:

III: Test for vowels:


INPUT:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Prac1_d_3{
class Program{
static void Main(string[] args){
int a;
char ch;
Console.WriteLine("Enter a character:");
a = Console.Read();
ch = Convert.ToChar(a);
switch (ch){
case 'a': Console.WriteLine(ch + " is a vowel");
break;
case 'e': Console.WriteLine(ch + " is a vowel");
break;
case 'i': Console.WriteLine(ch + " is a vowel");
break;
case 'o': Console.WriteLine(ch + " is a vowel");
break;
case 'u': Console.WriteLine(ch + " is a vowel");
break;
case 'A': Console.WriteLine(ch + " is a vowel");
break;
case 'E': Console.WriteLine(ch + " is a vowel");
break;
case 'I': Console.WriteLine(ch + " is a vowel");
break;
case 'O': Console.WriteLine(ch + " is a vowel");
7
AWP JOURNAL B.N.N COLLEGE

break;
case 'U': Console.WriteLine(ch + " is a vowel");
break;
default:Console.WriteLine(ch + " is not a vowel");
break;
}
Console.ReadKey();
}}}
OUTPUT:

IV: Use of foreach loop with arrays:


INPUT:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Prac__d_4{
class Program{
static void Main(string[] args){
String[] str = { "AI", "AWP", "IOT", "JAVA", "SPM" };
foreach (String s in str){
Console.WriteLine(s);
}
Console.ReadKey();
}}}
OUTPUT:

V: Reverse a number and find sum of digits of a number:


INPUT:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace reverse{
class Program{
static void Main(string[] args){
int num,
rev = 0,
sum = 0, d;
Console.WriteLine("Enter any number:");
num = Convert.ToInt32(Console.ReadLine());
while (num != 0){
8
AWP JOURNAL B.N.N COLLEGE

rev = rev * 10;


d = num % 10;
rev = rev + d;
sum = sum + d;
num = num / 10;
}
Console.WriteLine("Reverse of number=" + rev);
Console.WriteLine("Sum of digits=" + sum);
Console.ReadKey();
}}}
Output:

9
AWP JOURNAL B.N.N COLLEGE

PRACTICAL 2

Aim: Working with Object Oriented C# and ASP .NET


A: Create simple application to perform following operations
I: Finding factorial Value:
INPUT:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Prac2_a_1{
class Program{
static void Main(string[] args){
int num, i, fact = 1;
Console.WriteLine("Enter a number");
num = Convert.ToInt32(Console.ReadLine());
for (i = 1; i <= num; i++){
fact = fact * i;
}
Console.WriteLine("Factorial= " + fact);
Console.ReadKey();
}}}
OUTPUT:

II Money Conversionusing System:


INPUT:
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Prac2_a_2{
class Program{
static void Main(string[] args){
int choice;
Console.WriteLine("Enter your Choice :\n 1- Dollar to Rupee \n 2- Euro to Rupee \n 3- Malaysian Ringgit to
Rupee ");
choice = int.Parse(Console.ReadLine());
switch (choice){
case 1:
Double dollar, rupee, val;
Console.WriteLine("Enter the Dollar Amount :");
dollar = Double.Parse(Console.ReadLine());
Console.WriteLine("Enter the Dollar Value :");
val = double.Parse(Console.ReadLine());
rupee = dollar * val;
Console.WriteLine("{0} Dollar Equals {1} Rupees", dollar, rupee);
break;
case 2:
Double Euro, rupe, valu;
10
AWP JOURNAL B.N.N COLLEGE

Console.WriteLine("Enter the Euro Amount :");


Euro = Double.Parse(Console.ReadLine());
Console.WriteLine("Enter the Euro Value :");
valu = double.Parse(Console.ReadLine());
rupe = Euro * valu;
Console.WriteLine("{0} Euro Equals {1} Rupees", Euro, rupe);
break;
case 3:
Double ringit, rup, value;
Console.WriteLine("Enter the Ringgit Amount :");
ringit = Double.Parse(Console.ReadLine());
Console.WriteLine("Enter the Ringgit Value :");
value = double.Parse(Console.ReadLine());
rup = ringit * value;
Console.WriteLine("{0} Malaysian Ringgit Equals {1} Rupees", ringit, rup);
break;
} Console.ReadLine();
}}}
OUTPUT:

III: Quadratic Equationusing System:


INPUT:
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Prac2_1_3{
class Program{
class Quadraticroots{
double a, b, c;
public void read(){
Console.WriteLine(" \n To find the roots of a quadratic equation of the form a*x*x + b*x + c = 0");
Console.Write("\n Enter value for a : "); a = double.Parse(Console.ReadLine()); Console.Write("\n Enter
value for b : "); b = double.Parse(Console.ReadLine()); Console.Write("\n Enter value for c : "); c =
double.Parse(Console.ReadLine());
}
public void compute(){
int m;
double r1, r2, d1;
d1 = b * b - 4 * a * c;
if (a == 0)
m = 1;
else if (d1 > 0)
m = 2;
else if (d1 == 0)
11
AWP JOURNAL B.N.N COLLEGE

m = 3;
else
m = 4;
switch (m){
case 1: Console.WriteLine("\n Not a Quadratic equation, Linear equation");
Console.ReadLine();
break;
case 2: Console.WriteLine("\n Roots are Real and Distinct");
r1 = (-b + Math.Sqrt(d1)) / (2 * a);
r2 = (-b - Math.Sqrt(d1)) / (2 * a);
Console.WriteLine("\n First root is {0:#.##}", r1);
Console.WriteLine("\n Second root is {0:#.##}", r2);
Console.ReadLine();
break;
case 3: Console.WriteLine("\n Roots are Real and Equal");
r1 = r2 = (-b) / (2 * a);
Console.WriteLine("\n First root is {0:#.##}", r1);
Console.WriteLine("\n Second root is {0:#.##}", r2);
Console.ReadLine();
break;
case 4: Console.WriteLine("\n Roots are Imaginary");
r1 = (-b) / (2 * a);
r2 = Math.Sqrt(-d1) / (2 * a);
Console.WriteLine("\n First root is {0:#.##} + i {1:#.##}", r1, r2);
Console.WriteLine("\n Second root is {0:#.##} - i {1:#.##}", r1, r2);
Console.ReadLine();
break;
}}}
class Roots{
static void Main(string[] args){
Quadraticroots qr = new Quadraticroots(); qr.read(); qr.compute();
}}}}
OUTPUT:

IV: Temperature Conversion:


INPUT:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
12
AWP JOURNAL B.N.N COLLEGE

namespace Prac2_a_4{
class Program{
static void Main(string[] args){
int celsius,
faren;
Console.WriteLine("Enter the Temperature in Celsius(°C) : ");
celsius = int.Parse(Console.ReadLine());
faren = (celsius * 9) / 5 + 32;
Console.WriteLine("0Temperature in Fahrenheit is(°F) : " + faren);
Console.ReadLine();
}}}
OUTPUT:

13
AWP JOURNAL B.N.N COLLEGE

B: Create simple application to demonstrate use of following concepts


I: Function Overloading:
INPUT:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Prac2b_1_{
class Program{
public void addition(int a, int b){
Console.WriteLine("Addition of int values= " + (a + b));
}
public void addition(float a, float b){
Console.WriteLine("Addition of float values= " + (a + b));
}
static void Main(string[] args){
Program p = new Program();
p.addition(10, 20);
p.addition(11.2f, 13.4f);
Console.ReadKey();
}}}
OUTPUT:

II: Inheritance (all types) :


 Single Inheritance
INPUT:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Prac2b_2_a{
class furniture{
string material;
float price;
public void getdata(){
Console.WriteLine("Enter material name:");
material = Console.ReadLine();
Console.WriteLine("Enter price:");
price = float.Parse(Console.ReadLine());
}
public void displaydata(){
Console.Write("\nMaterial=" + material);
Console.Write("\nPrice=" + price);
}}
class table : furniture{
int height, surface_area;
public void accept(){
base.getdata();
Console.WriteLine("Enter height:");
14
AWP JOURNAL B.N.N COLLEGE

height = Int32.Parse(Console.ReadLine());
Console.WriteLine("Enter surface area");
surface_area = Int32.Parse(Console.ReadLine());
}
public void display(){
base.displaydata();
Console.WriteLine("\nHeight=" + height);
Console.WriteLine("Surface area=" + surface_area);
}}
class sample{
static void Main(string[] args){
table obj = new table();
obj.accept();
obj.display();
Console.ReadKey();
}}}
OUTPUT:

 Hierarchical Inheritance
INPUT:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Prac2b_2_b{
class employee{
public void display(){
Console.WriteLine("This is Employee class");
}}
class programmer : employee{
public void display(){
Console.WriteLine("This is Programmer class");
}}
class manager : employee{
public void display(){
Console.WriteLine("This is Manager class");
}}
class sample{
static void Main(string[] args){
Console.WriteLine("Whose information you want to see: \n 1.Programmer \n 2.Manager");
int ch = Int32.Parse(Console.ReadLine());
if (ch == 1){
15
AWP JOURNAL B.N.N COLLEGE

programmer p = new programmer();


p.display();
}
else if (ch == 2){
manager m = new manager();
m.display();
}
else{
Console.WriteLine("Enter correct choice");
}
Console.ReadKey();
}}}
OUTPUT:

 Multilevel Inheritance
INPUT:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication4{
class person{
int age;
String name;
public person(String s,int a){
name = s;
age = a;
}
public void show(){
Console.WriteLine("Name=" + name);
Console.WriteLine("Age=" + age);
}}
class employee : person{
String designation;
public employee(String s, int a, String d)
: base(s, a){
designation = d;
}
public void show(){
base.show();
Console.WriteLine("Designation=" + designation);
}}
class payroll : employee{
int salary;
public payroll(String s, int a, String d, int sal)
: base(s, a, d){
salary = sal;
}
16
AWP JOURNAL B.N.N COLLEGE

public void show()


{
base.show();
Console.WriteLine("Salary=" + salary);
}}
class program{
static void Main(string[] args){
Console.WriteLine("\nShowing person's data");
person p = new person("Rakesh",33);
p.show();
Console.WriteLine("\nShowing employee's data");
employee e = new employee("Rakesh",33,"Deputy Manager");
e.show();
Console.WriteLine("\nShowing payroll data");
payroll p1=new payroll("Rakesh",33,"Deputy Manager",50000);
p1.show();
Console.ReadKey();
}}}
OUTPUT:

III: Constructor overloading:


INPUT:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace inetrfacekpehle{
class construct{
int x;
public construct(int a, int b){
Console.WriteLine("Addition of integer values= " + (a + b));
}
public construct(float a, float b){
Console.WriteLine("Addition of float values= " + (a + b));
}
public construct(){
x = 2;
Console.WriteLine("Addition= " + (x + x));
}}
class program{
17
AWP JOURNAL B.N.N COLLEGE

static void Main(string[] args){


construct obj1 = new construct(10, 20);
construct obj2 = new construct(11.2f, 12.2f);
construct obj3 = new construct();
Console.ReadKey();
}}}
OUTPUT:

IV: Interfaces:
INPUT:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace _2bInterfaces{
interface rect{
void calculate1(float x, float y);
}
class circle{
public void calculate2(float a){
Console.WriteLine("Area of circle= " + 3.14 * a * a);
}}
class shape : circle, rect{
public void calculate1(float x, float y){
Console.WriteLine("Area of rectangle= " + x * y);
}}
class sample{
static void Main(string[] args){
shape obj = new shape();
obj.calculate1(10.1f, 20.1f);
obj.calculate2(5.3f);
Console.ReadKey();
}}}

OUTPUT:

C: Create simple application to demonstrate use of following concepts .


I Using Delegates and events
INPUT:
using System; using System.Collections.Generic;
using System.Linq; using System.Text;
namespace @delegate{
public delegate void dele();
class Program{
public static void display(){
Console.WriteLine("Welcome to C#");

18
AWP JOURNAL B.N.N COLLEGE

}
static void Main(string[] args){
dele d1 = new dele(display);
d1();
Console.ReadKey();
}}}
OUTPUT:

II: Exception handling


INPUT:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace exceptionHandling{
public delegate void dele();
class Program{
static void Main(string[] args){
int x = 10, y = 0, z;
try{
z = x / y;}
catch (Exception e){
Console.Write("An Error Occured\n");
Console.Write(e.Message);
}
finally{
Console.Write("\nFinally Block Occured");
y = 2;
z = x / y;
Console.Write("\nz=" + z);
}
Console.ReadKey();
}}}
OUTPUT:

19
AWP JOURNAL B.N.N COLLEGE

PRACTICAL 3

Aim: Working with the Web Forms and Controls.


A: Create a simple web page with various sever controls to demonstrate setting and use of their properties.
(Example : AutoPostBack)
INPUT
Design:

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:Label ID="Label1" runat="server" Text="Name: "></asp:Label>
&nbsp;<asp:TextBox ID="txtname" runat="server"></asp:TextBox><br /><br />
<asp:Label ID="lbladdress" runat="server" Text="Address:"></asp:Label>
&nbsp;<asp:TextBox ID="txtaddress" runat="server"></asp:TextBox><br /><br />
Gender:<br />
<asp:RadioButton ID="rbmale" runat="server" AutoPostBack="True" GroupName="a" Text="Male"
/>&nbsp;&nbsp;&nbsp;
<asp:RadioButton ID="rbfemale" runat="server" AutoPostBack="True" GroupName="a" Text="Female"
/><br /><br />
Subjects:<asp:RadioButtonList ID="RadioButtonList1" runat="server" AutoPostBack="True">
<asp:ListItem>AI</asp:ListItem>
<asp:ListItem>IOT</asp:ListItem>
<asp:ListItem>SPM</asp:ListItem>
<asp:ListItem>JAVA</asp:ListItem>
<asp:ListItem>AWP</asp:ListItem>
</asp:RadioButtonList><br />
Vehicles:<br />
<asp:CheckBoxList ID="CheckBoxList1" runat="server" AutoPostBack="True">
<asp:ListItem>BUS</asp:ListItem><asp:ListItem>CAR</asp:ListItem>
<asp:ListItem>AUTO</asp:ListItem></asp:CheckBoxList><br />
Fruits:<br />
<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True">
<asp:ListItem>Apple</asp:ListItem><asp:ListItem>Mango</asp:ListItem>
<asp:ListItem>Orange</asp:ListItem></asp:DropDownList><br /><br />
20
AWP JOURNAL B.N.N COLLEGE

<asp:Button ID="Button1" runat="server" Text="Display" OnClick="Button1_Click1" /><br />


<asp:Label ID="lblresult" runat="server" Text="Result: "></asp:Label>
<br /></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;
namespace WebApplication8{
public partial class WebForm1 : System.Web.UI.Page{
protected void Page_Load(object sender, EventArgs e){ }
protected void Button1_Click(object sender, EventArgs e){
lblresult.Text += "Name:" + txtname.Text + "</br>" + "Address:" + txtaddress.Text+"</br>";
if (rbmale.Checked == true)
lblresult.Text += "Gender:" + rbmale.Text + "</br>";
else
lblresult.Text += "Gender:" + rbfemale.Text + "</br>";
for (int i = 0; i < RadioButtonList1.Items.Count; i++){
if (RadioButtonList1.Items[i].Selected)
lblresult.Text += "Subjects:" + RadioButtonList1.Text + "</br>";
}
for (int i = 0; i < CheckBoxList1.Items.Count; i++){
if (CheckBoxList1.Items[i].Selected)
lblresult.Text += "Vehicles:" + CheckBoxList1.Text + "</br>";
}
for (int i = 0; i < DropDownList1.Items.Count; i++){
if (DropDownList1.Items[i].Selected)
lblresult.Text += "Fruits:" + DropDownList1.Text + "</br>";
}}}}

OUTPUT:

21
AWP JOURNAL B.N.N COLLEGE

B: Demonstarate the use of Calendar control to perform the following operation.


I: Display messages in a calendar control
II: Display vacation in a calendar control
III: Selected day in a calendar control using style
IV: Difference between two calendar dates
Desigin:

WebForm1.aspx:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs"
Inherits="calender.WebForm1" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<body><form id="form1" runat="server"><div>
<asp:Calendar ID="Calendar1" runat="server"></asp:Calendar><br />
&nbsp;<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 />
<asp:Button ID="btnresult" runat="server" OnClick="btn_result_Click" Text="Result:" /><br /><br />
<br />
<asp:Button ID="btnreset" runat="server" OnClick="btnreset_Click" Text="Reset:" /><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 calender{
public partial class WebForm1 : System.Web.UI.Page{
protected void Page_Load(object sender, EventArgs e){
}
protected void btn_result_Click(object sender, EventArgs e){
Calendar1.Caption = "Hassan";
Calendar1.FirstDayOfWeek = FirstDayOfWeek.Sunday;
22
AWP JOURNAL B.N.N COLLEGE

Calendar1.NextPrevFormat = NextPrevFormat.ShortMonth;
Calendar1.TitleFormat = TitleFormat.Month;
Label1.Text = "<h1>Welcome to Calandar</h1>";
Label2.Text = "Today's 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 btnreset_Click(object sender, EventArgs e){
Label1.Text = "";
Label2.Text = "";
Label3.Text = "";
Label4.Text = "";
Label5.Text = "";
Calendar1.SelectedDates.Clear();
}}}
OUTPUT:

23
AWP JOURNAL B.N.N COLLEGE

C: Demonstrate the use of Treeview Control.


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>
TreeView.aspx:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="TreeView.aspx.cs"
Inherits="WebApplication3.TreeView" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server"> <title></title></head>
<body> <form id="form1" runat="server">
<div>TreeView Control:
<asp:TreeView ID="TreeView1" runat="server" ImageSet="Arrows" Font-Underline="True">
<HoverNodeStyle BackColor="White" BorderColor="#FFCCCC" />
<Nodes>
<asp:TreeNode Text="Home" Value="Home"></asp:TreeNode>
<asp:TreeNode Text="Employee" Value="Employee">
<asp:TreeNode Text="personal Details" Value="personal Details"></asp:TreeNode>
<asp:TreeNode Text="Work Details" Value="Work Details"></asp:TreeNode>
<asp:TreeNode Text="Records" Value="Records"></asp:TreeNode>
</asp:TreeNode>
<asp:TreeNode Text="Employer" Value="Employer">
<asp:TreeNode Text="Employer Details" Value="Employer Details"></asp:TreeNode>
<asp:TreeNode Text="Contact Details" Value="Contact Details"></asp:TreeNode>
</asp:TreeNode>
<asp:TreeNode Text="Admin" Value="Admin"></asp:TreeNode></Nodes>
</asp:TreeView><br/>
Fetch Details List 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") %><br /></td></tr></table>
</ItemTemplate>
</asp:DataList></div></form></body></html>
TreeView.aspx.cs:
24
AWP JOURNAL B.N.N COLLEGE

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

25
AWP JOURNAL B.N.N COLLEGE

PRACTICAL 4
Aim: Working with Form Controls
A: Create a Registration form to demonstrate use of various Validation controls.
I: RangeValidator:
Design:

WebForm1.aspx:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs"
Inherits="calender.WebForm1" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<body><form id="form1" runat="server"><div>
<asp:Label ID="Label1" runat="server" Text="Age: "></asp:Label>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:RangeValidator ID="RangeValidator1" runat="server" ControlToValidate="TextBox1"
ErrorMessage="Enter value between 20-80" ForeColor="Red" MaximumValue="80"
MinimumValue="20"></asp:RangeValidator><br /><br />
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="OK" /><br /><br />
<asp:Label ID="Label2" runat="server" Text="Result: "></asp:Label>
</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 vaaalidation{
public partial class WebForm1 : System.Web.UI.Page{
protected void Page_Load(object sender, EventArgs e){
}
protected void Button1_Click(object sender, EventArgs e){
Label2.Text = TextBox1.Text;
}}}
Web.config
<?xml version="1.0"?>
<!--For more information on how to configure your ASP.NET application, please visit
http://go.microsoft.com/fwlink/?LinkId=169433-->
<configuration>
<appSettings>
<add key="ValidationSettings:UnobtrusiveValidationMode" value="None"/>
</appSettings>
<system.web>
<compilation debug="true" targetFramework="4.0" />
26
AWP JOURNAL B.N.N COLLEGE

</system.web>
</configuration>
OUTPUT:

II: compare validator:


Design:

WebForm1.aspx:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs"
Inherits="validation2.WebForm1" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
</head><body><form id="form1" runat="server"><div>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox><br /><br />
<asp:CompareValidator ID="CompareValidator1" runat="server" BackColor="White"
ControlToCompare="TextBox1" ControlToValidate="TextBox2" ErrorMessage="Enter correct values"
ForeColor="Red"></asp:CompareValidator>
<br /><br />
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox><br /><br />
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="OK" /><br /><br />
<asp:Label ID="Label1" runat="server" Text="Result:"></asp:Label>
</div></form></body></html>
WebForm1.aspc.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace validation2{
public partial class WebForm1 : System.Web.UI.Page{
protected void Page_Load(object sender, EventArgs e){
}
protected void Button1_Click(object sender, EventArgs e){
Label1.Text = TextBox2.Text;
27
AWP JOURNAL B.N.N COLLEGE

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

III: Required Field validator:


Design:

WebForm1.aspx:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs"
Inherits="validaton3.WebForm1" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
</head><body><form id="form1" runat="server"><div>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="TextBox1"
ErrorMessage="Enter value" ForeColor="Red"></asp:RequiredFieldValidator><br /><br />
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ControlToValidate="TextBox2"
ErrorMessage="Enter value" ForeColor="Red"></asp:RequiredFieldValidator>
<br /><br />
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="OK" />
<br /></div>
<asp:Label ID="Label1" runat="server" Text="Result:"></asp:Label>
</form></body></html>
28
AWP JOURNAL B.N.N COLLEGE

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 validaton3{
public partial class WebForm1 : System.Web.UI.Page{
protected void Page_Load(object sender, EventArgs e){
}
protected void Button1_Click(object sender, EventArgs e){
Label1.Text = TextBox2.Text;
}}}
Web.config:
<?xml version="1.0"?>
<!--For more information on how to configure your ASP.NET application, please visit
http://go.microsoft.com/fwlink/?LinkId=169433-->
<configuration><appSettings>
<add key="ValidationSettings:UnobtrusiveValidationMode" value="None"/>
</appSettings>
<system.web>
<compilation debug="true" targetFramework="4.0" />
</system.web></configuration>
OUTPUT:

IV: Regular Expression Validator:


Design

WebForm1.aspx:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs"
Inherits="validaton3.WebForm1" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
</head><body><form id="form1" runat="server">
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>&nbsp;&nbsp;

29
AWP JOURNAL B.N.N COLLEGE

<asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server"


ControlToValidate="TextBox1" ErrorMessage="Enter 10 digit mobile number" ForeColor="Red"
ValidationExpression="&quot;\d{10}&quot;"></asp:RegularExpressionValidator><br /><br />
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="OK" /><br /><br />
<asp:Label ID="Label1" runat="server" Text="Result:"></asp:Label>
</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 validaton3{
public partial class WebForm1 : System.Web.UI.Page{
protected void Page_Load(object sender, EventArgs e){
}
protected void Button1_Click(object sender, EventArgs e){
Label1.Text = TextBox1.Text;
}}}
Web.config:
<?xml version="1.0"?><!--
For more information on how to configure your ASP.NET application, please visit
http://go.microsoft.com/fwlink/?LinkId=169433-->
<configuration>
<appSettings>
<add key="ValidationSettings:UnobtrusiveValidationMode" value="None"/>
</appSettings>
<system.web>
<compilation debug="true" targetFramework="4.0" />
</system.web>
</configuration>

OUTPUT:

V: Custom Validator:
Design:

30
AWP JOURNAL B.N.N COLLEGE

WebForm1.aspx:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs"
Inherits="validaton3.WebForm1" %>
<!DOCTYPE html>
<html xmlns="http:/
<body><form id="form1" runat="server">
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>&nbsp;
<asp:CustomValidator ID="CustomValidator1" runat="server" ControlToValidate="TextBox1"
ErrorMessage="Enter number which is divisible by 2" ForeColor="Red"
OnServerValidate="CustomValidator1_ServletValidator"></asp:CustomValidator><br /><br />
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="OK" /><br /><br />
<asp:Label ID="Label1" runat="server" Text="Result:"></asp:Label>
</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 validaton3{
public partial class WebForm1 : System.Web.UI.Page{
protected void Page_Load(object sender, EventArgs e){
}
protected void Button1_Click(object sender, EventArgs e){
Label1.Text = TextBox1.Text;
}
protected void CustomValidator1_ServletValidator(object source, ServerValidateEventArgs args){
int num = int.Parse(TextBox1.Text);
if (num % 2 == 0){
args.IsValid = true;
}
else{
args.IsValid = false;
}}}}
Web.config:
<?xml version="1.0"?>
<!--For more information on how to configure your ASP.NET application, please visit
http://go.microsoft.com/fwlink/?LinkId=169433-->
<configuration>
<appSettings>
<add key="ValidationSettings:UnobtrusiveValidationMode" value="None"/>
</appSettings><system.web>
<compilation debug="true" targetFramework="4.0" />
</system.web></configuration>
OUTPUT:

31
AWP JOURNAL B.N.N COLLEGE

B: Create Web Form to demonstrate use of Adrotator Control.


Design:

WebForm1.aspx:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"><body>
<form id="form1" runat="server">
<asp:AdRotator ID="AdRotator1" runat="server" DataSourceID="XmlDataSource1" />
<asp:XmlDataSource ID="XmlDataSource1" runat="server"
DataFile="~/XMLFile.xml"></asp:XmlDataSource>
</form></body></html>
XML File.xml:
<?xml version="1.0" encoding="utf-8" ?>
<Advertisements><Ad>
<ImageUrl>tim-trad-CLm3pWXrS9Q-unsplash.jpg</ImageUrl>
<NavigateUrl>http://www.google.com</NavigateUrl>
<AlternateText>Google Site</AlternateText></Ad><Ad>
<ImageUrl>larm-rmah-5em1lVBmvw8-unsplash.jpg</ImageUrl>
<NavigateUrl>http://www.facebook.com</NavigateUrl>
<AlternateText>Facebook Site</AlternateText></Ad><Ad>
<ImageUrl>harley-davidson-AyH9hAmiX9Y-unsplash.jpg</ImageUrl>
<NavigateUrl>http://www.gmail.com</NavigateUrl>
<AlternateText>Gmail Site</AlternateText>
</Ad></Advertisements>

OUTPUT:

32
AWP JOURNAL B.N.N COLLEGE

C: Create Web Form to demonstrate use User Controls.


Add Web User Control
Website -> Add -> Web User Control and Name it ‘MyUserControl.

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><br />
<asp:Label ID="Label1" runat="server" ForeColor="White" Text=" "></asp:Label>
MyUserControl.ascx.cs
protected void txtSave_Click(object sender, EventArgs e)
{
Label1.Text = "Your Name is " + txtName.Text + " and you are from " +
txtcity.Text;
}
UserControlDisplay.aspx:
<%@ Page Language="C#" AutoEventWireup="true"

33
AWP JOURNAL B.N.N COLLEGE

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


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

34
AWP JOURNAL B.N.N COLLEGE

PRACTICAL 5
Aim: Working with Navigation, Beautification and Master page.
A: Create Web Form to demonstrate use of Website Navigation controls and Site Map
Step1:- Design view:

Home.aspx:

35
AWP JOURNAL B.N.N COLLEGE

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="Product.aspx" title="Product" description="" >
<siteMapNode url="Electronics.aspx" title="Electronics" description="" >
<siteMapNode url="Tv.aspx" title="Tv" description=""/>
<siteMapNode url="Fan.aspx" title="Fan" description="" />
</siteMapNode>
<siteMapNode url="Fashion.aspx" title="Fashion" description="" >
<siteMapNode url="Cloths.aspx" title="Cloths" description="" />
</siteMapNode>
<siteMapNode url="Shopping.aspx" title="Shopping" description="" >
<siteMapNode url="Bags" title="Bags" description="" />
<siteMapNode url="Shoes.aspx" title="Shoes" description="" />
</siteMapNode>
</siteMapNode>
</siteMapNode>
</siteMap>

OUTPUT:

36
AWP JOURNAL B.N.N COLLEGE

B: Create a web application to demonstrate use of Master Page with applying Styles and Themes for page
beautification.
Skin1.skin:
<asp:Label runat="server" ForeColor="red" Font-size="14pt" Font-Name="Verdana" />
<asp:Button runat="server" Borderstyle="Solid" BorderWidth="2px" Bordercolor="Blue"
Backcolor="Magenta"/>

StyleSheet1.css:
body {
background-color:yellow;
font-family:Cambria;
font-size:18px;
}
Site1.Master:
<%@ Master Language="C#" AutoEventWireup="true" CodeBehind="Site1.master.cs"
Inherits="Pract5.Site1" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<asp:ContentPlaceHolder ID="head" runat="server">
</asp:ContentPlaceHolder>
<link href="StyleSheet1.css" rel="stylesheet" type="text/css" />
</head><body>
<form id="form1" runat="server"> <div>
<asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server">
</asp:ContentPlaceHolder>
<asp:ContentPlaceHolder ID="ContentPlaceHolder2" runat="server">
</asp:ContentPlaceHolder>
</div> </form></body></html>
WebForm2.aspx:
<%@ Page Theme="Skin1" Title="" Language="C#" MasterPageFile="~/Site1.Master"
AutoEventWireup="true" CodeBehind="WebForm2.aspx.cs" Inherits="Pract5.WebForm2" %>
<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="Advanced Web Programming"></asp:Label>
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="ContentPlaceHolder2" runat="server">
<asp:Label ID="Label2" runat="server" Text="Enterprise Java"></asp:Label>
<br />
<asp:Label ID="Label3" runat="server" Text="Label"></asp:Label>
<br />
<asp:Button ID="Button1" runat="server" Text="Demo" OnClick="Button1_Click" />
</asp:Content>
WebForm2.aspx.cs:
using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace Pract5
37
AWP JOURNAL B.N.N COLLEGE

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

}
protected void Button1_Click(object sender, EventArgs e)
{
Label3.Text = "Master Page and Content Page Example";
}
}
}

OUTPUT:

38
AWP JOURNAL B.N.N COLLEGE

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


WebForm1.aspx:
 I:viewState
WebForm1.aspx:
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title></head><body>
<form id="form1" runat="server">
<%-- ViewState Example--%>
<div> ViewState<br />
&nbsp;<asp:Button ID="Button1" runat="server" Text="Increment" OnClick="Button1_Click" />
<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.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace AWP_Practs{
public partial class WebForm1 : System.Web.UI.Page {
protected void Page_Load(object sender, EventArgs e) {
}
//ViewState
protected void Button1_Click(object sender, EventArgs e) {
int counter;
if (ViewState["Counter"] == null) {
counter = 1;
}
else {
counter = (int)ViewState["Counter"] + 1;
}
ViewState["Counter"] = counter;
Label1.Text = "Counter: " + counter.ToString();
} }}
OUTPUT:

39
AWP JOURNAL B.N.N COLLEGE

II: CrossPage Posting


WebForm1.aspx:
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server"> <title></title></head><body> <form id="form1" runat="server">
<%-- CrossPage Posting--%>
<div>CrossPage Posting Example <br />
First Name:<asp:TextBox ID="txtname" runat="server"></asp:TextBox><br />
Email Id&nbsp;&nbsp;&nbsp;&nbsp; :
<asp:TextBox ID="txtemail" runat="server"></asp:TextBox><br /><br />
<asp:Button runat="server" ID="cmdPost"
PostBackUrl="~/WebForm2.aspx" Text="Cross-Page Postback" /> <br /> <br /> <br />
</div> </form></body></html>
WebForm2.aspx:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm2.aspx.cs"
Inherits="AWP_Practs.WebForm2" %>
<!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:Label ID="lblname" runat="server" Text="Label"></asp:Label> <br />
Email:<asp:Label ID="lblemail" runat="server" Text="Label"></asp:Label> </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;
namespace AWP_Practs{
public partial class WebForm2 : System.Web.UI.Page {
protected void Page_Load(object sender, EventArgs e) {
// CrossPage Posting
Page previousPage = Page.PreviousPage;
if (previousPage != null) {
lblname.Text = ((TextBox)previousPage.FindControl("txtname")).Text;
lblemail.Text = ((TextBox)previousPage.FindControl("txtemail")).Text;
}}}
OUTPUT:

40
AWP JOURNAL B.N.N COLLEGE

III: Cookies:
WebForm1.aspx:
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title></head><body>
<form id="form1" runat="server">
<%-- Cookies--%> <div>
Cookies Example <br /> First Name:
<asp:TextBox ID="txtname1" runat="server"></asp:TextBox><br />
Email Id&nbsp;&nbsp;&nbsp;&nbsp; :
<asp:TextBox ID="txtemail1" runat="server"></asp:TextBox><br /><br />
<asp:Button runat="server" ID="Button2"
Text="Submit" OnClick="Button2_Click" /> <br /> <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 AWP_Practs{
public partial class WebForm1 : System.Web.UI.Page {
protected void Page_Load(object sender, EventArgs e) {
}
protected void Button2_Click(object sender, EventArgs e) {
HttpCookie cookie = new HttpCookie("UserInfo");
cookie["name"] = txtname1.Text;
cookie["email"] = txtemail1.Text;
//for persistence cookies
cookie.Expires = DateTime.Now.AddSeconds(5);
Response.Cookies.Add(cookie);
Response.Redirect("WebForm2.aspx");
}}}
WebForm2.aspx:
//same AS CrossPage Posting Url
WebForm2.aspx.cs:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace AWP_Practs{
public partial class WebForm2 : System.Web.UI.Page {
protected void Page_Load(object sender, EventArgs e) {
//Cookies
HttpCookie cookie = Request.Cookies["UserInfo"];
41
AWP JOURNAL B.N.N COLLEGE

if (cookie != null) {
lblname.Text=cookie["name"];
lblemail.Text=cookie["email"];
}}}
OUTPUT:

IV: Session:
WebForm1.aspx:
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server"> <title></title></head><body>
<form id="form1" runat="server">
<%-- Session--%> <div> <br />
Session Example <br />
First Name:<asp:TextBox ID="txtname2" runat="server"></asp:TextBox><br />
Email Id&nbsp;&nbsp;&nbsp;&nbsp; :
<asp:TextBox ID="txtemail2" runat="server"></asp:TextBox><br /><br />
<asp:Button runat="server" ID="Button3"
Text="Submit" OnClick="Button3_Click" /><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 AWP_Practs{
public partial class WebForm1 : System.Web.UI.Page {
protected void Page_Load(object sender, EventArgs e) {
}
protected void Button3_Click(object sender, EventArgs e) {
Session["name"] = txtname2.Text;
Session["email"] = txtemail2.Text;
Session.Timeout = 1;
Response.Redirect("WebForm2.aspx"); } }}
WebForm2.aspx:
//Designing same as above
WebForm2.aspx.cs:
using System;
using System.Collections.Generic;
42
AWP JOURNAL B.N.N COLLEGE

using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace AWP_Practs{
public partial class WebForm2 : System.Web.UI.Page {
protected void Page_Load(object sender, EventArgs e) {
if(Session["name"]!=null)
lblname.Text = Session["name"].ToString();
if (Session["email"] != null)
lblemail.Text = Session["email"].ToString();
} }}

OUTPUT:

43
AWP JOURNAL B.N.N COLLEGE

PRACTICAL 6
Aim: Working with database
A: Create a web application bind data in a multiline textbox by querying in another textbox.
INPUT:
Pract6_a.aspx:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Pract6_a.aspx.cs"
Inherits="AWP_Practs.Pract6_a" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"><body>
<form id="form1" runat="server"><div>
<asp:TextBox ID="TextBox1" runat="server" TextMode="MultiLine"></asp:TextBox><br /><br />
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Execute Query" /><br /><br />
<asp:TextBox ID="TextBox2" runat="server" TextMode="MultiLine"></asp:TextBox>
</div></form></body></html>
Pract6_a.aspx.cs:
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace AWP_Practs{
public partial class Pract6_a : System.Web.UI.Page{
protected void Page_Load(object sender, EventArgs e){
}
protected void Button1_Click(object sender, EventArgs e){
string constr = ConfigurationManager.ConnectionStrings["conn"].ConnectionString;
SqlConnection con = new SqlConnection(constr);
con.Open();
SqlCommand cmd = new SqlCommand(TextBox1.Text,con);
SqlDataReader dr = cmd.ExecuteReader();
TextBox2.Text = "";
while (dr.Read()){
for (int i = 0; i < dr.FieldCount - 1; i++){
TextBox2.Text += dr[i].ToString().PadLeft(15);
}}
dr.Close();
con.Close();
}}}
44
AWP JOURNAL B.N.N COLLEGE

OUTPUT:

45
AWP JOURNAL B.N.N COLLEGE

B: Create a web application to display records by using database.


INPUT:
Pract6_b.aspx:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Pract6_b.aspx.cs"
Inherits="AWP_Practs.Pract6_b" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<body><form id="form1" runat="server"><div>
<asp:Label ID="Label1" runat="server" Text="customer details:"></asp:Label>
<br/><br/>
<asp:Button ID="Button1" runat="server" Text="display" OnClick="Button1_Click"/>
</div></form></body></html>
Pract6_b.aspx.cs:
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace AWP_Practs{
public partial class Pract6_b : System.Web.UI.Page{
protected void Page_Load(object sender, EventArgs e){
}
protected void Button1_Click(object sender, EventArgs e){
string constr = ConfigurationManager.ConnectionStrings["conn"].ConnectionString;
SqlConnection con = new SqlConnection(constr);
con.Open();
SqlCommand cmd = new SqlCommand("select * from Customer", con);
SqlDataReader dr = cmd.ExecuteReader();
while (dr.Read()){
//create one table and show hoe to fetch
Label1.Text += dr["FirstName"].ToString() + " " + dr["LastName"].ToString() + " " + dr["City"].ToString()
+ " " + dr["Country"].ToString() + " " + dr["Phone"].ToString() + "</br>";
}
dr.Close();
con.Close();
}}}
Web.Config:

46
AWP JOURNAL B.N.N COLLEGE

<?xml version="1.0"?>
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.5" />
<httpRuntime targetFramework="4.5" /></system.web>
<connectionStrings>
<add name="conn" connectionString="Data Source=PC\MSSQLSERVERDB;Initial
Catalog=Business;Integrated Security=True"/>
</connectionStrings>
</configuration>
OUTPUT:

47
AWP JOURNAL B.N.N COLLEGE

C: Demonstrate the use of Datalist link control.


INPUT:
Pract6_c.aspx:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Pract6_c.aspx.cs"
Inherits="AWP_Practs.Pract6_c" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"><body>
<form id="form1" runat="server"><div>
<asp:DataList ID="DataList1" runat="server" DataKeyField="id" DataSourceID="SqlDataSource1">
<ItemTemplate>
id:<asp:Label ID="idLabel" runat="server" Text='<%# Eval("id") %>' /><br />
FirstName:<asp:Label ID="FirstNameLabel" runat="server" Text='<%# Eval("FirstName") %>' /><br />
LastName:<asp:Label ID="LastNameLabel" runat="server" Text='<%# Eval("LastName") %>' /><br />
City:<asp:Label ID="CityLabel" runat="server" Text='<%# Eval("City") %>' /><br />
Country:<asp:Label ID="CountryLabel" runat="server" Text='<%# Eval("Country") %>' /><br />
Phone:<asp:Label ID="PhoneLabel" runat="server" Text='<%# Eval("Phone") %>' /><br /><br />
</ItemTemplate>
</asp:DataList>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="Data
Source=PC\MSSQLSERVERDB;Initial Catalog=Business;Integrated Security=True"
ProviderName="System.Data.SqlClient" SelectCommand="SELECT [id], [FirstName], [LastName], [City],
[Country], [Phone] FROM [Customer]"></asp:SqlDataSource>
</div></form></body></html>
Design

48
AWP JOURNAL B.N.N COLLEGE

PRACTICAL 7
Aim: Working with Database
A: Create a web application to display Databinding using dropdownlist control.
INPUT:
Pract7_a.aspx:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Pract7_a.aspx.cs"
Inherits="AWP_Practs.Pract7_a" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<body><form id="form1" runat="server"><div>
<asp:DropDownList ID="DropDownList1" runat="server" DataSourceID="SqlDataSource1"
DataTextField="Country" DataValueField="Country"></asp:DropDownList>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="Data
Source=PC\MSSQLSERVERDB;Initial Catalog=Business;Integrated Security=True"
ProviderName="System.Data.SqlClient" SelectCommand="SELECT [Country] FROM
[Customer]"></asp:SqlDataSource><br />
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Click me!" /><br />
<asp:Label ID="Label1" runat="server" Text="the Country You Have Selected Is : "></asp:Label>
</div></form></body></html>
Pract7_a.aspx.cs:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace AWP_Practs{
public partial class Pract7_a : System.Web.UI.Page{
protected void Page_Load(object sender, EventArgs e){
}
protected void Button1_Click(object sender, EventArgs e){
Label1.Text ="The Coutry You Have Selected Is : "+ DropDownList1.SelectedValue;
}}}

49
AWP JOURNAL B.N.N COLLEGE

OUTPUT:

50
AWP JOURNAL B.N.N COLLEGE

B: Create a web application for to display the phone no of an author using database.
INPUT:
Pract7_b.aspx:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Pract7_b.aspx.cs"
Inherits="AWP_Practs.Pract7_b" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<body><form id="form1" runat="server"><div>
<asp:DropDownList ID="DropDownList1" runat="server" DataSourceID="SqlDataSource1"
DataTextField="FirstName" DataValueField="Phone">
</asp:DropDownList>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="Data
Source=PC\MSSQLSERVERDB;Initial Catalog=Business;Integrated Security=True"
ProviderName="System.Data.SqlClient" SelectCommand="SELECT [FirstName], [Phone] FROM
[Customer]"></asp:SqlDataSource><br />
<asp:Button ID="Button1" runat="server" Text="Get Phone No." OnClick="Button1_Click" /><br />
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
</div></form></body></html>
Pract7_b.aspx.cs:
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace AWP_Practs{
public partial class Pract7_b : System.Web.UI.Page{
protected void Page_Load(object sender, EventArgs e){
}
protected void Button1_Click(object sender, EventArgs e){
Label1.Text = "Your Phone Number Is " + DropDownList1.SelectedValue;
}
}
}

51
AWP JOURNAL B.N.N COLLEGE

OUTPUT:

52
AWP JOURNAL B.N.N COLLEGE

C: Create a web application for inserting and deleting record from a database. (Using Execute-Non Query).
Design:

Pract7_c.aspx:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Pract7_c.aspx.cs"
Inherits="AWP_Practs.Pract7_c" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<body>
<form id="form1" runat="server"><div>
Enter Customer
ID:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<asp:TextBox ID="TextBox6" runat="server"></asp:TextBox><br />
Enter Customer First Name :<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox><br />
Enter Customer Last&nbsp; Name:<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox><br />
Enter Customer City:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<asp:TextBox ID="TextBox3" runat="server"></asp:TextBox><br />
Enter Customer Country :&nbsp;&nbsp;&nbsp;&nbsp;
<asp:TextBox ID="TextBox4" runat="server"></asp:TextBox><br />
Enter Customer Phone:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<asp:TextBox ID="TextBox5" runat="server"></asp:TextBox><br /><br />
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Insert Record" />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<asp:Button ID="Button2" runat="server" OnClick="Button2_Click" Text="Delete Record" /><br /><br />
<asp:Label ID="Label1" runat="server"></asp:Label>
</div></form></body></html>
Pract7_c.aspx.cs:
using System;
using System.Collections.Generic; using System.Configuration;
using System.Data.SqlClient; using System.Linq;
using System.Web; using System.Web.UI;
53
AWP JOURNAL B.N.N COLLEGE

using System.Web.UI.WebControls;
namespace AWP_Practs{
public partial class Pract7_c : System.Web.UI.Page{
protected void Page_Load(object sender, EventArgs e){
}
protected void Button1_Click(object sender, EventArgs e){
string constr = ConfigurationManager.ConnectionStrings["conn"].ConnectionString;
SqlConnection con = new SqlConnection(constr);
string InsertQuery = "insert into customer values(@id,@fname,@lname,@city,@country,@phone)";
SqlCommand cmd = new SqlCommand(InsertQuery, con);
cmd.Parameters.AddWithValue("@id", TextBox6.Text);
cmd.Parameters.AddWithValue("@fname",TextBox1.Text);
cmd.Parameters.AddWithValue("@lname", TextBox2.Text);
cmd.Parameters.AddWithValue("@city", TextBox3.Text);
cmd.Parameters.AddWithValue("@country", TextBox4.Text);
cmd.Parameters.AddWithValue("@phone", TextBox5.Text);
con.Open();
cmd.ExecuteNonQuery();
Label1.Text = "Record Inserted Successfuly";
con.Close();
}
protected void Button2_Click(object sender, EventArgs e){
string constr = ConfigurationManager.ConnectionStrings["conn"].ConnectionString;
SqlConnection con = new SqlConnection(constr);
string InsertQuery = "Delete from customer where FirstName=@fname";
SqlCommand cmd = new SqlCommand(InsertQuery, con);
cmd.Parameters.AddWithValue("@fname",TextBox1.Text);
con.Open();
cmd.ExecuteNonQuery();
Label1.Text = "Record Deleted Successfuly";
con.Close();
}}}

54
AWP JOURNAL B.N.N COLLEGE

OUTPUT:

55
AWP JOURNAL B.N.N COLLEGE

PRACTICAL 8
Aim: Working with Data Controls
A: Create a web application to demonstrate various uses and properties of SqlDataSource.
INPUT:
Pract8_a.aspx:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Pract8_a.aspx.cs"
Inherits="AWP_Practs.Pract8_a" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<body><form id="form1" runat="server"><div>
<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="true"
DataSourceID="SqlDataSource1" DataTextField="ProductName" DataValueField="ProductName"
OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged" style="margin-bottom: 0px">
</asp:DropDownList>
<asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="Data
Source=PC\MSSQLSERVERDB;Initial Catalog=Business;Integrated Security=True"
ProviderName="System.Data.SqlClient" SelectCommand="SELECT * FROM
[Product]"></asp:SqlDataSource>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="Data
Source=PC\MSSQLSERVERDB;Initial Catalog=Business;Integrated Security=True"
ProviderName="System.Data.SqlClient" SelectCommand="SELECT [ProductName] FROM
[Product]"></asp:SqlDataSource><br /><br />
<asp:DetailsView ID="DetailsView1" runat="server" AutoGenerateRows="False"
DataKeyNames="product_id" DataSourceID="SqlDataSource2" Height="50px" Width="125px"><Fields>
<asp:BoundField DataField="product_id" HeaderText="product_id" ReadOnly="True"
SortExpression="product_id" />
<asp:BoundField DataField="ProductName" HeaderText="ProductName" SortExpression="ProductName"
/>
<asp:BoundField DataField="supplier_id" HeaderText="supplier_id" SortExpression="supplier_id" />
<asp:BoundField DataField="UnitPrice" HeaderText="UnitPrice" SortExpression="UnitPrice" />
<asp:BoundField DataField="Package" HeaderText="Package" SortExpression="Package" />
<asp:CheckBoxField DataField="IsDiscontinued" HeaderText="IsDiscontinued"
SortExpression="IsDiscontinued" />
</Fields>
</asp:DetailsView>
</div></form></body></html>
Pract8_a.aspx.cs:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
56
AWP JOURNAL B.N.N COLLEGE

namespace AWP_Practs{
public partial class Pract8_a : System.Web.UI.Page{
protected void Page_Load(object sender, EventArgs e){
}
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e){
SqlDataSource2.SelectCommand = "select * from product where
ProductName='"+DropDownList1.SelectedValue+"'";
}}}
OUTPUT:

57
AWP JOURNAL B.N.N COLLEGE

B: Create a web application to demonstrate data binding using DetailsView and FormView Control.
INPUT:
Pract8_b.aspx:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Pract8_b.aspx.cs"
Inherits="AWP_Practs.Pract8_b" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<body><form id="form1" runat="server">
<div style="width: 713px">
<asp:FormView ID="FormView1" runat="server" BackColor="White" BorderColor="#999999"
BorderStyle="None" BorderWidth="1px" CellPadding="3" DataKeyNames="id"
DataSourceID="SqlDataSource1" GridLines="Vertical">
<EditItemTemplate>id:
<asp:Label ID="idLabel1" runat="server" Text='<%# Eval("id") %>' /><br />
FirstName:<asp:TextBox ID="FirstNameTextBox" runat="server" Text='<%# Bind("FirstName") %>' />
<br />
LastName:<asp:TextBox ID="LastNameTextBox" runat="server" Text='<%# Bind("LastName") %>' />
<br />
City:<asp:TextBox ID="CityTextBox" runat="server" Text='<%# Bind("City") %>' /><br />
Country:<asp:TextBox ID="CountryTextBox" runat="server" Text='<%# Bind("Country") %>' /><br />
Phone:<asp:TextBox ID="PhoneTextBox" runat="server" Text='<%# Bind("Phone") %>' /><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="#008A8C" Font-Bold="True" ForeColor="White" />
<FooterStyle BackColor="#CCCCCC" ForeColor="Black" />
<HeaderStyle BackColor="#000084" Font-Bold="True" ForeColor="White" />
<InsertItemTemplate>
id:<asp:TextBox ID="idTextBox" runat="server" Text='<%# Bind("id") %>' /><br />
FirstName:<asp:TextBox ID="FirstNameTextBox" runat="server" Text='<%# Bind("FirstName") %>' />
<br />
LastName:<asp:TextBox ID="LastNameTextBox" runat="server" Text='<%# Bind("LastName") %>' />
<br />
City:<asp:TextBox ID="CityTextBox" runat="server" Text='<%# Bind("City") %>' /><br />
Country:<asp:TextBox ID="CountryTextBox" runat="server" Text='<%# Bind("Country") %>' /><br />
Phone:<asp:TextBox ID="PhoneTextBox" runat="server" Text='<%# Bind("Phone") %>' /><br />
<asp:LinkButton ID="InsertButton" runat="server" CausesValidation="True" CommandName="Insert"
Text="Insert" />
&nbsp;<asp:LinkButton ID="InsertCancelButton" runat="server" CausesValidation="False"

58
AWP JOURNAL B.N.N COLLEGE

CommandName="Cancel" Text="Cancel" />


</InsertItemTemplate>
<ItemTemplate>
id:<asp:Label ID="idLabel" runat="server" Text='<%# Eval("id") %>' /><br />
FirstName:<asp:Label ID="FirstNameLabel" runat="server" Text='<%# Bind("FirstName") %>' /><br />
LastName:<asp:Label ID="LastNameLabel" runat="server" Text='<%# Bind("LastName") %>' /><br />
City:<asp:Label ID="CityLabel" runat="server" Text='<%# Bind("City") %>' /><br />
Country:<asp:Label ID="CountryLabel" runat="server" Text='<%# Bind("Country") %>' /><br />
Phone:<asp:Label ID="PhoneLabel" runat="server" Text='<%# Bind("Phone") %>' /><br />
</ItemTemplate>
<PagerStyle BackColor="#999999" ForeColor="Black" HorizontalAlign="Center" />
<RowStyle BackColor="#EEEEEE" ForeColor="Black" />
</asp:FormView>
<asp:DetailsView ID="DetailsView1" runat="server" AutoGenerateRows="False" BackColor="#CCCCCC"
BorderColor="#999999" BorderStyle="Solid" BorderWidth="3px" CellPadding="4" CellSpacing="2"
DataKeyNames="product_id" DataSourceID="SqlDataSource2" ForeColor="Black" Height="50px"
Width="125px">
<EditRowStyle BackColor="#000099" Font-Bold="True" ForeColor="White" />
<Fields>
<asp:BoundField DataField="product_id" HeaderText="product_id" ReadOnly="True"
SortExpression="product_id" />
<asp:BoundField DataField="ProductName" HeaderText="ProductName"
SortExpression="ProductName"/>
<asp:BoundField DataField="supplier_id" HeaderText="supplier_id" SortExpression="supplier_id" />
<asp:BoundField DataField="UnitPrice" HeaderText="UnitPrice" SortExpression="UnitPrice" />
<asp:BoundField DataField="Package" HeaderText="Package" SortExpression="Package" />
<asp:CheckBoxField DataField="IsDiscontinued" HeaderText="IsDiscontinued"
SortExpression="IsDiscontinued" />
</Fields>
<FooterStyle BackColor="#CCCCCC" />
<HeaderStyle BackColor="Black" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#CCCCCC" ForeColor="Black" HorizontalAlign="Left" />
<RowStyle BackColor="White" />
</asp:DetailsView>
<asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="Data
Source=PC\MSSQLSERVERDB;Initial Catalog=Business;Integrated Security=True"
ProviderName="System.Data.SqlClient" SelectCommand="SELECT * FROM
[Product]"></asp:SqlDataSource>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="Data
Source=PC\MSSQLSERVERDB;Initial Catalog=Business;Integrated Security=True"
ProviderName="System.Data.SqlClient" SelectCommand="SELECT * FROM
[Customer]"></asp:SqlDataSource>
<br /></div></form></body></html>
59
AWP JOURNAL B.N.N COLLEGE

Design:

60
AWP JOURNAL B.N.N COLLEGE

C: Create a web application to display Using Disconnected Data Access and Databinding using Grid View.
INPUT:
Pract8_c.aspx:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Pract8_c.aspx.cs"
Inherits="AWP_Practs.Pract8_c" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<body><form id="form1" runat="server"><div>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs
p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n
bsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Show Disconnected Fetched
Data" /><br />
<asp:GridView ID="GridView1" runat="server" BackColor="White" BorderColor="#336666"
BorderStyle="Double" BorderWidth="3px" CellPadding="4" GridLines="Horizontal">
<FooterStyle BackColor="White" ForeColor="#333333" />
<HeaderStyle BackColor="#336666" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#336666" ForeColor="White" HorizontalAlign="Center" />
<RowStyle BackColor="White" ForeColor="#333333" />
<SelectedRowStyle BackColor="#339966" Font-Bold="True" ForeColor="White" />
<SortedAscendingCellStyle BackColor="#F7F7F7" />
<SortedAscendingHeaderStyle BackColor="#487575" />
<SortedDescendingCellStyle BackColor="#E5E5E5" />
<SortedDescendingHeaderStyle BackColor="#275353" />
</asp:GridView>
</div></form></body></html>
Design:

Pract8_c.aspx.cs:

61
AWP JOURNAL B.N.N COLLEGE

using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace AWP_Practs{
public partial class Pract8_c : System.Web.UI.Page{
protected void Page_Load(object sender, EventArgs e){
}
protected void Button1_Click(object sender, EventArgs e){
string constr = ConfigurationManager.ConnectionStrings["conn"].ConnectionString;
SqlConnection con = new SqlConnection(constr);
SqlDataAdapter da = new SqlDataAdapter();
DataSet ds = new DataSet();
SqlCommand cmd=new SqlCommand("Select * from customer", con);
cmd.CommandType = CommandType.Text;
da.SelectCommand = cmd;
da.Fill(ds, "customer");
GridView1.DataSource = ds.Tables[0];
GridView1.DataBind();
}}}
OUTPUT:

62

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy