0% found this document useful (0 votes)
104 views90 pages

Awp Real Prac

Uploaded by

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

Awp Real Prac

Uploaded by

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

Name: Sweety Ronisha

Roll No:12

Practical 1
1. Working with basic C# and ASP .NET.
a. Create an application that obtains four int values from the user and displays the product.

Code:-
using System;
using System.Collections.Generic; using
System.Linq;
using System.Text;

namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
Int a=Convert.ToInt32(Console.ReadLine());
Int b=Convert.ToInt32(Console.ReadLine());
Int c=Convert.ToInt32(Console.ReadLine());
Int d=Convert.ToInt32(Console.ReadLine());
Int product=a*b*c*d;
Console.WriteLine(“The product is “+product());
Console.ReadLine();
}
}
}

Output:
b. Create an application to demonstrate string operations.

Code:-
using System;

namespace pract2

class Program

static void Main(string[] args)

string f; string l;

f = "steven clark";

l = "clark";

Console.WriteLine(f.Clone());

Console.WriteLine(f.CompareTo(l));

Console.WriteLine(f.Contains("ven"));

Console.WriteLine(f.EndsWith("n"));

Console.WriteLine(f.Equals(l));
Console.WriteLine(f.GetHashCode());

Console.WriteLine(f.GetType());

Console.WriteLine(f.GetTypeCode());

Console.WriteLine(f.IndexOf("e"));

Console.WriteLine(f.ToLower());

Console.WriteLine(f.ToUpper());

Console.WriteLine(f.Insert(0, "HELLO"));

Console.WriteLine(f.IsNormalized());

Console.WriteLine(f.LastIndexOf("e"));

Console.WriteLine(f.Length);

Console.WriteLine(f.Remove(5));
Console.WriteLine(f.Replace('e', 'i')); string[] split = f.Split(new
char[] { 'e' });

Console.WriteLine(split[0]);

Console.WriteLine(split[1]);

Console.WriteLine(split[2]);

Console.WriteLine(f.StartsWith("s")); Console.WriteLine(f.Substring(2, 5));

Console.WriteLine(f.ToCharArray());

Console.WriteLine(f.Trim());

Console.ReadKey();

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

Code:- using System;


namespace pract1c
{

class student

string[] sid=new string[5];

string[] sname=new string[5];

string[] course_name=new string[5];

string[] dob=new string[5];

Console.WriteLine(“Enter Student id:”);

Sid[i]=Console.ReadLine();

Console.WriteLine(“Enter Student name:”);

sname[i]=Console.ReadLine();

Console.WriteLine(“Enter cource name:”);

Course_name[i]=Console.ReadLine();
Console.WriteLine(“Enter date of birth:”);

dob[i]=Console.ReadLine();

For(int i=1; i<=3;i++)

Console.WriteLine(“Student id:” +sid[i]);

Console.WriteLine(“Student name:” +sname[i]);

Console.WriteLine(“cource name:” +cource_name[i]);

Console.WriteLine(“date of birth:” +dob[i]);

Console.ReadKey();

Output:
d.Create an application to demonstrate following operations

i. Generate Fibonacci series. ii. Test for prime numbers. iii. Test for vowels. iv. Use of foreach loop
with arrays v. Reverse a number and find the sum of digits of a number.

I. Code:-

using System;

namespace Practical4

class Program

static void Main(string[] args)

int f1 = 0 ,f2=1, f3,n,i=2;

n = Convert.ToInt32(Console.ReadLine());

Console.WriteLine("Fibonaaci Series"); Console.WriteLine(f1 + "\t" + f2);

while(i<=n)

f3 = f1 + f2;

Console.WriteLine("\n" + f3);

f1 = f2;
f2 = f3; i++;

Output:
2. Code:-

using System;

namespace prome

class Program

static void Main(string[] args)

int num, counter;

Console.Write("Enter number:"); num =


int.Parse(Console.ReadLine());

for (counter = 2; counter <= num / 2; counter++)

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

}
Output:

3.Code:- using
System;

namespace pracct4vowel

class Program

static void Main(string[] args)

string str; int i,


len, vowel;

Console.Write("Input the string : "); str =


Console.ReadLine();

vowel = 0;

len = str.Length;

for (i = 0; i < len; i++)

if (str[i] == 'a' || str[i] == 'e' || str[i] == 'i' || str[i] == 'o' || str[i] == 'u' || str[i] == 'A' || str[i]
== 'E' || str[i] == 'I' || str[i] == 'O' || str[i] == 'U')

vowel++;

Console.Write("\nThe total number of vowel in the string is :

{0}\n", vowel);

}
}

Output:

4. Code:-

using System;

namespace forech

class Program

static void Main(string[] args)

int[] a = { 1, 2, 3, 4, 5 };

foreach(int x in a)

Console.WriteLine(x);

Output:
5. Code:-

using System;

namespace reerse_sum

class Program

static void Main(string[] args)

int rem ,rev=0, sum = 0, m,n; n=


Convert.ToInt32(Console.ReadLine()); m = n;

while (n>0)

rem= n % 10; rev = rev * 10 + rem; sum = sum + rem; n=n/


10;

Console.WriteLine("The reverse of"+m+"is"+rev);

Console.WriteLine("The sum of" + m + "is" + sum);

Output:-
Practical 2
2. Working with Object Oriented C# and ASP .NET
a. Create a simple application to perform following operations i. Finding factorial Value ii. Money
Conversion iii. Quadratic Equation iv. Temperature Conversion.
1 Code:
using System;

namespace factrial
{
class Program
{
static void Main(string[] args)
{
int i, number, fact;
Console.WriteLine("Enter the Number");
number = int.Parse(Console.ReadLine());
fact = number;
for (i = number - 1; i >= 1; i--)
{
fact = fact * i;
}
Console.WriteLine("\nFactorial of Given Number is: " + fact);
Console.ReadLine();

}
}

Output
2. Code:-
using System;

namespace money_conersion
{
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;
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;
}
}
}
}

Output:

3. Code :-
using System;

namespace example
{
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)
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
{
public static void Main()
{
Quadraticroots qr = new Quadraticroots();
qr.read();
qr.compute();
}
}
}

Output:

4 Code:-
using System;

namespace Temprature_Conversion
{
class Program
{
static void Main(string[] args)
{
double f, c;
Console.WriteLine("Enter the value of Celsius:");
c = Convert.ToDouble(Console.ReadLine());
f = c* 9 / 5 + 32;
Console.WriteLine(c + "°C in Fahrenheit is: " + f + "°F");
Console.WriteLine("Enter the value of Fahrenheit:");
f = Convert.ToDouble(Console.ReadLine());
c = (f - 32) * 5 / 9;
Console.WriteLine(f + "°F in Celsius is: " + c + "°C");
Console.ReadLine();
}

}
}

Output:

b. Create a simple application to demonstrate use of following concepts i. Function Overloading ii.
Inheritance (all types) iii. Constructor overloading iv. Interfaces

1.Code:-
using System;

namespace funtion_overloadinh
{
class Program
{
class Add
{
static void add(int x)
{
Console.WriteLine("X= " + (x + x));

}
static void add(int x, int y)
{
Console.WriteLine("X+Y=" + (x + y));
}
static void add(int x, int y, int z)
{
Console.WriteLine("X+Y+Z=" + (x + y + z));
}

static void Main(string[] args)


{
Console.WriteLine("Enter the value of x,y,z");
int a, b, c;
a = int.Parse(Console.ReadLine());
b = int.Parse(Console.ReadLine());
c = int.Parse(Console.ReadLine());
add(a);
add(a,b);
add(a,b,c);
}
}

}
}

