You are on page 1of 125

ANKIT TYAGI; ROLL NO 8990

INDEX
Practical Details Page No. Sign
No.

1. Working with basic C# and ASP .NET

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

b.Create an application to demonstrate string operations.

c.Programs to create and use DLL

. 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.
2. Working with Object Oriented C# and ASP .NET

Create simple application to demonstrate use of following concepts

i. Function Overloading
ii. Inheritance (all types)
iii. Constructor overloading
iv. Interfaces
v. Using Delegates and events
vi. Exception handling
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)
b. Demonstrate the use of Calendar control to perform following
operations.
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

4. Demonstrate the use of Tree view control performs following


operations.

1
ANKIT TYAGI; ROLL NO 8990

i. Tree view control and data list


ii. Tree view operations

5. Working with Form Controls

a. Create a Registration form to demonstrate use of various


Validation controls.

b. Create Web Form to demonstrate use of Ad rotator Control.

c. Create Web Form to demonstrate use of User Controls.

6. Working with Navigation, Beautification and Master page.

a. Create Web Form to demonstrate use of Website Navigation


controls and Site Map.
b. Create a web application to demonstrate the use of Master
Page with applying Styles and Themes for page
beautification.
c. Create a web application to demonstrate various states of
ASP.NET Pages.
7. Working with Database

a. Create a web application for inserting and deleting records


from a database..
b. Create a web application to display records by using a
database.
8. Working with Database
a. Create a web application to display Data binding using
dropdown list control.
9. Working with data controls
a. Create a web application to demonstrate various uses and
properties of SqlDataSource.
b. Create a web application to demonstrate data binding using
Details View and Form View Control.
c. Create a web application to display Using Disconnected Data
Access and Databinding using Grid View.

10. Working with GridView control

a. Create a web application to demonstrate use of GridView


control template and GridView hyperlink.
b. Create a web application to demonstrate use of GridView
button column and GridView events.
c. Create a web application to demonstrate GridView paging
and Create own table format using GridView.

2
ANKIT TYAGI; ROLL NO 8990

11. Working with AJAX and XML and Jquery

a. Create a web application to demonstrate reading and writing


operation with XML.
b. Create a web application to demonstrate different types of
selector.
c. Create a web application to demonstrate use of various Ajax
controls.

3
ANKIT TYAGI; ROLL NO 8990

PRACTICAL NO: 1
WORKING WITH BASIC C# AND ASP .NET

1A] Create an application that obtains four int values from the user and displays
the product.

Code:

4
ANKIT TYAGI; ROLL NO 8990

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

public class practical1


{
public static void Main()
{
Console.WriteLine("Enter first integer");
int a = int.Parse(Console.ReadLine());
Console.WriteLine("Enter Second integer");
int b = int.Parse(Console.ReadLine());
Console.WriteLine("Enter Third integer");
int c = int.Parse(Console.ReadLine());
Console.WriteLine("Enter forth integer");
int d = int.Parse(Console.ReadLine());
Console.WriteLine("The product of four integers is=" + (a * b * c * d ));
int e = int.Parse(Console.ReadLine());
}
}

Output:

1B] Create an application to demonstrate string operations.

Code:

5
ANKIT TYAGI; ROLL NO 8990

using System;
class Geeks
{

// Main Method
static void Main(string[] args)
{

// declare a string Name using


// "System.String" class
System.String Name;

// initialization of String
Name = "Shri";

// declare a string id using


// using an alias(shorthand)
// "String" of System.String
// class
String id;

// initialization of String
id = "33";

// declare a string mrk using


// string keyword
string mrk;

// initialization of String
mrk = "97";

// Declaration and initialization of


// the string in a single line
string rank = "1";

// Displaying Result
Console.WriteLine("Name: {0}", Name);
Console.ReadLine();
Console.WriteLine("Id: {0}", id);
Console.ReadLine();
Console.WriteLine("Marks: {0}", mrk);
Console.ReadLine();
Console.WriteLine("Rank: {0}", rank);
Console.ReadLine();
}
}

6
ANKIT TYAGI; ROLL NO 8990

Output:

1C] Programs to create and use DLL


1. Creating a DLL File:

7
ANKIT TYAGI; ROLL NO 8990

1. Open Visual Studio then select "File" -> "New" -> "Project..." then select "Visual C#"
-> "Class library".

2.  In the calculate class, write methods for the addition and subtraction of two
integers.

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

namespace Calculation
{
public class calculate

{
//method used for Addition
public int Add(int a, int b)
{
return a + b;
}

//Method used for subtraction


public int Sub(int a, int b)
{
return a - b;

8
ANKIT TYAGI; ROLL NO 8990

}
}
}

3. Build the solution (F6). If the build is successful then you will see a "calculation.dll"
file in the "bin/debug" directory of your project.

2. Using DLL File

Step 1 – Create "Windows Forms application" .

Step 2 - Design the form

9
ANKIT TYAGI; ROLL NO 8990

Step 3 - Add a reference for the dll file, "calculation.dll", that we created earlier.
Right- click on the project and then click on "Add reference".

Step 4 - Add the namespace ("using calculation;") and write the code.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;

10
ANKIT TYAGI; ROLL NO 8990

using System.Threading.Tasks;
using System.Windows.Forms;
using Calculation;

namespace WindowsFormsApplication3
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

calculate cal = new calculate();

private void guna2Button1_Click(object sender, EventArgs e)


{
try
{
//storing the result in int i
int i = cal.Add(int.Parse(txtFirstNo.Text), int.Parse(txtSecNo.Text));
txtResult.Text = i.ToString();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}

private void guna2Button2_Click(object sender, EventArgs e)


{
try
{
//storing the result in int i
int i = cal.Sub(int.Parse(txtFirstNo.Text), int.Parse(txtSecNo.Text));
txtResult.Text = i.ToString();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
}
}

Output:

1. Addition :

11
ANKIT TYAGI; ROLL NO 8990

2. Subtraction:

1D] 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.

12
ANKIT TYAGI; ROLL NO 8990

Code:

using System;