Output:

2.Code:- (SIngle Inheritance)


using System;

namespace Single_inhertience
{

class Program
{
static void Main(string[] args)
{
Father f = new Father();
f.Display();
// Son class
Son s = new Son();
s.Display();
s.DisplayOne();

Console.ReadKey();
}
class Father
{
public void Display()
{
Console.WriteLine("This is base class");
}
}
class Son : Father
{
public void DisplayOne()
{
Console.WriteLine("This is derived class");
}
}
}
}

Output :

Code: - (Multilevel Inheritance)


using System;

namespace Mutlevel_inheri
{
class Program
{
static void Main(string[] args)
{
A s = new A();
s.Display();
s.DisplayOne();
s.DisplayTwo();
Console.Read();
}
}

class A : B
{
public void DisplayTwo()
{
Console.WriteLine("A.. ");
}

}
class C
{
public void Display()
{
Console.WriteLine("C...");
}
}
class B : C
{
public void DisplayOne()
{
Console.WriteLine("B...");
}
}

}
Output:

Code:- (Hierarchical Inheritance)


using System;

namespace Hirarichal_inheri
{
class Program
{
static void Main(string[] args)
{
A f = new A();
f.display();
B s = new B();
s.display();
s.displayOne();
C d = new C();
d.displayTwo();
Console.ReadKey();

}
}
class A
{
public void display()
{
Console.WriteLine("A");
}
}
class B : A
{
public void displayOne()
{
Console.WriteLine("B");
}
}
class C : A
{
public void displayTwo()
{
Console.WriteLine("C");
}
}
}

Output:

3.Code:
using System;
class ADD
{

int x, y;
int f, p, s;

public ADD(int a, int b)


{
x = a;
y = b;
}

public ADD(int a, int b, int c)


{
f = a;
p = b;
s = c;
}

public void show()


{
Console.WriteLine("1st constructor Addtition of 2 numbers: {0} ",
(x + y));
}

public void show1()


{
Console.WriteLine("2nd constructor Addtition of 3 numbers: {0}",
(f + p + s));
}
}

class GFG
{

static void Main()


{

ADD g = new ADD(10, 20);

g.show();

ADD q = new ADD(10, 20, 30);

q.show1();

}
}

Output :-

4.Code:- using System;


using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace arithmeticinterface
{
public interface interex
{
void add(int a, int b);
void sub(int a, int b);
void mul(int a, int b);
void divi(double a, double b);
void display();
}
class inter1 : interex
{
int x, y, z;
double d;
public void add(int a, int b)
{
int m, n;
m = a;
n = b;
x = m + n;
}
public void sub(int a, int b)
{
int m, n;
m = a;
n = b;
y = a - b;
}
public void mul(int a, int b)
{
int m, n;
m = a;
n = b;
z = a * b;
}
public void divi(double a, double b)
{
double m, n;
m = a;
n = b;
d = a / b;
}
public void display()
{
Console.WriteLine("Addition value is:" + x);
Console.WriteLine("Subtraction value is:" + y);
Console.WriteLine("Multiplication value is:" + z);
Console.WriteLine("Divition value is:" + d);
}
}
class Program
{
static void Main(string[] args)
{
inter1 obj = new inter1();
int g, h;
Console.WriteLine("Enter the first Number to perform Arithmetic operations:");
g = Convert.ToInt16(Console.ReadLine());
Console.WriteLine("Enter the second Number to perform Arithmetic operations:");
h = Convert.ToInt16(Console.ReadLine());
obj.add(g, h);
obj.sub(g, h);
obj.mul(g, h);
obj.divi(g, h);
obj.display();
Console.ReadKey();
}
}
}
Output:

3. Create a simple application to demonstrate use of following concepts i. Using Delegates and
events ii. Exception handling.

1. Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Delegates_demo
{
public delegate int Mydelegate(int x, int y);
class sample
{
public static int rectangle(int a, int b)
{

return a * b;
}

class Program
{
static void Main(string[] args)
{
Console.WriteLine("Delegate Program");
Mydelegate mdl = new Mydelegate(sample.rectangle);
Console.WriteLine("The Area of rectangle is {0}", mdl(4, 5));
Console.ReadKey();
}
}
}

Output :

2.Code:-
using System;

namespace ErrorHandlingApplication {
class DivNumbers {
int result;

DivNumbers() {
result = 0;
}
public void division(int num1, int num2) {
try {
result = num1 / num2;
} catch (DivideByZeroException e) {
Console.WriteLine("Exception caught: {0}", e);
} finally {
Console.WriteLine("Result: {0}", result);
}
}
static void Main(string[] args) {
DivNumbers d = new DivNumbers();
d.division(25, 0);
Console.ReadKey();
}
}
}

Output:-

Practical 3
3. Working with Web Forms and Controls.
a. Create a simple web page with various server controls to demonstrate setting and use of their
properties. (Example : AutoPostBack) .
Code :-
"WebForm1.aspx:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs"
Inherits="autopostback.WebForm1" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<center> AutoPost Back </center>
<asp:ListBox ID="ListBox1" runat="server" AutoPostBack="True"
OnSelectedIndexChanged="ListBox1_SelectedIndexChanged">
<asp:ListItem>Red</asp:ListItem>
<asp:ListItem>Blue</asp:ListItem>
<asp:ListItem>Green</asp:ListItem>
</asp:ListBox>

<br />
<asp:Label ID="Label1" 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 autopostback
{
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

protected void ListBox1_SelectedIndexChanged(object sender, EventArgs e)


{
if (ListBox1.SelectedItem != null)
{
Label1.Text = "You selected" + ListBox1.SelectedItem.ToString();
}
else
{
Label1.Text = "Select any other item from listbox";
}
}
}
}

Output:

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.

Code:-
Webform.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs"
Inherits="_3B_calendra.WebForm1" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<asp:Calendar ID="Calendar1" runat="server" BackColor="#FFFFCC" BorderColor="#FFCC66"
BorderWidth="1px" DayNameFormat="Shortest" Font-Names="Verdana" Font-Size="8pt"
ForeColor="#663399" Height="200px" OnDayRender="Calendar1_DayRender"
OnSelectionChanged="Calendar1_SelectionChanged1" ShowGridLines="True" Width="220px">
<DayHeaderStyle BackColor="#FFCC66" Font-Bold="True" Height="1px" />
<NextPrevStyle Font-Size="9pt" ForeColor="#FFFFCC" />
<OtherMonthDayStyle ForeColor="#CC9966" />
<SelectedDayStyle BackColor="#CCCCFF" Font-Bold="True" />
<SelectorStyle BackColor="#FFCC66" />
<TitleStyle BackColor="#990000" Font-Bold="True" Font-Size="9pt" ForeColor="#FFFFCC" />
<TodayDayStyle BackColor="#FFCC66" ForeColor="White" />
</asp:Calendar>
<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:Calendar ID="Calendar2" runat="server"></asp:Calendar>
<br />
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Submit" />
<br />
<asp:Label ID="Label1" runat="server" Text="Label"></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 _3B_calendra
{
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

protected void Calendar1_SelectionChanged1(object sender, EventArgs e)


{
Calendar1.SelectedDayStyle.BackColor = System.Drawing.Color.Red;
Calendar1.SelectedDayStyle.ForeColor = System.Drawing.Color.Yellow;

Label2.Text = "Todays Date is :"+Calendar1.TodaysDate.ToShortDateString();


Label3.Text = "Selected date is :"+Calendar1.SelectedDate.ToShortDateString();

protected void Calendar1_DayRender(object sender, DayRenderEventArgs e)


{
if(e.Day.Date.Year==2020 && e.Day.Date.Month == 9||e.Day.Date.Day==11)
{
Label l1 = new Label();
l1.Text = "Ganpati";
e.Cell.Controls.Add(l1);
Label4.Text = "Ganpati Vaction Date is: 8/11/2021";
}
}

protected void Button1_Click(object sender, EventArgs e)


{
TimeSpan ts = Calendar1.SelectedDate - Calendar2.SelectedDate;
Label1.Text = "The Difference Between Two date is"+ts.TotalDays.ToString();
}
}
}

Output:
c. Demonstrate the use of Treeview control perform following operations. 25 a) Treeview control
and datalist b) Treeview operations.
Code:

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

<!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 navigation:<asp:TreeView ID = "TreeView1" runat = "server" Width ="150px"
ImageSet="Arrows">
<HoverNodeStyle Font-Underline="True" ForeColor="#5555DD" />
<Nodes>
<asp:TreeNode Text = "ASP.NET Practs" Value = "New Node">
<asp:TreeNode Text = "Calendar Control" Value = "RED" NavigateUrl="~/Home.aspx">
</asp:TreeNode>
<asp:TreeNode Text = "Constructor Overloading" Value = "GREEN"
NavigateUrl="~/Home.aspx"></asp:TreeNode>
<asp:TreeNode NavigateUrl="~/Home.aspx" Text="Inheritance"
Value="BLUE"></asp:TreeNode>
<asp:TreeNode NavigateUrl="~/~/Home.aspx" Text="Class Properties" Value="Class
Properties"></asp:TreeNode>

</asp:TreeNode>
</Nodes>
<NodeStyle Font-Names="Tahoma" Font-Size="10pt" ForeColor="Black"
HorizontalPadding="5px" NodeSpacing="0px" VerticalPadding="0px" />
<ParentNodeStyle Font-Bold="False" />
<SelectedNodeStyle Font-Underline="True" ForeColor="#5555DD"
HorizontalPadding="0px" VerticalPadding="0px" />
</asp:TreeView>
<br />
Fetch Datalist Using XML data : </div>
<asp:DataList ID="DataList1" runat="server">
<ItemTemplate>
<table class = "table" border="1">
<tr>
<td>Roll Num : <%# Eval("sid") %><br />
Name : <%# Eval("sname") %><br />
Class : <%# Eval("sclass")%>
</td>
</tr>
</table>
</ItemTemplate>
</asp:DataList>

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

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>

Default2.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 _3b
{
public partial class _default : 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();
}

}
}
}

Home.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Home.aspx.cs"
Inherits="_3b.Home" %>

<!DOCTYPE html>

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

Output:
Practical 4

4. Working with Form Controls.


a. Create a Registration form to demonstrate use of various Validation controls.
Code:-
Webform.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs"
Inherits="_4A.WebForm1" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<style type="text/css">
.auto-style1
{ width: 72%;
background-color: #C0C0C0;
}
.auto-style2
{ width: 357px;
text-align: right;
}
.auto-style3
{ width: 357px;
text-align: right;
height: 30px;
}
.auto-style4
{ height: 30px;
width: 445px;
}
.auto-style5 {
width: 445px;
}
.auto-style6
{ width: 357px;
text-align: right;
height: 21px;
}
.auto-style7
{ width: 445px;
height: 21px;
}
</style>
</head>
<body>
<center> Registration form with validation</center>
<form id="form1" runat="server">

<table align="center" class="auto-style1">


<tr>
<td class="auto-style3">First Name</td>
<td class="auto-style4">
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server"
ControlToValidate="TextBox1" ErrorMessage="First Name is required"
ForeColor="Red"></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td class="auto-style2">Last Name</td>
<td class="auto-style5">
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server"
ControlToValidate="TextBox2" ErrorMessage="Last Name is required"
ForeColor="Red"></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td class="auto-style2">Email Id</td>
<td class="auto-style5">
<asp:TextBox ID="TextBox3" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server"
ControlToValidate="TextBox3" ErrorMessage="EmailId is required"
ForeColor="Red"></asp:RequiredFieldValidator>
&nbsp;&nbsp;
<asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server"
ErrorMessage="Email Id should be valid" ForeColor="#0000CC"
ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"
ControlToValidate="TextBox3" Enabled="False"></asp:RegularExpressionValidator>
</td>
</tr>
<tr>
<td class="auto-style2">Password</td>
<td class="auto-style5">
<asp:TextBox ID="TextBox4" runat="server"
TextMode="Password"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator4" runat="server"
ControlToValidate="TextBox4" ErrorMessage="Password is required"
ForeColor="Red"></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td class="auto-style2">Re-Type Password</td>
<td class="auto-style5">
<asp:TextBox ID="TextBox5" runat="server"
TextMode="Password"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator5" runat="server"
ControlToValidate="TextBox5" ErrorMessage="Re-type Password"
ForeColor="Red"></asp:RequiredFieldValidator>
&nbsp;<asp:CompareValidator ID="CompareValidator1" runat="server"
ControlToCompare="TextBox4" ControlToValidate="TextBox5" ErrorMessage="Same
Password required" ForeColor="#0033CC"></asp:CompareValidator>
</td>
</tr>
<tr>
<td class="auto-style3">Age</td>
<td class="auto-style4">
<asp:TextBox ID="TextBox6" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator6" runat="server"
ControlToValidate="TextBox6" ErrorMessage="Age is required"
ForeColor="Red"></asp:RequiredFieldValidator>
&nbsp;<asp:RangeValidator ID="RangeValidator1" runat="server"
ControlToValidate="TextBox6" ErrorMessage="&gt;18 and &lt;30" ForeColor="#0033CC"
MaximumValue="30" MinimumValue="18" Type="Integer"></asp:RangeValidator>
</td>
</tr>
<tr>
<td class="auto-style2">Mobile Number</td>
<td class="auto-style5">
<asp:TextBox ID="TextBox7" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator7" runat="server"
ControlToValidate="TextBox7" ErrorMessage="Mobile no is required"
ForeColor="Red"></asp:RequiredFieldValidator>
&nbsp;
<asp:RegularExpressionValidator ID="RegularExpressionValidator2" runat="server"
ErrorMessage="MobileNo should be valid" ForeColor="#0000CC"
ValidationExpression="\d{10}"
ControlToValidate="TextBox7"></asp:RegularExpressionValidator>
</td>
</tr>
</tr>
<tr>
<td class="auto-style6">UserID</td>
<td class="auto-style7">
<asp:TextBox ID="TextBox8" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator8" runat="server"
ControlToValidate="TextBox8" ErrorMessage="UserId is required"
ForeColor="Red"></asp:RequiredFieldValidator>
&nbsp;
<asp:CustomValidator ID="CustomValidator1" runat="server"
ErrorMessage="UserId atleast &gt;3charachter" ForeColor="Blue"
ValidateEmptyText="True"
OnServerValidate="CustomValidator1_ServerValidate1"></asp:CustomValidator>
</td>
</tr>
<tr>
<td class="auto-style2">&nbsp;</td>
<td class="auto-style5">&nbsp;</td>
</tr>
<tr>
<td class="auto-style2">&nbsp;</td>
<td class="auto-style5">
<asp:Button ID="btnS" runat="server" Text="Register Now" />
</td>
</tr>
<tr>
<td class="auto-style2">&nbsp;</td>
<td class="auto-style5">
<asp:ValidationSummary ID="ValidationSummary1" runat="server"
ForeColor="Red" />
</td>
</tr>
<tr>
<td class="auto-style2">&nbsp;</td>
<td class="auto-style5">
&nbsp;</td>
</tr>
</table>