class Operations
{
public void fibonacci()
{

int n1=0,n2=1,n3,i,num;
Console.Write("Enter size of fibonacci series: ");
num = int.Parse(Console.ReadLine());
Console.Write(n1+""+n2+"");
for(i=2;i<num;++i)
{
n3=n1+n2;
Console.Write(n3+"");
n1=n2;
n2=n3;
}

public void prime_no()


{
int n, i, m=0, flag=0;
Console.Write("Enter the Number: ");
n = int.Parse(Console.ReadLine());
m=n/2;

for(i = 2; i <= m; i++)


{
if(n % i == 0)
{
Console.Write("Number is not Prime.");
flag=1;
break;
}
}
if (flag==0)
Console.Write("Number is Prime.");

13
ANKIT TYAGI; ROLL NO 8990

public void vowels()


{
char ch;
Console.WriteLine("Enter a alphabet : ");
ch = (char)Console.Read();
switch (ch)
{
case 'a':
case 'A':
case 'e':
case 'E':
case 'i':
case 'I':
case 'o':
case 'O':
case 'u':
case 'U':
Console.WriteLine();
Console.WriteLine(ch + "is vowel");
break;
default:
Console.WriteLine();

Console.Write(ch + "is a consonant");


break;
}

public void demofor()


{
string[] s = { "TEST", "FOR", "FOREACH","LOOP" };
foreach (String str in s)
{
Console.WriteLine(str);
}

public void sum()


{

14
ANKIT TYAGI; ROLL NO 8990

int num,copy,rev=0,rem,sumDigits=0;
Console.Write("Enter number:");
num = int.Parse(Console.ReadLine());
copy = num;

while (num > 0)


{
rem = num % 10;
rev = rev * 10 + rem;
sumDigits=sumDigits+rem;
num = num / 10;
}
Console.WriteLine("Reverse of " + copy +":"+ rev);
Console.WriteLine("Sum of digits:" + sumDigits);
}

class practical
{
public static void Main()
{
int no;
Operations obj=new Operations();
Console.WriteLine("enter your choice");
Console.WriteLine("1.generate fibonacci series");
Console.WriteLine("2.test for prime numbers");

Console.WriteLine("3.test for vowels");


Console.WriteLine("4.use of foreach loop with arrays");
Console.WriteLine("5.reverce a number and find sum of digits");

no=Convert.ToInt32(Console.ReadLine());
switch(no)
{
case 1:
obj.fibonacci();
break;
case 2:
obj.prime_no();
break;
case 3:

15
ANKIT TYAGI; ROLL NO 8990

obj.vowels();
break;
case 4:
obj.demofor();
break;
case 5:
obj.sum();
break;
default:

Console.WriteLine("you entered a wrong choice");


break;

}
}
}

Output:

1. Fibonacci Series:

2. Prime Numbers:

16
ANKIT TYAGI; ROLL NO 8990

3. Vowels:

4. Foreach loop with arrays:

17
ANKIT TYAGI; ROLL NO 8990

5. Reverse no. and find sum:

18
ANKIT TYAGI; ROLL NO 8990

PRACTICAL 2
WORKING WITH OBJECT ORIENTED C# AND ASP .NET

2. Create simple application to demonstrate use of following concepts

19
ANKIT TYAGI; ROLL NO 8990

i. Function Overloading
ii. Inheritance (all types)
iii. Constructor overloading
iv. Interfaces
v. Using Delegates and events
vi. Exception handling

i. Function Overloading:

Code:

using System;
class Func
{

// adding two integer values.


public int Add(int a, int b)
{
int sum = a + b;
return sum;
}

// adding three integer values.


public int Add(int a, int b, int c)
{
int sum = a + b + c;
return sum;
}

// Main Method
public static void Main(String[] args)
{

// Creating Object
Func ob = new Func();

int sum1 = ob.Add(1, 2);


Console.WriteLine("sum of the two "
+ "integer value : " + sum1);
Console.ReadLine();

int sum2 = ob.Add(1, 2, 3);


Console.WriteLine("sum of the three "
+ "integer value : " + sum2);
Console.ReadLine();

20
ANKIT TYAGI; ROLL NO 8990

}
}

Output:

ii. Inheritance (all types)

1. Single inheritance:

Code:

using System;
class A
{
public void show()
{
Console.WriteLine("This is parent class");
}
}
class B: A
{
public void print()
{
Console.WriteLine("this is child class");
}
}
class test
{
public static void Main(string[] args)
{
B s=new B();
s.show();
s.print();
Console.ReadLine();
}

21
ANKIT TYAGI; ROLL NO 8990

Output:

2. Multiple Inheritance:

Code:
using System;

interface I1

void show();

interface I2

void display();

class A:I1,I2

public void show()

Console.WriteLine("This is first interface method");

Console.ReadLine();

22
ANKIT TYAGI; ROLL NO 8990

Public void display()

Console.WriteLine("This is second interface method");

Console.ReadLine();

class Program

public static void Main(string[] args)

A a=new A();

a.show();

a.display();

Output:

3. Multilevel inheritance:

23
ANKIT TYAGI; ROLL NO 8990

Code:
using System;
public class A
{
public void show()

{
Console.WriteLine("class A");
Console.ReadLine();
}
}
public class B: A
{
public void show1()
{
Console.WriteLine("class B");
Console.ReadLine();
}
}
public class C : B
{
public void show2()
{
Console.WriteLine("class C");
Console.ReadLine();
}
}
class multileveldemo{
public static void Main(string[] args)
{

C ob = new C();
ob.show();
ob.show1();
ob.show2();
Console.ReadLine();
}
}

24
ANKIT TYAGI; ROLL NO 8990

Output:

4. Hierarchical Inheritance:

Code:
using System;
class parent
{
public void display()
{
Console.WriteLine("This is parent");
Console.ReadLine();
}
}
class child1:parent
{
public void show1()
{
Console.WriteLine("THIS is first child");
Console.ReadLine();
}
}
class child2:parent
{
public void show2()
{
Console.WriteLine("this is second child");
Console.ReadLine();
}
}
class demo
{
public static void Main(string[] args)
{
child1 c1=new child1();
c1.display();
c1.show1();
child2 c2=new child2();

25
ANKIT TYAGI; ROLL NO 8990

c2.display();
c2.show2();
Console.ReadLine();
}
}

Output:

5. Hybrid Inheritance:

Code:
//Hybrid Inheritance
using System;
class parent
{
public void display()
{
Console.WriteLine("I am parent ");
}
}
class child1 : parent
{
public void display1()
{

Console.WriteLine("I am 1st child of parent");


}
}
class subchild : child1
{
public void show()
{
Console.WriteLine("I am child of child1");
}
}
class child2 : parent
{
public void display2()

26
ANKIT TYAGI; ROLL NO 8990

{
Console.WriteLine("I am 2nd child of parent");
}
}
class test
{
public static void Main(string[] args)
{
child1 c1=new child1();
c1.display();
c1.display1();
child2 c2=new child2();
c2.display();
c2.display2();
subchild s=new subchild();
s.display();
s.display1();
s.show();
Console.ReadLine();
}
}

Output:

iii. Constructor overloading:

Code:
using System;
class Demo
{
int a,b,c,d;
public Demo()
{
Console.WriteLine("this is default constructor");
}
public Demo(int x,int y)
{
a=x;
b=y;

27
ANKIT TYAGI; ROLL NO 8990

Console.WriteLine("This is parameterized constructor:A="+a+"B="+b);


}
public Demo(Demo d2)
{
int c=d2.a;
int d=d2.b;
Console.WriteLine("This is copy constructor:A="+c+"B="+d);
}
}
class program
{
public static void Main(string[] args)
{
Demo d1=new Demo();
Demo d2=new Demo(1,2);
Demo d3=new Demo(d2);
Console.ReadLine();
}
}

Output:

iv. Interfaces:

Code:

using System;
interface I1
{
void show();
}
interface I2

{
void display();
}
class A:I1,I2
{
public void show()
{

28
ANKIT TYAGI; ROLL NO 8990

Console.WriteLine("This is first interface method");


}
public void display()
{
Console.WriteLine("This is second interface method");
}
}
class Program
{
public static void Main(string[] args)
{
A a=new A();
a.show();
a.display();
Console.ReadLine();
}
}

Output:

v. Using Delegates and events:

Code:

using System;

namespace SampleApp
{

public delegate void MyDel(string str);


class EventProgram
{
public event MyDel MyEvent;
public void show(string username)
{
Console.WriteLine( "Welcome " + username);
}
static void Main(string[] args)
{
EventProgram obj1 = new EventProgram();
MyDel d=new MyDel(obj1.show);

29
ANKIT TYAGI; ROLL NO 8990

obj1.MyEvent+=d;
obj1. MyEvent("Krutika");
Console.ReadLine();
}
}
}

Output:

vi. Exception handling:

Code:
using System;
public class excdemo
{
public static void Main(string[] args)
{

try
{
int a = 10;
int b = 0;
Console.WriteLine(a/b);
}
catch (Exception e)
{
Console.WriteLine(e);
}
Console.WriteLine("Rest of the code.....");
Console.ReadLine();
}
}

Output:

30
ANKIT TYAGI; ROLL NO 8990

31
ANKIT TYAGI; ROLL NO 8990

PRACTICAL 3
WORKING WITH WEB FORMS AND CONTROL

32
ANKIT TYAGI; ROLL NO 8990

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

Code:

Pra3A.aspx

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


Inherits="practical3.pra3A" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<br />
View state data:&nbsp;
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
<br />
<asp:Button ID="Button1" runat="server" BackColor="Red" onclick="Button1_Click"
Text="viewstate" />
<br />
<br />
<br />
Enter Your Name:<asp:TextBox ID="TextBox1" runat="server" AutoPostBack="True"
ontextchanged="TextBox1_TextChanged" ToolTip="Enter name"></asp:TextBox>
<br />
<br />
Select your hobbies:<asp:CheckBox ID="CheckBox1" runat="server"
AutoPostBack="True" ForeColor="#0066FF"
oncheckedchanged="CheckBox1_CheckedChanged" Text="singing" />
&nbsp;&nbsp;
<asp:CheckBox ID="CheckBox2" runat="server" AutoPostBack="True"
ForeColor="Fuchsia" oncheckedchanged="CheckBox2_CheckedChanged"
Text="dancing" />
&nbsp;
<br />
<br />
select gender:<asp:RadioButton ID="RadioButton1" runat="server"
AutoPostBack="True" GroupName="gender"
oncheckedchanged="RadioButton1_CheckedChanged" Text="male" />
&nbsp;
<asp:RadioButton ID="RadioButton2" runat="server" AutoPostBack="True"
GroupName="gender" oncheckedchanged="RadioButton2_CheckedChanged"
Text="female" />
<br />
<br />
<br />
select class:&nbsp;
<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True"
onselectedindexchanged="DropDownList1_SelectedIndexChanged">
<asp:ListItem>FYIT</asp:ListItem>
<asp:ListItem>SYIT</asp:ListItem>
<asp:ListItem>TYIT</asp:ListItem>

33
ANKIT TYAGI; ROLL NO 8990

</asp:DropDownList>
<br />
<br />
select division:&nbsp;
<asp:ListBox ID="ListBox1" runat="server" AutoPostBack="True" Height="39px"
onselectedindexchanged="ListBox1_SelectedIndexChanged">
<asp:ListItem>A</asp:ListItem>
<asp:ListItem>B</asp:ListItem>
</asp:ListBox>
<br />
Name ::<asp:Label ID="Label2" runat="server" Text="Label"></asp:Label>
<br />
Hobbies:<asp:Label ID="Label3" runat="server" Text="Label"></asp:Label>
<br />
Gender:<asp:Label ID="Label6" runat="server" Text="Label"></asp:Label>
<br />
Class:<asp:Label ID="Label4" runat="server" Text="Label"></asp:Label>
<br />
Division:<asp:TextBox ID="TextBox2" runat="server" Height="54px" Width="126px"></asp:TextBox>
<br />
<br />
</div>
</form>
</body>
</html>

Pra3A.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace practical3
{
public partial class pra3A : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
String name="Helloworld";
if(ViewState["name"]==null)
{
ViewState["name"]=name;
}
}
protected void Button1_Click(object sender, EventArgs e)
{
Label1.Text = ViewState["name"].ToString();
}
protected void TextBox1_TextChanged(object sender, EventArgs e)
{
Label2.Text = TextBox1.Text;
}
protected void CheckBox2_CheckedChanged(object sender, EventArgs e)
{
Label3.Text = CheckBox2.Text;
}

34
ANKIT TYAGI; ROLL NO 8990

protected void CheckBox1_CheckedChanged(object sender, EventArgs e)


{
Label3.Text = CheckBox1.Text;
}
protected void RadioButton1_CheckedChanged(object sender, EventArgs e)
{
Label6.Text = RadioButton1.Text;
}
protected void RadioButton2_CheckedChanged(object sender, EventArgs e)
{
Label6.Text = RadioButton2.Text;
}
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
Label4.Text = DropDownList1.SelectedItem.Text;
}
protected void ListBox1_SelectedIndexChanged(object sender, EventArgs e)
{
for (int i = 0; i < ListBox1.Items.Count; i++)
{
if (ListBox1.Items[i].Selected == true)
{ TextBox2.Text = TextBox2.Text + "" + ListBox1.Items[i].Text; }
}
}
}
}

Output:

35
ANKIT TYAGI; ROLL NO 8990

3B] 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:

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


Inherits="practical3.WebForm1" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<br />
<br />
<asp:Calendar ID="Calendar1" runat="server" BackColor="#FF6699"
BorderColor="#3399FF" DayNameFormat="Full" ForeColor="Black"
NextPrevFormat="ShortMonth"
ShowGridLines="True" >
<DayHeaderStyle BackColor="#FF0066" />
<NextPrevStyle BorderStyle="Solid" ForeColor="#000099" />
<OtherMonthDayStyle BackColor="#66FF33" />
<SelectedDayStyle BackColor="Red" />
<SelectorStyle BackColor="#3399FF" />
<TitleStyle BackColor="#3333CC" />
<TodayDayStyle BackColor="White" />
</asp:Calendar>
you selected date:<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
<br />
todays date:<asp:Label ID="Label2" runat="server" Text="Label"></asp:Label>
<br />
Ganpati vacation start:<asp:Label ID="Label3" runat="server" Text="Label"></asp:Label>
<br />
Days remaining for ganpati vacation:<asp:Label ID="Label4" runat="server"
Text="Label"></asp:Label>
<br />
Days remaining for newyear:<asp:Label ID="Label5" runat="server" Text="Label"></asp:Label>
<br />
<asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="submit" />
<br />
<br />
<br />
<br />
<br />
<br />

36
ANKIT TYAGI; ROLL NO 8990

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

Pra3b.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace practical3
{
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
Calendar1.Caption = "mycalender";
Calendar1.FirstDayOfWeek = FirstDayOfWeek.Sunday;
Calendar1.NextPrevFormat = NextPrevFormat.ShortMonth;
Calendar1.TitleFormat = TitleFormat.Month;
Label1.Text = Calendar1.SelectedDate.Date.ToString();
Label2.Text = Calendar1.TodaysDate.ToShortDateString();
Label3.Text = "9-10-2021";
TimeSpan d = new DateTime(2020, 9, 10) - DateTime.Now;
Label4.Text = d.Days.ToString();
TimeSpan d1 = new DateTime(2021, 12, 31) - DateTime.Now;
Label5.Text = d1.Days.ToString();
if (Calendar1.SelectedDate.ToShortDateString() == "9-10-2020")
Label3.Text = "<b>Ganpati festival start<b>";
if (Calendar1.SelectedDate.ToShortDateString() == "9-14-2020")
Label3.Text="<b>Ganpati festival end<b>";
}
protected void Calender1_DayRender(object sender,
System.Web.UI.WebControls.DayRenderEventArgs e)
{
if (e.Day.Date.Day == 15 && e.Day.Date.Month == 8)
{
e.Cell.BackColor = System.Drawing.Color.Thistle;
e.Cell.Text = "Independence day";
}
if (e.Day.Date.Day == 10 && e.Day.Date.Month == 9)
{
Calendar1.SelectedDate = new DateTime(2021, 9, 10);
Calendar1.SelectedDates.SelectRange(Calendar1.SelectedDate,Calendar1.SelectedDate.AddDa ys(10));
e.Cell.Text = "Ganpati";
}
}
}
}