</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 _4A
{
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

protected void Button1_Click(object sender, EventArgs e)


{

protected void CustomValidator1_ServerValidate(object source,


ServerValidateEventArgs args)
{
string cust_val = args.Value;
args.IsValid = false; if
((cust_val.Length)>3)
{
args.IsValid = true;
return;
}

protected void CustomValidator1_ServerValidate1(object source,


ServerValidateEventArgs args)
{

}
}
}
Output:

b. Create Web Form to demonstrate use of Adrotator Control.


Code:
adrotorcontrol.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="adrotorcontrol.aspx.cs"
Inherits="_4B.adrotorcontrol" %>

<!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" Target="_blank"
AdvertisementFile="~/ADdata.xml" OnAdCreated="AdRotator1_AdCreated" />
</div>
</form>
</body>
</html>

<%-- --%>
ADdata.xml
<?xml version="1.0" encoding="utf-8" ?>
<Advertisements>
<Ad>
<ImageUrl>~/Images/insta.png</ImageUrl>

<NavigateUrl>https://www.arcgis.com/apps/opsdashboard/index.html#/bda7594740f
d40299423467b48e9ecf6</NavigateUrl>
<AlternateText>Please visit https://www.instagram.com</AlternateText>
<Impressions>30</Impressions>
<Keyword>Instagram</Keyword>
</Ad>

<Ad>
<ImageUrl>~/Images/you.png</ImageUrl>
<NavigateUrl>https://www.youtube.com/</NavigateUrl>
<AlternateText>Please visit https://www.youtube.com</AlternateText>
<Impressions>20</Impressions>
<Keyword>Youtube</Keyword>
</Ad>
</Advertisements>

Output:
c. Create Web Form to demonstrate use of User Controls.
Code:-
login.ascx
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="login.ascx.cs"
Inherits="_4C.MyCntrl.login" %>
<style type="text/css"> .auto-
style2 {
width: 100%;
}
.auto-style3 {
width: 426px;
}
.auto-style4 { margin-
left: 0px;
}
.auto-style5 {
width: 20px;
}
</style>

<table class="auto-style2">
<tr>
<td class="auto-style5">Username</td>
<td class="auto-style3">
<asp:TextBox ID="usertxt" runat="server" Width="143px"
OnTextChanged="usertxt_TextChanged" ValidationGroup="lv"
CssClass="autostyle4"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server"
ControlToValidate="usertxt" ForeColor="Red"
ValidationGroup="lv">*</asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td class="auto-style5">Password</td>
<td class="auto-style3">
<asp:TextBox ID="passtxt" runat="server" Width="143px"
ValidationGroup="lv"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server"
ControlToValidate="passtxt" ForeColor="Red"
ValidationGroup="lv">*</asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td class="auto-style5"></td>
<td class="auto-style3">
<asp:Button ID="Button1" runat="server" Text="Login" Width="65px"
ValidationGroup="lv" />
</td>
</tr>
</table>

register.ascx
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="register.ascx.cs"
Inherits="_4C.MyCntrl.WebUserControl1" %>
<style type="text/css">

.auto-style6 {
width: 107px;
}
.auto-style5
{ width: 109px;
}
</style>

<table style="width:100%;">
<tr>
<td class="auto-style6">Username</td>
<td>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td class="auto-style6">Password</td>
<td>
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td class="auto-style6">Renter-Password</td>
<td>
<asp:TextBox ID="TextBox3" runat="server"></asp:TextBox>
</td>
</tr>
</table>
<table style="width:100%;">
<tr>
<td class="auto-style6">Email</td>
<td>
<asp:TextBox ID="TextBox4" runat="server"></asp:TextBox>
</td>
</tr>
</table>
<table style="width:100%;">
<tr>
<td class="auto-style5">&nbsp;</td>
<td>
<asp:Button ID="Button1" runat="server" Text="Register" Width="77px" />
</td>
</tr>
</table>

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

<%@ Register src="MyCntrl/login.ascx" tagname="login" tagprefix="uc1" %>


<%@ Register src="MyCntrl/register.ascx" tagname="register" tagprefix="uc2" %>

<!DOCTYPE html>
<script runat="server">
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<uc1:login ID="login1" runat="server" />
</div>
<uc2:register ID="register1" runat="server" />
</form>
</body>
</html>

Output:

Practical 5
Working with Navigation, Beautification and Master page.
a. Create Web Form to demonstrate use of Website Navigation controls and Site Map.
Code:
Webform1.aspx:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs"
Inherits="_5a.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:SiteMapPath ID="SiteMapPath1" runat="server">
</asp:SiteMapPath>
<br />
<br />
<asp:Menu ID="Menu1" runat="server" DataSourceID="SiteMapDataSource1">
</asp:Menu>
<br />
<asp:SiteMapDataSource ID="SiteMapDataSource1" runat="server" />
</div>
</form>
</body>
</html>
Webform2.aspx:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm2.aspx.cs"
Inherits="_5a.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:SiteMapPath ID="SiteMapPath1" runat="server">
</asp:SiteMapPath><br/>
Welcome to Online Store
</div>

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

Webform.aspx:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm2.aspx.cs"
Inherits="_5a.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:SiteMapPath ID="SiteMapPath1" runat="server">
</asp:SiteMapPath><br/>
Welcome to Online Store
</div>

</form>
</body>
</html>
Webform3.aspx:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm3.aspx.cs"
Inherits="_5a.WebForm3" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:SiteMapPath ID="SiteMapPath1" runat="server">
</asp:SiteMapPath><br/>
Hii Welcome to online shopping : Mobiles
</div>
</form>

</body>
</html>

Output
:
b. Create a web application to demonstrate use of Master Page with applying Styles and Themes for
page beautification.
Code:
MasterPage.Master:
<%@ Master Language="C#" AutoEventWireup="true" CodeBehind="MasterPage.master.cs"
Inherits="Masterpage5a.MasterPage" %>

<!DOCTYPE html>
<html>
<head runat="server">
<title>Master Page Demo</title>
<link href="StyleSheet1.css" rel="stylesheet" />
<asp:ContentPlaceHolder ID="head" runat="server">
</asp:ContentPlaceHolder>
<style type="text/css">
.auto-style1 {
position: absolute;
top: 373px;
left: 1028px;
bottom: 303px;
}
.auto-style2 {
position: absolute;
top: 537px;
left: 1016px;
z-index: 1;
}
</style>
</head>
<body>
<!DOCTYPE html>
<form id="form1" runat="server">
<html>
<head>
<title>Master</title>
<link rel="stylesheet" type="text/css" href="StyleSheet.css">
</head>
<body>
<header id="header">
<h1>Demo Of Master Page</h1>
</header>
<nav id="nav">
<ul>
<li><a href="Hello.aspx">Insight</a></li>
<li><a href="#">Products</a></li>
<li><a href="#">Downloads</a></li>
<li><a href="#">Contact Us</a></li>
</ul>
</nav>
<aside id="side">
<h1>Info</h1>
<a href="#"><p>Product Type 1</p></a>
<a href="#"><p>Product Type 2</p></a>
<a href="#"><p>Product Type 3<a href="#"><asp:ScriptManager ID="ScriptManager1"
runat="server">
</asp:ScriptManager>
</a>
</p>
</aside>
<div id="con">
<asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server">
</asp:ContentPlaceHolder>
</div>
<footer id="footer">
copyright @MyWorld
</footer>
</body>
</html>
</form>
</body>
</html>

StyleSheet1.css
#header {
color: blueviolet;
text-align: center;
font-size: 20px;
}