37
ANKIT TYAGI; ROLL NO 8990

Output:

38
ANKIT TYAGI; ROLL NO 8990

PRACTICAL NO: 4
DEMONSTRATE THE USE OF TREE VIEW CONTROL PERFORMS
FOLLOWING OPERATIONS.

39
ANKIT TYAGI; ROLL NO 8990

4] Demonstrate the use of tree view control. Perform following operations:


i. 1. Tree view control and data list. 2. Tree view operations.

Code:

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


<items>
<treeviewitem text="Home"navigateurl="Default.aspx">
<treeviewitem text="Edit"navigateurl="Default.aspx">
<treeviewitem text="Cut"navigateurl="Default.aspx"/>
<treeviewitem text="Copy"navigateurl="Default.aspx"/>
</treeviewitem>
<treeviewitem text="File"navigateurl="Default.aspx">
<treeviewitem text="Save"navigateurl="Default.aspx"/>
</treeviewitem>
</treeviewitem>
</items>

Output:

ii.
iii.

40
ANKIT TYAGI; ROLL NO 8990

PRACTICAL NO: 5
WORKING WITH FORM CONTROLS

41
ANKIT TYAGI; ROLL NO 8990

5A] Create a Registration form to demonstrate use of various Validation


controls.

Registration Form.aspx:

<%@Page Language="C#"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0
Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1"runat="server">
<asp:Label ID="Label1"runat="server" Text="Full Name :"></asp:Label>
<asp:TextBox ID="TextBox1"runat="server"
style="position: relative; top: 1px; left: 2px; width: 161px"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1"runat="server"
ControlToValidate="TextBox1"ErrorMessage="Name cannot be blank."
ForeColor="Red"></asp:RequiredFieldValidator>
<br />
<br />
<asp:Label ID="Label2"runat="server" Text="E-Mail :"></asp:Label>
<asp:TextBox ID="TextBox2"runat="server" style="margin-left: 56px"
Width="145px"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator2"runat="server"
ControlToValidate="TextBox2"ErrorMessage="EMail cannot be blank."
ForeColor="Red"></asp:RequiredFieldValidator>
<br />
<br />
<asp:Label ID="Label3"runat="server" Text="DOB : "></asp:Label>
<asp:TextBox ID="TextBox3"runat="server" style="margin-left: 62px"
Width="141px"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator3"runat="server"
ControlToValidate="TextBox3"ErrorMessage="DOB cannot be blank."
ForeColor="Red"></asp:RequiredFieldValidator>
<br />
<br />
<asp:Label ID="Label4"runat="server" Text="Age : "></asp:Label>
<asp:TextBox ID="TextBox4"runat="server" style="margin-left: 72px"
Width="148px"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator4"runat="server"
ControlToValidate="TextBox4"ErrorMessage="Age cannot be blank."
ForeColor="#FF5050"></asp:RequiredFieldValidator>
<asp:RangeValidator ID="RangeValidator1"runat="server"

42
ANKIT TYAGI; ROLL NO 8990

ControlToValidate="TextBox4"CultureInvariantValues="True"
ErrorMessage="Age must be between 18 - 30"ForeColor="#FF5050"
MaximumValue="30"MinimumValue="18"></asp:RangeValidator>
<br />
<br />
<asp:Label ID="Label7"runat="server" Text="Mobile No : "></asp:Label>
<asp:TextBox ID="TextBox7"runat="server" style="margin-left: 32px"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator5"runat="server"
ControlToValidate="TextBox5"ErrorMessage="Mobile No cannot be blank."
ForeColor="Red"></asp:RequiredFieldValidator>
<br />
<br />
<asp:Label ID="Label5"runat="server" Text="Course :"></asp:Label>
<asp:TextBox ID="TextBox5"runat="server" style="margin-left: 57px"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator6"runat="server"
ControlToValidate="TextBox6"ErrorMessage="Course cannot be blank."
ForeColor="Red"></asp:RequiredFieldValidator>
<br />
<br />
<asp:Label ID="Label6"runat="server" Text="Sem : "></asp:Label>
<asp:TextBox ID="TextBox6"runat="server"
style="margin-left: 70px; margin-top: 0px"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator7"runat="server"
ControlToValidate="TextBox7"ErrorMessage="Sem cannot be blank."
ForeColor="Red"></asp:RequiredFieldValidator>
<br />
<br />
<asp:Button ID="Button1"runat="server" style="margin-left: 80px"
Text="SUBMIT" />
<asp:ValidationSummary ID="ValidationSummary1"runat="server" />
</form>
</body>
</html>

Default.Aspx.cs:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class _Default :System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
}

43
ANKIT TYAGI; ROLL NO 8990

Output:

44
ANKIT TYAGI; ROLL NO 8990

5B] Create web form to demonstrate use of Adrotator Control.

Code:

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

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


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

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

<asp:AdRotator ID="AdRotator1"runat="server"AdvertisementFile="~/ads.xml" />

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

ads.xml
<?xml version="1.0" encoding="utf-8" ?>
<Advertisements>
<Ad>
<ImageUrl>a.jpg</ImageUrl>
<Height>300px</Height>
<Width>200px</Width>

<NavigateUrl>https://www.google.co.in</NavigateUrl>
<AlternateText>abc site</AlternateText>
<Impressions>2</Impressions>
<Keyword>Computer</Keyword>
</Ad>

<Ad>

45
ANKIT TYAGI; ROLL NO 8990

<ImageUrl>b.jpg</ImageUrl>
<Height>300px</Height>
<Width>200px</Width>
<NavigateUrl>https://www.google.co.in</NavigateUrl>
<AlternateText>abc site</AlternateText>
<Impressions>2</Impressions>
<Keyword>Computer</Keyword>
</Ad>
</Advertisements>

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

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


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

}
}
Output:

5C] Create Web Form to demonstrate use User Controls.

46
ANKIT TYAGI; ROLL NO 8990

Default.aspx
<%@ Page
Language="C#"AutoEventWireup="true"CodeFile="Default.aspx.cs"Inherits="_Default"%>
<%@ Register Src="contactus.ascx"TagPrefix="uc1"TagName="contactus"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0
Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
<head runat="server">
<title></title>
</head>
<body>
<form id="form1"runat="server">
<div>
<uc1:contactusrunat="server" id="contactus"/>
</div>
</form>
</body>
</html>
User Control:
contactus.ascx
<%@ Control Language="C#"AutoEventWireup="true"CodeFile="contactus.ascx.cs"
Inherits="contactus"%>
<asp:Label ID="Label1"runat="server" Text="ENTER FIRST NAME"></asp:Label>
<asp:TextBox ID="TextBox1"runat="server"
style="position: relative; top: 0px; left: 28px; width: 130px"></asp:TextBox>
<p>
<asp:Label ID="Label2"runat="server" Text="ENTER LAST NAME"></asp:Label>
<asp:TextBox ID="TextBox2"runat="server" style="margin-left: 30px"></asp:TextBox>
</p>
<p>
<asp:Button ID="Button1"runat="server" style="margin-left:
85px" Text="SUBMIT" />
</p>

Output:

47
ANKIT TYAGI; ROLL NO 8990

48
ANKIT TYAGI; ROLL NO 8990

PRACTICAL NO: 6
WORKING WITH NAVIGATION, BEAUTIFICATION AND MASTER
PAGE.

49
ANKIT TYAGI; ROLL NO 8990

6A] Create Web Form to demonstrate use of Website Navigation controls and
Site Map.

Code:

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


<siteMapxmlns="http://schemas.microsoft.com/AspNet/SiteMap-File-1.0">
<siteMapNodeurl="" title="" description="">
<siteMapNodeurl="Default.aspx" title="HOME PAGE" description="" />
<siteMapNodeurl="myweb1.aspx" title="FIRST PAGE" description="" />
<siteMapNodeurl="myweb2.aspx" title="SECOND PAGE" description="">
<siteMapNodeurl="myweb3.aspx" title="THIRD PAGE" description="" />
</siteMapNode>
</siteMapNode>
</siteMap>

Default.aspx
<%@ Page
Language="C#"AutoEventWireup="true"CodeBehind="Default.as
px.cs" Inherits="WebApplication15.WebForm1"%>

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


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

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

</div>
<asp:HyperLink ID="HyperLink1"runat="server"NavigateUrl="~/myweb1.aspx">HOME
PAGE</asp:HyperLink>
</form>
</body>
</html>

myweb1.aspx

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


Inherits="WebApplication15.myweb1"%>

50
ANKIT TYAGI; ROLL NO 8990

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


Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1- transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1"runat="server">
<asp:SiteMapPath ID="SiteMapPath1"runat="server">
</asp:SiteMapPath>
<br />
<div>
<asp:HyperLink ID="HyperLink1"runat="server"NavigateUrl="~/myweb2.aspx">FIRST
PAGE</asp:HyperLink>
</div>
</form>
</body>
</html>

myweb2.aspx
<%@ Page Language="C#"AutoEventWireup="true"CodeBehind="myweb2.aspx.cs"
Inherits="WebApplication15.myweb2"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0
Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1- transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">

51
ANKIT TYAGI; ROLL NO 8990

<title></title>
</head>
<body>
<form id="form1"runat="server">
<asp:SiteMapPath ID="SiteMapPath1"runat="server">
</asp:SiteMapPath>
<br />
<div>
<asp:HyperLink ID="HyperLink1"runat="server"NavigateUrl="~/myweb3.aspx">THIRD
PAGE</asp:HyperLink>
</div>
</form>
</body>
</html>
myweb3.aspx
<%@ Page Language="C#"AutoEventWireup="true"CodeBehind="myweb3.aspx.cs"
Inherits="WebApplication15.myweb3"%>

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


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

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

<asp:HyperLink ID="HyperLink1"runat="server"NavigateUrl="~/Default.aspx">HOME
PAGE</asp:HyperLink>

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

OUTPUT:

52
ANKIT TYAGI; ROLL NO 8990

1. Home page:

2. First Page:

3. Second Page:

4. Third Page:

53
ANKIT TYAGI; ROLL NO 8990

6B] Create a web application to demonstrate the use of Master Page with applying
Styles and Themes for page beautification.

Code:

Site1.master

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


Inherits="site1" %>

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


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

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

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

54
ANKIT TYAGI; ROLL NO 8990

Default.aspx
<%@ Page Title=""
Language="C#"MasterPageFile="~/site1.master"AutoEventWireup="true"CodeFile="Default.as
px.cs" Inherits="_Default" %>
<asp:Content ID="c2"ContentPlaceHolderID="ContentPlaceHolder1"Runat="Server">
<asp:Label ID="Label1"runat="server" Text="Select The Date"></asp:Label>
<asp:Calendar ID="Calendar1"runat="server"></asp:Calendar>
<asp:HyperLink
ID="HyperLink1"runat="server"NavigateUrl="~/Default2.aspx">Next</asp:HyperLink
<p>
</p>
</asp:Content>

Default1.aspx

<%@ Page Title=""


Language="C#"MasterPageFile="~/site1.master"AutoEventWireup="true"CodeFile="Default2.a
spx.cs" Inherits="Default2"%>

<asp:Content ID="c1"ContentPlaceHolderID="ContentPlaceHolder1"Runat="Server">
<asp:Label ID="Label1"runat="server" style="position: relative" Text="NAME"></asp:Label>
<asp:TextBox ID="TextBox1"runat="server" style="margin-left: 24px"
Width="133px"></asp:TextBox>
<asp:HyperLink ID="HyperLink1"runat="server"NavigateUrl="~/Default.aspx"
style="position: relative">HOME PAGE</asp:HyperLink>
</asp:Content>

Stylesheet.cs

body
{
background-color:White;
font:italic|Arial|12;
}
Skin Code

Theme.skin

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

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


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

55
ANKIT TYAGI; ROLL NO 8990

<asp:GridViewrunat="server"SkinId="gridviewSkin"BackColor="White">
<AlternatingRowStyleBackColor="Blue" />
</asp:GridView>

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


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

<asp:Imagerunat="server"ImageUrl="~/images/image1.jpg" />
--%>
<asp:Labelrunat="server"backcolor=blue/>

Output:

56
ANKIT TYAGI; ROLL NO 8990

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

A] WebForm1.aspx

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


Inherits="WebApplication11.WebForm1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0
Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1- transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1"runat="server">
<title></title>
</head>
<body>
<form id="form1"runat="server">
<div>
User Name:-<asp:textbox id="TextBox1"runat="server"></asp:textbox>
<br />
Password :-<asp:textbox id="TextBox2"runat="server"></asp:textbox>
<br />
<asp:button id="Button1"runat="server" onclick="Button1_Click" text="Submit" />
<asp:button id="Button3"runat="server" onclick="Button3_Click" text="Restore" />
</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 WebApplication11
{
public partial class WebForm1 :System.Web.UI.Page
{

public string a, b;
protected void Button1_Click(object sender, EventArgs e)
57
ANKIT TYAGI; ROLL NO 8990

ViewState["name"] =
TextBox1.Text;
ViewState["password"] =
TextBox2.Text;

TextBox1.Text = TextBox2.Text = string.Empty;


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

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

}
}

}
}

Default.aspx

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


Inherits="_Default"%>

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


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

<html xmlns="http://www.w3.org/1999/xhtml">

<head id="Head1"runat="server">
<title>
Untitled Page
</title>
</head>

58
ANKIT TYAGI; ROLL NO 8990

<body>
<form id="form1"runat="server">
<div>
&nbsp; &nbsp; &nbsp;

<table style="width: 568px; height: 103px">

<tr>
<td style="width: 209px">
<asp:Label ID="lblstr"runat="server" Text="Enter a String" style="width:94px">
</asp:Label>
</td>

<td style="width: 317px">


<asp:TextBox ID="txtstr"runat="server" style="width:227px">
</asp:TextBox>
</td>
</tr>

<tr>
<td style="width: 209px"></td>
<td style="width: 317px"></td>
</tr>

<tr>
<td style="width: 209px">
<asp:Button ID="btnnrm"runat="server"
Text="No action button" style="width:128px" />
</td>

<td style="width: 317px">


<asp:Button ID="btnstr"runat="server"
OnClick="btnstr_Click" Text="Submit the String" />
</td>
</tr>

<tr>
<td style="width: 209px"></td>

<td style="width: 317px"></td>


</tr>

<tr>
<td style="width: 209px">

59
ANKIT TYAGI; ROLL NO 8990

<asp:Label ID="lblsession"runat="server" style="width:231px">


</asp:Label>
</td>

<td style="width: 317px"></td>


</tr>

<tr>
<td style="width: 209px">
<asp:Label ID="lblshstr"runat="server">
</asp:Label>
</td>

<td style="width: 317px"></td>


</tr>

</table>

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