#nav {
background-color: darkseagreen;
padding: 5px;
}
ul {
list-style-type: none;
}

li a {
color: crimson;
font-size: 30px;
column-width: 5%;
}

li {
display: inline;
padding-left: 2px;
column-width: 20px;
}

a{
text-decoration: none;
margin-left: 20px
}

li a:hover {
background-color: aqua;
color: coral;
padding: 1%;
}

#side {
text-align: center;
float: right;
width: 15%;
padding-bottom: 79%;
background-color: #F1FAEE;
}

#article {
background-color: burlywood;
padding: 10px;
padding-bottom: 75%;
}
#footer {
background-color: #C7EFCF;
text-align: center;
padding-bottom: 5%;
font-size: 20px;
}

#con {
border: double;
border-color: burlywood;
}
Hello.aspx:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Hello.aspx.cs"
Inherits="Masterpage5a.WebForm1" %>

<!DOCTYPE html>

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

Home.aspx:
<%@ Page Title="" Language="C#" MasterPageFile="~/MasterPage.Master"
AutoEventWireup="true" CodeBehind="Home.aspx.cs" Inherits="Masterpage5a.Home" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1"
runat="server"><h1>Home page</h1>
</asp:Content>

Output:

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


WebForm1.aspx:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs"
Inherits="_5c.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:HiddenField ID="HiddenField1" runat="server" Value="2" />
<br />
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
<br />
<br />
<asp:Label ID="Label2" runat="server" Text="Label"></asp:Label>
<br />
<br />
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="View State" />
<br />
<br />
<asp:Button ID="Button2" runat="server" OnClick="Button2_Click" Text="Hidden Feild" />
<br />
<br />
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<br />
<br />
<asp:Button ID="Button3" runat="server" OnClick="Button3_Click" Text="Cookies" />
</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 _5c
{
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if(IsPostBack)
{
if(ViewState["count"] != null)
{
int ViewStateVal = Convert.ToInt32(ViewState["count"]) + 1;
Label2.Text = "View State:" + ViewStateVal.ToString();
ViewState["count"] = ViewStateVal.ToString();
}
else
{
ViewState["count"] = "1";
}
}
}

protected void Button1_Click(object sender, EventArgs e)


{
Label1.Text = ViewState["count"].ToString();
}

protected void Button2_Click(object sender, EventArgs e)


{
if(HiddenField1.Value!=null)
{
int val = Convert.ToInt32(HiddenField1.Value) + 1;
HiddenField1.Value = val.ToString();
}
}

protected void Button3_Click(object sender, EventArgs e)


{
HttpCookie h = new HttpCookie("name");
h.Value = TextBox1.Text;
Response.Cookies.Add(h);
Response.Redirect("WebForm2.aspx");
}
}
}
WebForm2.aspx:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm2.aspx.cs"
Inherits="_5c.WebForm2" %>

<!DOCTYPE html>

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

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

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
</div>
</form>
</body>
</html>
Output:
Practical 6
6.Working with Database.
a. Create a web application bind data in a multiline textbox by querying in another textbox.
Code:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="bindtext.aspx.cs"
Inherits="WebApplication8.bindtext" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:TextBox ID="TextBox1" Text="<%#textdata %>" runat="server"
Height="121px" TextMode="MultiLine" Width="266px" CausesValidation="False"
OnTextChanged="TextBox1_TextChanged" ></asp:TextBox>
<asp:TextBox ID="TextBox2" runat="server" AutoPostBack="True"
OnTextChanged="TextBox2_TextChanged"></asp:TextBox>
</div>
</form>
</body>
</html>

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 bindtext : System.Web.UI.Page
{
public string textdata;
protected void Page_Load(object sender, EventArgs e)
{

protected void TextBox2_TextChanged(object sender, EventArgs e)


{
textdata = TextBox2.Text;
this.DataBind();
}

protected void TextBox1_TextChanged(object sender, EventArgs e)


{

}
}
}

Output:
+

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


Code:
WebForm1.aspx:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs"
Inherits="_6b.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:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<br />
<br />
<asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" />
<br />
<br />
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
</div>
</form>
</body>
</html>

WebForm1.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 _6b
{
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

protected void Button1_Click(object sender, EventArgs e)


{
string conn =
ConfigurationManager.ConnectionStrings["EmployeeConnectionString"].ConnectionString;
SqlConnection con = new SqlConnection(conn);
string query = "SELECT Address FROM empRegister WHERE UserID='" + TextBox1.Text + "'";
con.Open();
SqlCommand cmd = new SqlCommand(query, con);
Label1.Text = cmd.ExecuteScalar().ToString();
con.Close();
}
}

Output:
c. Demonstrate the use of Datalist link control.
Code:
WebForm1.aspx:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs"
Inherits="_6c.WebForm1" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<style type="text/css">
.auto-style1 {
color: #800000;
font-size: x-large;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$
ConnectionStrings:EmployeeConnectionString %>" SelectCommand="SELECT * FROM
[empRegister]"></asp:SqlDataSource>
<h1><strong><span class="auto-style1">&nbsp;DataList </span>
<br class="auto-style1" />
</strong></h1>
<asp:DataList ID="DataList1" runat="server" DataKeyField="UserID"
DataSourceID="SqlDataSource1">
<ItemTemplate>
First Name:
<asp:Label ID="First_NameLabel" runat="server" Text='<%# Eval("[First Name]") %>' />
<br />
Last Name:
<asp:Label ID="Last_NameLabel" runat="server" Text='<%# Eval("[Last Name]") %>' />
<br />
UserID:
<asp:Label ID="UserIDLabel" runat="server" Text='<%# Eval("UserID") %>' />
<br />
EmailId:
<asp:Label ID="EmailIdLabel" runat="server" Text='<%# Eval("EmailId") %>' />
<br />
Paasword:
<asp:Label ID="PaaswordLabel" runat="server" Text='<%# Eval("Paasword") %>' />
<br />
Mobile No:
<asp:Label ID="Mobile_NoLabel" runat="server" Text='<%# Eval("[Mobile No]") %>' />
<br />
Address:
<asp:Label ID="AddressLabel" runat="server" Text='<%# Eval("Address") %>' />
<br />
<br />
</ItemTemplate>
</asp:DataList>
</div>
</form>
</body>
</html>

Output:
Practical 7
7. Working with Database
a. Create a web application to display Data Binding using dropdownlist control.
Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

namespace prac7a
{
public partial class example : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
DataSet studs = new DataSet();
studs.Tables.Add(new DataTable("student"));
studs.Tables["student"].Columns.Add(new DataColumn("rollno"));
studs.Tables["student"].Columns.Add(new DataColumn("name"));
studs.Tables["student"].Columns.Add(new DataColumn("class"));
studs.Tables["student"].Columns.Add(new DataColumn("phone"));
studs.Tables["student"].Columns.Add(new DataColumn("email"));

DataRow dr = studs.Tables["student"].NewRow();
dr["rollno"] = "1";
dr[1] = "Sam";
dr[2] = "it";
dr[3] = "6523236521";
dr[4] = "[email protected]";
studs.Tables["student"].Rows.Add(dr);

dr = studs.Tables["student"].NewRow();
dr["rollno"] = "2";
dr[1] = "Tam";
dr[2] = "it";
dr[3] = "65235323212";
dr[4] = "[email protected]";
studs.Tables["student"].Rows.Add(dr);

GridView1.DataSource = studs.Tables["student"];
GridView1.DataBind();

DropDownList1.DataSource = studs.Tables["student"];
DropDownList1.DataTextField = "name";
DropDownList1.DataValueField = "rollno";
DropDownList1.DataBind();

}
}
}

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