Default.aspx.cs
using System;
using System.Collections.Generic;
using
System.Linq;
using
System.Web;
using
System.Web.UI;
using System.Web.UI.WebControls;
public partial class _Default :System.Web.UI.Page
{
String mystr;

protected void Page_Load(object sender, EventArgs e)


{
this.lblshstr.Text = this.mystr;
this.lblsession.Text =
(String)this.Session["str"];
}

60
ANKIT TYAGI; ROLL NO 8990

protected void btnstr_Click(object sender, EventArgs e)


{
this.mystr = this.txtstr.Text;
this.Session["str"] =
this.txtstr.Text;
this.lblshstr.Text =
this.mystr;
this.lblsession.Text = (String)this.Session["str"];

}
}

Output:

61
ANKIT TYAGI; ROLL NO 8990

PRACTICAL NO: 7
WORKING WITH DATABASE

62
ANKIT TYAGI; ROLL NO 8990

7A] Create a web application for inserting and deleting records from a
database.
Code:
Default.asp

<%@PageLanguage="C#"AutoEventWireup="true"CodeFile="Default.aspx.cs"Inherits="_Defa
ult"%>

<!DOCTYPEhtmlPUBLIC"-//W3C//DTD XHTML 1.0 Transitional//EN"


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

<htmlxmlns="http://www.w3.org/1999/xhtml">
<headrunat="server">
<title></title>
</head>
<body>
<formid="form1"runat="server">
<div>

<asp:LabelID="Label1"runat="server"Text="Roll No"></asp:Label>
<asp:TextBoxID="TextBox1"runat="server"
style="position: relative; top: -2px; left: 73px; width: 129px"></asp:TextBox>

</div><p>
<asp:LabelID="Label2"runat="server"Text="Name"></asp:Label>
<asp:TextBoxID="TextBox2"runat="server"style="margin-left: 83px"></asp:TextBox></p>
<asp:LabelID="Label3"runat="server"Text="Mobile Number"></asp:Label>
<asp:TextBoxID="TextBox3"runat="server"style="margin-left: 24px"></asp:TextBox><p>
<asp:ButtonID="Button1"runat="server"onclick="Button1_Click"style="margin-
left:
138px"Text="INSERT"Width="68px"/><asp:ButtonID="Button2"runat="server"
onclick="Button2_Click"style="position: relative; top: 0px; left: 25px; width:
78px"
Text="UPDATE"/>
<asp:ButtonID="Button3"runat="server"onclick="Button3_Click"Text="Delete"style="m
argin-left: 65px"Width="105px"/>

</p>
<asp:GridViewID="GridView1"runat="server">
</asp:GridView>
</form>
</body></html
>Aspx.cs Code:

63
ANKIT TYAGI; ROLL NO 8990

Default.aspx.csusing System;
usingSystem.Collections.Generic;
usingSystem.Linq;
usingSystem.Web;
usingSystem.Web.UI;
usingSystem.Web.UI.WebControls;
usingSystem.Data.SqlClient;
publicpartialclass_Default : System.Web.UI.Page
{

SqlConnection con =newSqlConnection(@"Data


Source=.\SQLEXPRESS;AttachDbFilename='C:\Users\SujuTadadikar\Documents\Visual
Studio 2010\WebSites\WebSite11\App_Data\Database.mdf';Integrated Security=True;Connect
Timeout=30;User Instance=True");
protectedvoidPage_Load(object sender, EventArgs e)

string query = "select * from students";


SqlCommandcmd = newSqlCommand(query, con); con.Open();

GridView1.DataSource =cmd.ExecuteReader();

GridView1.DataBind();

con.Close();

protectedvoid Button1_Click(object sender, EventArgs e)

con.Open();

SqlCommandcmd = newSqlCommand("insert into students values('" + TextBox1.Text + "','" +


TextBox2.Text + "','" + TextBox3.Text + "')" ,con);

cmd.ExecuteNonQuery();

con.Close();

Response.Redirect("Default.aspx");

64
ANKIT TYAGI; ROLL NO 8990

protectedvoid Button2_Click(object sender, EventArgs e)

con.Open();

SqlCommandcmd = newSqlCommand("update students set s_name='" + TextBox2.Text


+ "' where s_id=' " + TextBox1.Text + "'", con);
cmd.ExecuteNonQuery();
con.Close();

Response.Redirect("Default.aspx");

}
protectedvoid Button3_Click(object sender, EventArgs e)

con.Open();

SqlCommandcmd = newSqlCommand("delete from students where s_id=' " +


TextBox1.Text + "'", con);
cmd.ExecuteNonQuery();

con.Close();

Response.Redirect("Default.aspx");

65
ANKIT TYAGI; ROLL NO 8990

Output:

Original Database:

Inserting Values:

66
ANKIT TYAGI; ROLL NO 8990

Updating the 2nd value:

Deleting the 3 rdvalues:

67
ANKIT TYAGI; ROLL NO 8990

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

Code:

Default.aspx

<%@PageLanguage="C#"AutoEventWireup="true"CodeFile="Default.aspx.cs"Inherits="_Defa
ult"%>

<!DOCTYPEhtmlPUBLIC"-//W3C//DTD XHTML 1.0 Transitional//EN"


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

<htmlxmlns="http://www.w3.org/1999/xhtml">
<headrunat="server">
<title></title>
</head>
<body>
<formid="form1"runat="server">
<div>

<asp:LabelID="Label1"runat="server"Text="Roll No"></asp:Label>
<asp:TextBoxID="TextBox1"runat="server"
style="position: relative; top: -2px; left: 73px; width: 129px"></asp:TextBox>

</div><p>
<asp:LabelID="Label2"runat="server"Text="Name"></asp:Label>
<asp:TextBoxID="TextBox2"runat="server"style="margin-left: 83px"></asp:TextBox></p>
<asp:LabelID="Label3"runat="server"Text="Mobile Number"></asp:Label>
<asp:TextBoxID="TextBox3"runat="server"style="margin-left: 24px"></asp:TextBox><p>
<asp:ButtonID="Button1"runat="server"onclick="Button1_Click"style="margin-
left:
138px"Text="INSERT"Width="68px"/><asp:ButtonID="Button2"runat="server"
onclick="Button2_Click"style="position: relative; top: 0px; left: 25px; width:
78px"
Text="UPDATE"/>
<asp:ButtonID="Button3"runat="server"onclick="Button3_Click"Text="Delete"style="m
argin-left: 65px"Width="105px"/>
68
ANKIT TYAGI; ROLL NO 8990

</p>
<asp:GridViewID="GridView1"runat="server">
</asp:GridView>
</form>
</body>
</html>

Aspx.cs

Default.aspx.csusing System;
usingSystem.Collections.Generic;
usingSystem.Linq;
usingSystem.Web;
usingSystem.Web.UI;
usingSystem.Web.UI.WebControls;
usingSystem.Data.SqlClient;

publicpartialclass_Default : System.Web.UI.Page
{

SqlConnection con =newSqlConnection(@"Data


Source=.\SQLEXPRESS;AttachDbFilename='C:\Users\SujuTadadikar\Documents\Visual
Studio 2010\WebSites\WebSite11\App_Data\Database.mdf';Integrated Security=True;Connect
Timeout=30;User Instance=True");
protectedvoidPage_Load(object sender, EventArgs e)
{
string query = "select * from students";
SqlCommandcmd = newSqlCommand(query, con); con.Open();
GridView1.DataSource =cmd.ExecuteReader();
GridView1.DataBind();
con.Close();

}
protectedvoid Button1_Click(object sender, EventArgs e)
{

con.Open();

SqlCommandcmd = newSqlCommand("insert into students values('" + TextBox1.Text + "','" +


TextBox2.Text + "','" + TextBox3.Text + "')" ,con);

cmd.ExecuteNonQuery();
con.Close();
69
ANKIT TYAGI; ROLL NO 8990

Response.Redirect("Default.aspx");
}

protectedvoid Button2_Click(object sender, EventArgs e)

con.Open();

SqlCommandcmd = newSqlCommand("update students set s_name='" + TextBox2.Text

+ "' where s_id=' " + TextBox1.Text + "'", con);


cmd.ExecuteNonQuery();
con.Close();
Response.Redirect("Default.aspx");
}

protectedvoid Button3_Click(object sender, EventArgs e)

con.Open();

SqlCommandcmd = newSqlCommand("delete from students where s_id=' " +


TextBox1.Text + "'", con);
cmd.ExecuteNonQuery();
con.Close();
Response.Redirect("Default.aspx");

Output:

Original Database:

70
ANKIT TYAGI; ROLL NO 8990

Inserting Values:

Database with Values:

71
ANKIT TYAGI; ROLL NO 8990

PRACTICAL NO: 8
WORKING WITH DATABASE

72
ANKIT TYAGI; ROLL NO 8990

8A] Create a web application to display Data binding using dropdown list
control.

Code:
Default.aspx

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


Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"

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

<html xmlns="http://www.w3.org/1999/xhtml">

<head id="Head1" runat="server">

<title></title>

</head>

<body>

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

<div>

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

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

style="position: relative; top: -2px; left: 73px; width: 129px"></asp:TextBox>

</div><p>

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

<asp:TextBox ID="TextBox2" runat="server" style="margin-left: 83px"></asp:TextBox></p>

<asp:Label ID="Label3" runat="server" Text="Mobile Number"></asp:Label>

<asp:TextBox ID="TextBox3" runat="server" style="margin-left: 24px"></asp:TextBox>

<br />

<br />

73
ANKIT TYAGI; ROLL NO 8990

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

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

style="margin-left: 90px; margin-top: 13px"></asp:TextBox>

<br />

<br />

<p>

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


style="margin-left: 138px" Text="INSERT" Width="68px" /><asp:Button
ID="Button2" runat="server" onclick="Button2_Click" style="position:
relative; top: 0px; left: 25px; width: 78px"

Text="UPDATE" />

<asp:Button ID="Button3" runat="server" onclick="Button3_Click"

Text="Delete" style="margin-left: 65px" Width="88px" />

</p>

<asp:GridView ID="GridView1" runat="server">

</asp:GridView>

<asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl="~/Default2.aspx"


style="position: relative">Generate DropDownList</asp:HyperLink>

</form>

</body>

</html>

Default2.aspx

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


Inherits="Default2" %>

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

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

<html xmlns="http://www.w3.org/1999/xhtml">

74
ANKIT TYAGI; ROLL NO 8990

<head id="Head1" runat="server">


<title></title>

</head>

<body>

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

<div>

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

</asp:DropDownList>

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

<asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl="~/Default.aspx"


style="position: relative">Home Page</asp:HyperLink>

<br />

<br />

<asp:Button ID="Button1" runat="server" Text="Find" OnClick="Button1_Click1"


Width="59px" />

<br />

<br />

<asp:GridView ID="GridView1" runat="server" BackColor="White"

BorderColor="#999999"

BorderStyle="None" BorderWidth="1px" CellPadding="3" GridLines="Vertical">

<AlternatingRowStyleBackColor="#DCDCDC" />

<FooterStyleBackColor="#CCCCCC" ForeColor="Black" />

<HeaderStyleBackColor="#000084" Font-Bold="True" ForeColor="White" />

<PagerStyleBackColor="#999999" ForeColor="Black" HorizontalAlign="Center" />

<RowStyleBackColor="#EEEEEE" ForeColor="Black" />

<SelectedRowStyleBackColor="#008A8C" Font-Bold="True" ForeColor="White" />

<SortedAscendingCellStyleBackColor="#F1F1F1" />

<SortedAscendingHeaderStyleBackColor="#0000A9" />
75
ANKIT TYAGI; ROLL NO 8990

<SortedDescendingCellStyleBackColor="#CAC9C9" />

<SortedDescendingHeaderStyleBackColor="#000065" />

</asp:GridView>

</div>

</form>

</body>

</html>

Aspx.cs Code:

Default.aspx.cs

using System; using


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

usingSystem.Data.SqlClient;

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

SqlConnection con = new SqlConnection(@"Data

Source=.\SQLEXPRESS;AttachDbFilename='C:\Users\SujuTadadikar\Documents\Visual

Studio 2010\WebSites\WebSite18\App_Data\Database.mdf';Integrated Security=True;Connect

Timeout=30;User Instance=True");

protected void Page_Load(object sender, EventArgs e)

string query = "select * from student";

SqlCommandcmd = new SqlCommand(query, con); con.Open();

GridView1.DataSource = cmd.ExecuteReader();

76
ANKIT TYAGI; ROLL NO 8990

GridView1.DataBind();

con.Close();

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

con.Open();

SqlCommandcmd = new SqlCommand("insert into student values('" + TextBox1.Text +

"','" + TextBox2.Text + "','" + TextBox3.Text + "','" + TextBox4.Text + "')", con);


cmd.ExecuteNonQuery();

con.Close();

Response.Redirect("Default.aspx");

protected void Button2_Click(object sender, EventArgs e)

con.Open();
SqlCommandcmd = new SqlCommand("update student set s_name='" + TextBox2.Text +
"' where s_id=' " + TextBox1.Text + "'", con);
cmd.ExecuteNonQuery();

con.Close();

Response.Redirect("Default.aspx");

protected void Button3_Click(object sender, EventArgs e)

con.Open();

SqlCommandcmd = new SqlCommand("delete from student where s_id=' " +


TextBox1.Text + "'", con); cmd.ExecuteNonQuery();

con.Close();

77
ANKIT TYAGI; ROLL NO 8990

Response.Redirect("Default.aspx");

Default2.aspx.cs

using System; using


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

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

stringstr = @"Data Source=.\SQLEXPRESS;AttachDbFilename='C:\USERS\SUJU

TADADIKAR\DOCUMENTS\VISUAL STUDIO
2010\WEBSITES\WEBSITE18\APP_DATA\DATABASE.MDF';Integrated

Security=True;Connect Timeout=30;User Instance=True";


protected void Page_Load(object sender, EventArgs e)
{

SqlConnection con = new SqlConnection(str);


string com = "Select * from student";

SqlDataAdapteradpt = new SqlDataAdapter(com, con);

DataTabledt = new DataTable(); adpt.Fill(dt);

DropDownList1.DataSource = dt;

DropDownList1.DataBind();

DropDownList1.DataTextField = "s_name";

78
ANKIT TYAGI; ROLL NO 8990

DropDownList1.DataValueField = "s_id";

DropDownList1.DataBind();

protected void Button1_Click1(object sender, EventArgs e)

SqlConnection con = new SqlConnection(str);

SqlCommandcmd = new SqlCommand("select * from student where s_id = '" +

DropDownList1.SelectedValue + "'", con);

SqlDataAdapterAdpt = new SqlDataAdapter(cmd);

DataTabledt = new DataTable();

Adpt.Fill(dt);

GridView1.DataSource = dt;

GridView1.DataBind();

Label1.Text = "Record found";

Output:

Home Page:

79
ANKIT TYAGI; ROLL NO 8990

Dropdown Page:

80
ANKIT TYAGI; ROLL NO 8990

PRACTICAL NO: 9
WORKING WITH DATA CONTROLS

81
ANKIT TYAGI; ROLL NO 8990

9A] Create a web application to demonstrate various uses and properties of


SqlDataSource.

Code:

Default.aspx

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


Inherits="_Default" %>

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

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

<html xmlns="http://www.w3.org/1999/xhtml">

<head runat="server">

<title></title>

</head>

<body style="position: relative">

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

<div>

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

ConnectionString="<%$ ConnectionStrings:DatabaseConnectionString %>"


SelectCommand="SELECT * FROM [Employee]"></asp:SqlDataSource>

</div>

82
ANKIT TYAGI; ROLL NO 8990

<p>

&nbsp;</p>

<p>

&nbsp;</p>

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

DataSourceID="SqlDataSource1">

<Columns>

<asp:BoundFieldDataField="emp_id" HeaderText="emp_id"

SortExpression="emp_id" />

<asp:BoundFieldDataField="emp_name" HeaderText="emp_name"

SortExpression="emp_name" />

<asp:BoundFieldDataField="salary" HeaderText="salary"

SortExpression="salary" />

</Columns>

</asp:GridView>

</form>

</body>

</html>

Database:

83
ANKIT TYAGI; ROLL NO 8990

84
ANKIT TYAGI; ROLL NO 8990

Output:

85
ANKIT TYAGI; ROLL NO 8990

9B] Create a web application to demonstrate data binding using Details View
and Form View Control.
Code:

Default.aspx

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


Inherits="_Default" %>

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

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

<html xmlns="http://www.w3.org/1999/xhtml">

<head runat="server">

<title></title>

</head>

<body style="position: relative">

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

<div>

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

ConnectionString="<%$ ConnectionStrings:DatabaseConnectionString %>"


SelectCommand="SELECT * FROM [Employee]"></asp:SqlDataSource>

</div>

<p>

&nbsp;</p>

86
ANKIT TYAGI; ROLL NO 8990

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

DataSourceID="SqlDataSource1">

<Columns>

<asp:BoundFieldDataField="emp_id" HeaderText="emp_id"

SortExpression="emp_id" />

<asp:BoundFieldDataField="emp_name" HeaderText="emp_name"

SortExpression="emp_name" />

<asp:BoundFieldDataField="salary" HeaderText="salary"

SortExpression="salary" />

</Columns>

</asp:GridView>

<p>

&nbsp;</p>

<asp:FormView ID="FormView1" runat="server" DataSourceID="SqlDataSource1">

<EditItemTemplate>emp_id:

<asp:TextBox ID="emp_idTextBox" runat="server" Text='<%# Bind("emp_id") %>' />

<br />

emp_name:

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

Text='<%# Bind("emp_name") %>' />

<br />
salary:
<asp:TextBox ID="salaryTextBox" runat="server" Text='<%# Bind("salary") %>' />

<br />

<asp:LinkButton ID="UpdateButton" runat="server" CausesValidation="True"

87
ANKIT TYAGI; ROLL NO 8990

CommandName="Update" Text="Update" />

&nbsp;<asp:LinkButton ID="UpdateCancelButton" runat="server"

CausesValidation="False" CommandName="Cancel" Text="Cancel" />

</EditItemTemplate><InsertItemT
emplate>emp_id:
<asp:TextBox ID="emp_idTextBox" runat="server" Text='<%# Bind("emp_id") %>' />

<br />emp_name:

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

Text='<%# Bind("emp_name") %>' />

<br />
salary:
<asp:TextBox ID="salaryTextBox" runat="server" Text='<%# Bind("salary") %>' />

<br />

<asp:LinkButton ID="InsertButton" runat="server" CausesValidation="True"

CommandName="Insert" Text="Insert" />

&nbsp;<asp:LinkButton ID="InsertCancelButton" runat="server"

CausesValidation="False" CommandName="Cancel" Text="Cancel" />

</InsertItemTemplate><Item
Template>emp_id:
<asp:Label ID="emp_idLabel" runat="server" Text='<%# Bind("emp_id") %>' />

<br />emp_name:

<asp:Label ID="emp_nameLabel" runat="server" Text='<%# Bind("emp_name") %>' />

<br />
salary:
<asp:Label ID="salaryLabel" runat="server" Text='<%# Bind("salary") %>' />

<br />

88
ANKIT TYAGI; ROLL NO 8990

</ItemTemplate>

</asp:FormView>

<br />

<br />

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

DataSourceID="SqlDataSource1" Height="50px" Width="125px">

<Fields>

<asp:BoundFieldDataField="emp_id" HeaderText="emp_id"

SortExpression="emp_id" />

<asp:BoundFieldDataField="emp_name" HeaderText="emp_name"

SortExpression="emp_name" />

<asp:BoundFieldDataField="salary" HeaderText="salary"

SortExpression="salary" />

</Fields>

</asp:DetailsView>

</form>

</body>

</html>

Output:

89
ANKIT TYAGI; ROLL NO 8990

9C] Create a web application to display Using Disconnected Data Access and
Data binding using Grid View.