Inherits="prac7a.example" %>

<!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">
</asp:GridView>
<asp:DropDownList ID="DropDownList1" runat="server">
</asp:DropDownList>
<br />
</div>
</form>
</body>
</html>
Output:

b. Create a web application for to display the phone no of an author using database.
Code:
WebForm1.aspx:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs"
Inherits="__7a.WebForm1" %>

<!DOCTYPE html>

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

Select&nbsp; Your UserId To Get&nbsp; Phone Number :&nbsp;


<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
&nbsp;<br />
<br />
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Get Phone No." />
<br />
<br />
Your Phone No is : <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>

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

WebForm1.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 __7a
{
public partial class WebForm1 : System.Web.UI.Page
{
string conn =
ConfigurationManager.ConnectionStrings["EmployeeConnectionString2"].ConnectionString;
protected void Page_Load(object sender, EventArgs e)
{

protected void Button1_Click(object sender, EventArgs e)


{
SqlConnection con = new SqlConnection(conn);
string query = "SELECT Mobile FROM empRegister WHERE UserId='" + TextBox1.Text + "'";
SqlCommand cmd = new SqlCommand(query, con);
con.Open();
Label1.Text = cmd.ExecuteScalar()+ " ";
}
}
}

Output:
c. Create a web application for inserting and deleting record from a database. (Using Execute-Non
Query)
Code :
WebForm1.aspx:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs"
Inherits="DataBase.WebForm1" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<table>
<tr>
<td>
<asp:Label ID="Label2" runat="server" Text="Id"></asp:Label>
</td>
<td colspan="2">
<asp:TextBox ID="txtId" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td>
<asp:Label ID="Label1" runat="server" Text="Name"></asp:Label>
</td>
<td colspan="2">
<asp:TextBox ID="txtname" runat="server"></asp:TextBox>
</td>
</tr>

<tr>
<td>
<asp:Label ID="Label3" runat="server" Text="EmailD"></asp:Label>
</td>
<td colspan="2">
<asp:TextBox ID="txtmail" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td>
<asp:Label ID="Label4" runat="server" Text="Password"></asp:Label>
</td>
<td colspan="2">
<asp:TextBox ID="txtpass" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td>

</td>
<td colspan="2">
<asp:Button ID="btnsave" runat="server" Text="Insert" OnClick="btnsave_Click" />
<asp:Button ID="delete" runat="server" Text="Delete" OnClick="Delete_Click" />
<asp:Button ID="btnclear" runat="server" Text="Update" OnClick="btnclear_Click" />
</td>
</tr>
<tr>
<td>

</td>
<td colspan="2">
<asp:Label ID="lblSuccessmessage" runat="server" Text="Label"
ForeColor="#009900"></asp:Label>
</td>
</tr>
<tr>
<td>
</td>
<td colspan="2">
&nbsp;</td>
</tr>
</table>
<br />

<br />
<asp:GridView ID="GridView2" runat="server" AutoGenerateColumns="False"
DataKeyNames="Id" DataSourceID="SqlDataSource2">
<Columns>
<asp:BoundField DataField="Id" HeaderText="Id" ReadOnly="True"
SortExpression="Id" />
<asp:BoundField DataField="Name" HeaderText="Name" SortExpression="Name" />
<asp:BoundField DataField="Email" HeaderText="Email" SortExpression="Email" />
<asp:BoundField DataField="Password" HeaderText="Password"
SortExpression="Password" />
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$
ConnectionStrings:StudentConnectionString2 %>" SelectCommand="SELECT * FROM
[st_info]"></asp:SqlDataSource>
<br />
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$
ConnectionStrings:StudentConnectionString %>" SelectCommand="SELECT * FROM
[st_info]"></asp:SqlDataSource>
</div>

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

WebForm1.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 DataBase
{
public partial class WebForm1 : System.Web.UI.Page
{
string conn =
ConfigurationManager.ConnectionStrings["StudentConnectionString"].ConnectionString;
protected void Page_Load(object sender, EventArgs e)
{

}
public void Binds()
{
SqlConnection con = new SqlConnection(conn);
con.Open();
SqlCommand cmd = new SqlCommand("select * from st_info ", con);
SqlDataReader rd = cmd.ExecuteReader();
GridView2.DataSource = rd;
GridView2.DataBind();
lblSuccessmessage.Text = "Record Found";
con.Close();
}

protected void btnsave_Click(object sender, EventArgs e)


{
int added = 0;
SqlConnection con = new SqlConnection(conn);
con.Open();
SqlCommand cmd = new SqlCommand("insert into st_info(Id,Name,Email,Password) values
(@Id,@Name,@Email,@Password)", con);
cmd.Parameters.AddWithValue("@Id", txtId.Text);
cmd.Parameters.AddWithValue("@Name", txtname.Text);
cmd.Parameters.AddWithValue("@Email", txtmail.Text);
cmd.Parameters.AddWithValue("@Password", txtpass.Text);

try
{
added = cmd.ExecuteNonQuery();
lblSuccessmessage.Text = added+"Record Inserted Successfully";

}
catch(Exception e1)
{
lblSuccessmessage.Text = e1.Message;
}
if(added<0)
{
Binds();
con.Close();
}
txtId.Text = " ";
txtname.Text = " ";
txtmail.Text = " ";
txtpass.Text = " ";

protected void Delete_Click(object sender, EventArgs e)


{
int deleted = 0;
SqlConnection con = new SqlConnection(conn);
con.Open();
SqlCommand cmd = new SqlCommand("delete from st_info where Id=@Id ", con);
try
{
cmd.Parameters.AddWithValue("@Id", txtId.Text);
deleted = cmd.ExecuteNonQuery();
lblSuccessmessage.Text = deleted + "Record Deleted SuccessFully";
}
catch (Exception e1)
{
lblSuccessmessage.Text = e1.Message;
}
if (deleted <0)
{
Binds();
con.Close();
}
}

protected void btnclear_Click(object sender, EventArgs e)


{
int added = 0;
SqlConnection con = new SqlConnection(conn);
con.Open();
SqlCommand cmd = new SqlCommand("Update st_info set Name=@Name where
(Password=@Password)", con);
cmd.Parameters.AddWithValue("@Name", txtname.Text);
cmd.Parameters.AddWithValue("@Password", txtpass.Text);
try
{
added = cmd.ExecuteNonQuery();
lblSuccessmessage.Text = added + "Record Updated Successfully";

}
catch (Exception e1)
{
lblSuccessmessage.Text = e1.Message;
}
if (added < 0)
{
Binds();
con.Close();
}
txtId.Text = " ";
txtname.Text = " ";
txtmail.Text = " ";
txtpass.Text = " ";

}
}
}

Output:
Practical 8

8. Working with data control


a. Create a web application to demonstrate various uses and properties of SqlDataSource.
Code:
webform2.aspx:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm2.aspx.cs"
Inherits="_8a.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:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$
ConnectionStrings:EmployeeConnectionString %> "
SelectCommand="SELECt * FROM empRegister"
UpdateCommand="Update empRegister SET
First_Name=@First_Name,Last_Name=@Last_Name,EmailId=@EmailId,Mobile=@Mobile ,Address=
@Address WHERE UserID=@UserID">

</asp:SqlDataSource>

<br />
</div>
<asp:GridView ID="GridView1" runat="server" AllowSorting="True"
AutoGenerateColumns="False" AutoGenerateEditButton="True" AutoGenerateSelectButton="True"
CellPadding="4" DataKeyNames="UserID" DataSourceID="SqlDataSource1" ForeColor="#333333"
GridLines="None" AllowPaging="True">
<AlternatingRowStyle BackColor="White" ForeColor="#284775" />
<Columns>
<asp:BoundField DataField="First_Name" HeaderText="First_Name"
SortExpression="First_Name" />
<asp:BoundField DataField="Last_Name" HeaderText="Last_Name"
SortExpression="Last_Name" />
<asp:BoundField DataField="UserID" HeaderText="UserID" ReadOnly="True"
SortExpression="UserID" />
<asp:BoundField DataField="EmailId" HeaderText="EmailId" SortExpression="EmailId" />
<asp:BoundField DataField="Paasword" HeaderText="Paasword"
SortExpression="Paasword" />
<asp:BoundField DataField="Mobile" HeaderText="Mobile" SortExpression="Mobile" />
<asp:BoundField DataField="Address" HeaderText="Address" SortExpression="Address" />
</Columns>
<EditRowStyle BackColor="#999999" />
<FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
<RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
<SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
<SortedAscendingCellStyle BackColor="#E9E7E2" />
<SortedAscendingHeaderStyle BackColor="#506C8C" />
<SortedDescendingCellStyle BackColor="#FFFDF8" />
<SortedDescendingHeaderStyle BackColor="#6F8DAE" />
</asp:GridView>
</form>
</body>
</html>

Output:

After Updating:

b. Create a web application to demonstrate data binding using DetailsView and FormView Control.
Code:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs"
Inherits="_8a.WebForm1" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<asp:DetailsView ID="DetailsView1" runat="server" AllowPaging="True"
AutoGenerateRows="False" BackColor="#DEBA84" BorderColor="#DEBA84" BorderStyle="None"
BorderWidth="1px" CellPadding="3" CellSpacing="2" DataKeyNames="Id"
DataSourceID="SqlDataSource1" Height="50px" Width="125px">
<EditRowStyle BackColor="#738A9C" Font-Bold="True" ForeColor="White" />
<Fields>
<asp:BoundField DataField="Id" HeaderText="Id" ReadOnly="True" SortExpression="Id" />
<asp:BoundField DataField="Name" HeaderText="Name" SortExpression="Name" />
<asp:BoundField DataField="Email" HeaderText="Email" SortExpression="Email" />
<asp:BoundField DataField="Password" HeaderText="Password"
SortExpression="Password" />
</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="SqlDataSource1" runat="server" ConnectionString="<%$
ConnectionStrings:StudentConnectionString2 %>" SelectCommand="SELECT * FROM
[st_info]"></asp:SqlDataSource>
</form>
</body>
</html>

Output:

c. Create a web application to display Using Disconnected Data Access and Databinding using
GridView.
Code:
Webform2.aspx:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm2.aspx.cs"
Inherits="__7a.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:DropDownList ID="DropDownList1" runat="server" DataSourceID="SqlDataSource1"
DataTextField="First_Name" DataValueField="UserID">
</asp:DropDownList>
<br />
<br />
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Click" />
<br />
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$
ConnectionStrings:EmployeeConnectionString %>" SelectCommand="SELECT * FROM
[empRegister]"></asp:SqlDataSource>
<br />
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
<br />
<asp:GridView ID="GridView1" runat="server" CellPadding="4" ForeColor="#333333"
GridLines="None">
<AlternatingRowStyle BackColor="White" />
<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>
</form>
</body>
</html>
Webform2.aspx.cs:
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 __7a
{
public partial class WebForm2 : System.Web.UI.Page
{
string conn =
ConfigurationManager.ConnectionStrings["EmployeeConnectionString"].ConnectionString;

protected void Page_Load(object sender, EventArgs e)


{

protected void Button1_Click(object sender, EventArgs e)


{
SqlConnection con = new SqlConnection(conn);
SqlCommand cmd = new SqlCommand("select * from empRegister where UserId='" +
DropDownList1.SelectedValue + "'", con);
SqlDataAdapter adpt = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
adpt.Fill(dt);
GridView1.DataSource = dt;
GridView1.DataBind();
Label1.Text = "Record Found";
}
}
}
Output:

Practical 9

9 Working with GridView control


a. Create a web application to demonstrate use of GridView control template and
GridView hyperlink.

Code:

webform1.aspx:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm2.aspx.cs"
Inherits="_9a.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" Font-Bold="True" Font-Size="X-Large"


Text="UNIVERSITY OF MUMBAI"></asp:Label>

            <br />

            Study Material :<br />

            <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"


BackColor="White" BorderColor="#3366CC" BorderStyle="None" BorderWidth="1px"
CellPadding="4" DataSourceID="SqlDataSource1">

                <Columns>

                    <asp:BoundField DataField="Sno" HeaderText="S.No"


SortExpression="Sno" />

                    <asp:BoundField DataField="TopicName" HeaderText="Topic Name"


SortExpression="TopicName" />

                    <asp:TemplateField HeaderText="Description" SortExpression="Description">

                        <EditItemTemplate>

                            <asp:TextBox ID="TextBox1" runat="server" Text='<%#


Bind("Description") %>'></asp:TextBox>

                        </EditItemTemplate>

                        <ItemTemplate>

                            <asp:Label ID="Label1" runat="server" Text='<%# Bind("Description")


%>'></asp:Label>
                        </ItemTemplate>

                    </asp:TemplateField>

                    <asp:HyperLinkField DataNavigateUrlFields="TopicName"
HeaderText="Download File" Target="_blank" Text="download"
DataNavigateUrlFormatString="~\download\AWPpdf" DataTextField="DownLoadFile">

                    <ItemStyle BackColor="#33CCFF" />

                    </asp:HyperLinkField>

                </Columns>

                

                <FooterStyle BackColor="#99CCCC" ForeColor="#003399" />

                <HeaderStyle BackColor="#003399" Font-Bold="True" ForeColor="#CCCCFF" />

                <PagerStyle BackColor="#99CCCC" ForeColor="#003399" HorizontalAlign="Left"


/>

                <RowStyle BackColor="White" ForeColor="#003399" />

                <SelectedRowStyle BackColor="#009999" Font-Bold="True"


ForeColor="#CCFF99" />

                <SortedAscendingCellStyle BackColor="#EDF6F6" />

                <SortedAscendingHeaderStyle BackColor="#0D4AC4" />

                <SortedDescendingCellStyle BackColor="#D6DFDF" />

                <SortedDescendingHeaderStyle BackColor="#002876" />

            </asp:GridView>

            <br />

            <br />

            <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$


ConnectionStrings:EmployeeConnectionString4 %>" SelectCommand="SELECT * FROM
[Table_1]"></asp:SqlDataSource>

        </div>

    </form>

</body>

</html>
Output:

b.Create a web application to demonstrate use of GridView button column and


GridView events.
Code:
Webform2.aspx:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs"
Inherits="_9a.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" AutoGenerateColumns="False"
BackColor="White" BorderColor="#999999" BorderStyle="None" BorderWidth="1px"
CellPadding="3" DataKeyNames="UserID" DataSourceID="SqlDataSource1"
GridLines="Vertical">
                <AlternatingRowStyle BackColor="#DCDCDC" />
                <Columns>
                    <asp:BoundField DataField="First_Name" HeaderText="First_Name"
SortExpression="First_Name" />
                    <asp:BoundField DataField="Last_Name" HeaderText="Last_Name"
SortExpression="Last_Name" />
                    <asp:BoundField DataField="UserID" HeaderText="UserID" ReadOnly="True"
SortExpression="UserID" />
                    <asp:BoundField DataField="EmailId" HeaderText="EmailId"
SortExpression="EmailId" />
                    <asp:BoundField DataField="Paasword" HeaderText="Paasword"
SortExpression="Paasword" />
                    <asp:BoundField DataField="Mobile" HeaderText="Mobile"
SortExpression="Mobile" />
                    <asp:BoundField DataField="Address" HeaderText="Address"
SortExpression="Address" />
                </Columns>
                <FooterStyle BackColor="#CCCCCC" ForeColor="Black" />
                <HeaderStyle BackColor="#000084" Font-Bold="True" ForeColor="White" />
                <PagerStyle BackColor="#999999" ForeColor="Black"
HorizontalAlign="Center" />
                <RowStyle BackColor="#EEEEEE" ForeColor="Black" />
                <SelectedRowStyle BackColor="#008A8C" Font-Bold="True"
ForeColor="White" />
                <SortedAscendingCellStyle BackColor="#F1F1F1" />
                <SortedAscendingHeaderStyle BackColor="#0000A9" />
                <SortedDescendingCellStyle BackColor="#CAC9C9" />
                <SortedDescendingHeaderStyle BackColor="#000065" />
            </asp:GridView>
            <br />
            <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$
ConnectionStrings:EmployeeConnectionString2 %>" SelectCommand="SELECT * FROM
[empRegister]"></asp:SqlDataSource>
        </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 _9a
{
    public partial class WebForm1 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, GridViewCommandEventArgs e)
        {
            if (e.CommandName == "b1")
            {
                Response.Write(e.CommandName);
                GridView1.SelectedRowStyle.BackColor = System.Drawing.Color.Brown;
                GridView1.Rows[Convert.ToInt16(e.CommandArgument)].BackColor =
System.Drawing.Color.Blue;
            }
        }
    }    }

Output:
c. Create a web application to demonstrate GridView paging and Creating own table
format using GridView.

Code:
paging.aspx:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="paging.aspx.cs"
Inherits="_9a.paging" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <style type="text/css">
        .auto-style1 {
            width: 100%;
            border-collapse: collapse;
            border-left-style: solid;
            border-left-width: 2px;
            border-right: 2px solid #C0C0C0;
            border-top-style: solid;
            border-top-width: 2px;
            border-bottom: 2px solid #C0C0C0;
            background-color: #FFFF00;
        }
        .auto-style2 {
            width: 465px;
        }
    </style>
</head>
<body>
    <form id="form1" runat="server">
        <div>
            <center>
            <table  class="auto-style1">
                <tr>
                    
                    <td style="font-size:x-large;font-weight:bold; background-color:#C0C0C0"
class="auto-style2"> Paging In GridView </td>
                  
                </tr>
                <tr>
                    <td class="auto-style2" style="background-color: #FFFFFF">
                        <asp:GridView ID="GridView1" runat="server" AllowPaging="True"
AllowSorting="True" AutoGenerateColumns="False" CellPadding="4"
DataKeyNames="UserID" DataSourceID="SqlDataSource1" ForeColor="#333333"
GridLines="None">
                            <AlternatingRowStyle BackColor="White" />
                            <Columns>
                                <asp:CommandField ShowSelectButton="True" />
                                <asp:BoundField DataField="First_Name" HeaderText="First_Name"
SortExpression="First_Name" />
                                <asp:BoundField DataField="Last_Name" HeaderText="Last_Name"
SortExpression="Last_Name" />
                                <asp:BoundField DataField="UserID" HeaderText="UserID"
ReadOnly="True" SortExpression="UserID" />
                                <asp:BoundField DataField="EmailId" HeaderText="EmailId"
SortExpression="EmailId" />
                                <asp:BoundField DataField="Paasword" HeaderText="Paasword"
SortExpression="Paasword" />
                                <asp:BoundField DataField="Mobile" HeaderText="Mobile"
SortExpression="Mobile" />
                                <asp:BoundField DataField="Address" HeaderText="Address"
SortExpression="Address" />
                            </Columns>
                            <FooterStyle BackColor="#990000" Font-Bold="True"
ForeColor="White" />
                            <HeaderStyle BackColor="#990000" Font-Bold="True"
ForeColor="White" />
                            <PagerStyle BackColor="#FFCC66" ForeColor="#333333"
HorizontalAlign="Center" />
                            <RowStyle BackColor="#FFFBD6" ForeColor="#333333" />
                            <SelectedRowStyle BackColor="#FFCC66" Font-Bold="True"
ForeColor="Navy" />
                            <SortedAscendingCellStyle BackColor="#FDF5AC" />
                            <SortedAscendingHeaderStyle BackColor="#4D0000" />
                            <SortedDescendingCellStyle BackColor="#FCF6C0" />
                            <SortedDescendingHeaderStyle BackColor="#820000" />

                        </asp:GridView>
                        <asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:EmployeeConnectionString5 %>"
ProviderName="System.Data.SqlClient" SelectCommand="SELECT * FROM
[empRegister]"></asp:SqlDataSource>
                    </td>
               </tr>
            </table>
            
        </div>
    </form>
</body>
</html>
Output:
P

 
Practical 11

Programs to create and use DLL


Class1.cs:-
using System;
usingSystem.Collections.Generic;
usingSystem.Linq;
usingSystem.Text;

namespace ClassLibrary5
{
publicclassClass1
{
publicint add(int a, int b)
{
int c = a + b;
return c;
}
}
}

Consoleapplication5.cs:-
using System;
usingSystem.Collections.Generic;
usingSystem.Linq;
usingSystem.Text;

namespace ConsoleApplication5
{
classProgram
{
staticvoid Main(string[] args)
{
ClassLibrary5.Class1 c = newClassLibrary5.Class1();
int t = c.add(1, 2);
Console.WriteLine("addition={0}", t);
Console.ReadKey();
}
}
}
11) output:-

You might also like