Code:

Default.aspx

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


Inherits="_Default" %>

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


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

<html xmlns="http://www.w3.org/1999/xhtml">

<head runat="server">

<title></title>

</head>

<body>

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

<div>

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


ShowFooter="True" BackColor="White" BorderColor="#CC9966" BorderStyle="None"
BorderWidth="1px" CellPadding="4" EnableModelValidation="True"
OnSelectedIndexChanged="gridInsert_SelectedIndexChanged">

<Columns>

<asp:TemplateField HeaderText="EmployeId">

<ItemTemplate>

<asp:Label ID="lblempid" runat="server" Text='<%#Eval("EmployeeId")


%>'></asp:Label>

</ItemTemplate>

<FooterTemplate>

<asp:TextBox ID="txtempid" runat="server">

</asp:TextBox>

90
ANKIT TYAGI; ROLL NO 8990

</FooterTemplate>

</asp:TemplateField>

<asp:TemplateField HeaderText="Firstname">

<ItemTemplate>

<asp:Label ID="lblname" runat="server" Text='<%#Eval("FirstName")


%>'></asp:Label>

</ItemTemplate>

<FooterTemplate>

<asp:TextBox ID="txtname" runat="server">

</asp:TextBox>

</FooterTemplate>

</asp:TemplateField>

<asp:TemplateField HeaderText="LastName">

<ItemTemplate>

<asp:Label ID="lbllname" runat="server" Text='<%#Eval("LastName")


%>'></asp:Label>

</ItemTemplate>

<FooterTemplate>

<asp:TextBox ID="txtlname" runat="server">

</asp:TextBox>

</FooterTemplate>

</asp:TemplateField>

<asp:TemplateField HeaderText="Address">

<ItemTemplate>

<asp:Label ID="lbladdress" runat="server" Text='<%#Eval("Address")


%>'></asp:Label>

91
ANKIT TYAGI; ROLL NO 8990

</ItemTemplate>

<FooterTemplate>

<asp:TextBox ID="txtaddress" runat="server">

</asp:TextBox>

</FooterTemplate>

</asp:TemplateField>

<asp:TemplateField HeaderText="EmailId">

<ItemTemplate>

<asp:Label ID="lblemailid" runat="server" Text='<%#Eval("EmailId")


%>'></asp:Label>

</ItemTemplate>

<FooterTemplate>

<asp:TextBox ID="txtEmailid" runat="server">

</asp:TextBox>

</FooterTemplate>

</asp:TemplateField>

<asp:TemplateField HeaderText="Operation">

<FooterTemplate>

<asp:Button ID="btnsave" runat="server" Text="Insert"


OnClick="gridInsert_SelectedIndexChanged" />

</FooterTemplate>

</asp:TemplateField>

</Columns>

<FooterStyle BackColor="#FFFFCC" ForeColor="#330099" />

<HeaderStyle BackColor="#990000" Font-Bold="True" ForeColor="#FFFFCC" />

<PagerStyle BackColor="#FFFFCC" ForeColor="#330099" HorizontalAlign="Center" />

92
ANKIT TYAGI; ROLL NO 8990

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

<SelectedRowStyle BackColor="#FFCC66" Font-Bold="True" ForeColor="#663399" />

</asp:GridView>

</div>

</form>

</body>

</html>

Default.aspx

using System;

using System.Collections.Generic;

using System.Linq;

using System.Web;

using System.Web.UI;

using System.Web.UI.WebControls;

using System.Data;

using System.Data.SqlClient;

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

SqlConnection con;

SqlCommand cmd;

SqlDataAdapter adap;

93
ANKIT TYAGI; ROLL NO 8990

DataTable dt;

SqlCommandBuilder cmbuild;

public _Default()

con = new SqlConnection(@"Data Source=.;Initial Catalog=Records;User


ID=sa;Password=mcn@123");

protected void Page_Load(object sender, EventArgs e)

if (!IsPostBack)

FillGrid();

public void FillGrid()

adap = new SqlDataAdapter("select * from EmployeeDetails", con);

dt = new DataTable();

adap.Fill(dt);

cmbuild = new SqlCommandBuilder(adap);

gridInsert.DataSource = dt;

gridInsert.DataBind();

protected void gridInsert_SelectedIndexChanged(object sender, EventArgs e)

TextBox TextEmpId = gridInsert.FooterRow.FindControl("txtempid") as TextBox;


94
ANKIT TYAGI; ROLL NO 8990

TextBox TextEmpName = gridInsert.FooterRow.FindControl("txtName") as TextBox;

TextBox TextLname = gridInsert.FooterRow.FindControl("txtlname") as TextBox;

TextBox TextAddress = gridInsert.FooterRow.FindControl("txtaddress") as TextBox;

TextBox TextEmailId = gridInsert.FooterRow.FindControl("txtEmailid") as TextBox;

con.Open();

cmd = new SqlCommand("insert into EmployeeDetails values('" + TextEmpId.Text + "','" +


TextEmpName.Text + "','" + TextLname + "','" + TextAddress + "','" + TextEmailId + "')", con);

cmd.ExecuteNonQuery();

con.Close();

Output:

95
ANKIT TYAGI; ROLL NO 8990

PRACTICAL NO: 10
WORKING WITH GRIDVIEW CONTROL

96
ANKIT TYAGI; ROLL NO 8990

10A] Create a web application to demonstrate use of GridView control template


and GridView hyperlink.

Code:

Default.aspx

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

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

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

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

<html xmlns="http://www.w3.org/1999/xhtml">

<head runat="server">

<title></title>

</head>

<body style="position: relative">

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

<div>

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

ConnectionString="<%$ ConnectionStrings:DatabaseConnectionString %>"


SelectCommand="SELECT * FROM [Employee]"></asp:SqlDataSource>

97
ANKIT TYAGI; ROLL NO 8990

</div>

<p>

&nbsp;</p>

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

AutoGenerateEditButton="True" AutoGenerateDeleteButton="True"

DataSourceID="SqlDataSource1">

<Columns>

<asp:HyperLinkFieldDataTextField="emp_id" DataNavigateUrlFields="emp_id"

DataNavigateUrlFormatString="~/Details.aspx?emp_id={0}"

HeaderText="emp_id" ItemStyle-Width = "150" />

<asp:TemplateFieldHeaderText="emp_name" >

<ItemTemplate>

<%#Eval("emp_name") %>

</ItemTemplate>

<EditItemTemplate>

<asp:TextBox ID="emp_nameTextBox" runat="server" Text='<%# Bind("emp_name") %>' />

</EditItemTemplate>

</asp:TemplateField>

</Columns>

</asp:GridView>

<p>

&nbsp;</p>

<br />

<br />

98
ANKIT TYAGI; ROLL NO 8990

</form>

</body>

</html>

Details.aspx

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


Inherits="Details" %>

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

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

<html xmlns="http://www.w3.org/1999/xhtml">

<head runat="server">

<title></title>

</head>

<body>

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

<asp:Label ID="Label1" runat="server" Text="You are at Details Page "></asp:Label><div>

</div>

<asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl="~/Default.aspx">Home

Page</asp:HyperLink>

</form>

</body>

</html>

99
ANKIT TYAGI; ROLL NO 8990

100
ANKIT TYAGI; ROLL NO 8990

aspx.cs
using System;
usingSystem.Collections.Generic;
usingSystem.Linq;
usingSystem.Web;
usingSystem.Web.UI;
usingSystem.Web.UI.WebControls;
usingSystem.Data;
publicpartialclass_Default : System.Web.UI.Page
{

protectedvoidPage_Load(object sender, EventArgs e)

if (!this.IsPostBack)

DataTabledt = newDataTable();
dt.Columns.AddRange(newDataColumn[3] { newDataColumn("emp_id"), new

DataColumn("emp_name"), newDataColumn("salary") });

GridView1.DataBind();

}}}

Output:

10B] Create a web application to demonstrate use of GridView button column


101
ANKIT TYAGI; ROLL NO 8990

and GridView events.

Grid_view.aspx:-

Grid_view.aspx.cs:-

using System;
usingSystem.Collections.Generic;
usingSystem.Linq;
usingSystem.Web;
usingSystem.Web.UI;
usingSystem.Web.UI.WebControls;
usingSystem.Drawing;
public partial class grid_view : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

}
protected void GridView1_RowCommand(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;
}
}
}

102
ANKIT TYAGI; ROLL NO 8990

Output:

103
ANKIT TYAGI; ROLL NO 8990

10C]. Create a web application to demonstrate GridView paging and


Creating own table format using GridView.

Code:
Default.aspx

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

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

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

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

<html xmlns="http://www.w3.org/1999/xhtml">

<head runat="server">

<title></title>

</head>

<body>

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

<div>

</div>

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

ConnectionString="<%$ ConnectionStrings:DatabaseConnectionString %>"

SelectCommand="SELECT * FROM [Employee]"></asp:SqlDataSource>

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

DataSourceID="SqlDataSource1" AllowPaging="True" PageSize="2">

<Columns>

104
ANKIT TYAGI; ROLL NO 8990

<asp:BoundFieldDataField="emp_id" HeaderText="emp_id"

SortExpression="emp_id" />

<asp:BoundFieldDataField="emp_name" HeaderText="emp_name"

SortExpression="emp_name" />

<asp:BoundFieldDataField="salaray" HeaderText="salaray"

SortExpression="salaray" />

</Columns>

<PagerSettingsFirstPageText="First" LastPageText="Last" Mode="NumericFirstLast"


PageButtonCount="4" />

</asp:GridView>

</form>

</body></html>

ASPX.cs CODE:
Default.aspx.cs
using System; using
System.Collections.Generic; using
System.Linq; using System.Web;
using System.Web.UI; using
System.Web.UI.WebControls;
using System.Data.SqlClient;

usingSystem.Data;

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

protected void Page_Load(object sender, EventArgs e)

105
ANKIT TYAGI; ROLL NO 8990

BindData();

protected void BindData()

GridView1.DataBind();

protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)

GridView1.PageIndex = e.NewPageIndex;

BindData();

Design:

106
ANKIT TYAGI; ROLL NO 8990

Database:

Output:

107
ANKIT TYAGI; ROLL NO 8990

108
ANKIT TYAGI; ROLL NO 8990

PRACTICAL NO: 11
WORKING WITH AJAX AND XML AND JQUERY

109
ANKIT TYAGI; ROLL NO 8990

11A] Create a web application to demonstrate reading and writing


operation with XML .

Code:

Webfor1.aspx

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


Inherits="practical_10.WebForm1" %>

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


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

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div style="height: 362px; width: 937px">

<asp:Label ID="lbl1"
runat="server"></asp:Label> &nbsp;&nbsp;
<br />
<br />
<asp:Button ID="btnwrite" Text="XML writer" runat="server" Font-Size="X-Large"
onclick="btnwrite_Click"
/>
<br />
<br />

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

Height="158px" style="margin-left: 30px"

Width="239px"></asp:ListBox>

110
ANKIT TYAGI; ROLL NO 8990

<br /><br />


<asp:Button ID="btnread" Text="XML Reader" runat="server" Font-Size="X-Large"
onclick="btnread_Click" style="height: 41px" />

</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;
using System.Xml;

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

protected void btnwrite_Click(object sender, EventArgs e)


{

111
ANKIT TYAGI; ROLL NO 8990

XmlTextWriter writer = new XmlTextWriter("c:\\users\\kiran\\documents\\visual


studio 2010\\Projects\\practical 10\\practical 10\\XMLFile1.xml",null);

writer.WriteStartDocument();
writer.WriteComment("This is xml file for person details");
//write next element
writer.WriteStartElement("Details");

writer.WriteStartElement("p1");
writer.WriteAttributeString("id","1");
writer.WriteElementString("name","sona");
writer.WriteElementString("gender",
"female");

writer.WriteEndElement();

writer.WriteStartElement("p2");
writer.WriteAttributeString("id", "2");
writer.WriteElementString("name", "john");
writer.WriteElementString("gender", "male");
writer.WriteEndElement();

writer.WriteEndEleme

nt();

//Ends the document


writer.WriteEndDocument();
writer.Close();

lbl1.Text = "Data written successfully";

protected void btnread_Click(object sender, EventArgs e)

112
ANKIT TYAGI; ROLL NO 8990

{
XmlReader xReader = XmlReader.Create("c:\\users\\kiran\\documents\\visual
studio 2010\\Projects\\practical 10\\practical 10\\XMLFile1.xml");
while (xReader.Read())
{

switch (xReader.NodeType)
{
case XmlNodeType.Element:
ListBox1.Items.Add("<" + xReader.Name + ">");

break;
case XmlNodeType.Text:
ListBox1.Items.Add(xReader.Valu
e); break;
case XmlNodeType.EndElement:
ListBox1.Items.Add("</"+xReader.Name+"
>"); break;

}
}
}

}
}

Output-

Writing operation

113
ANKIT TYAGI; ROLL NO 8990

Reading operation:

114
ANKIT TYAGI; ROLL NO 8990

11B] Create a web application to demonstrate the


different types of selectors
Selectors.aspx

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


Inherits="jquery.selectors" %>

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


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

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>jquery selectors demo</title>
<script src="jquery-3.5.1.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function () {

$("#btn1").click(function () {
$("#p1").hide("slow");
});
$("#btn2").click(function () {
$("#p1").show("slow");
});
$("p.c1").click(function () {
$("this").toggle();
});

115
ANKIT TYAGI; ROLL NO 8990

$("#btn4").click(function () {
$(".c1").slideUp();
});
$("#btn5").click(function () {
$("*").hide();
});

$("#btn3").click(function () {
$("div").animate({ left: '250px' });
});
});

</script>
</head>
<body>
<form id="form1" runat="server">
<div style="background-color: #00FFFF; position: absolute;" >
<p id="p1">hide and show paragraph</p><br />
<p class="c1">click me to toggle paragraph</p><br />
<h2 class="c1">class selector</h2>

<button id="btn1">hide paragraph</button>


<button id="btn2">show paragraph</button>
<button id="btn3">start animation</button>
<button id="btn4">slide up</button>
<button id="btn5">hide all</button>

</div>
</form>
116
ANKIT TYAGI; ROLL NO 8990

</body>
</html>

Output:

117
ANKIT TYAGI; ROLL NO 8990

11C] Create a web application to demonstrate use of various Ajax controls.

ajaxcontrol.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Ajaxcontrol.aspx.cs"
Inherits="WebApplication6.Ajaxcontrol" %>

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


"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html
xmlns="http://www.w3.org/1999/xhtml"><head runat="server"><title></title>

<style type="text/css">

.style1

{
font-family: Arial;
}

.style2

{
font-size: x-large;

</style>

118
ANKIT TYAGI; ROLL NO 8990

</head><body><form id="form1" runat="server">

<div>

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

<asp:UpdateProgress ID="UpdateProgress2" runat="server" DynamicLayout="true"


AssociatedUpdatePanelID="UpdatePanel1" >

<ProgressTemplate>

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp

119
ANKIT TYAGI; ROLL NO 8990

<span>
class="style1"><strong>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs
p; <span class="style2">&nbsp;Loading... </span>

</strong></span>

</ProgressTemplate>

</asp:UpdateProgress>

<asp:UpdatePanel ID="UpdatePanel1" runat="server">

<ContentTemplate>

<br />

<asp:Timer ID="Timer1" runat="server" Interval="1000">

</asp:Timer>

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

Text="partial postback" Width="170px" />

<br />

<br />

<asp:Label ID="lblpartial" runat="server"></asp:Label>

</ContentTemplate>

</asp:UpdatePanel>

<p></p>

<p>&nbsp;&nbsp;&nbsp<strong>Outside the Update Panel</strong></p>

<asp:Button ID="Button2" runat="server" onclick="Button2_Click"

120
ANKIT TYAGI; ROLL NO 8990

Text="total postback" />

<br />

<asp:UpdateProgress ID="UpdateProgress1" runat="server" DynamicLayout="true"

AssociatedUpdatePanelID="UpdatePanel1" DisplayAfter="20000" >

<ProgressTemplate>

Loading...

</ProgressTemplate>

</asp:UpdateProgress>

<asp:Label ID="lbltotal" runat="server"></asp:Label>

</form>

</body>

</html>

ajaxcontrol.aspx.cs

using System;

using System.Collections.Generic;

using System.Linq;

using System.Web;

using System.Web.UI;

using System.Web.UI.WebControls;

121
ANKIT TYAGI; ROLL NO 8990

namespace WebApplication6

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

protected void Page_Load(object sender, EventArgs e)

protected void Button1_Click(object sender, EventArgs e)

System.Threading.Thread.Sleep(5000);

string time = DateTime.Now.ToLongTimeString();

lblpartial.Text = "Showing time from panel " + time;

protected void Button2_Click(object sender, EventArgs e)

System.Threading.Thread.Sleep(5000);

string time = DateTime.Now.ToLongTimeString();

lbltotal.Text = "Showing time from outside " + time;

122
ANKIT TYAGI; ROLL NO 8990

Output:

123
ANKIT TYAGI; ROLL NO 8990

124
ANKIT TYAGI; ROLL NO 8990

125

You might also like