You are on page 1of 157

Practical No: 1

A) Create an application that obtains four int values from


the user and displays the product.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace p1
{
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
int a, b, c, d, s;
a = int.Parse(TextBox1.Text);
b= int.Parse(TextBox2.Text);
c= int.Parse(TextBox3.Text);
d= int.Parse(TextBox4.Text);
s = a + b + c + d;
TextBox5.Text = s.ToString();
}
}
}
<%@ Page Language="C#" AutoEventWireup="true"
CodeBehind="four_int_values.aspx.cs"
Inherits="p1.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>
A<asp:TextBox ID="TextBox1" runat="server"
Width="175px"> </asp:TextBox>
</div>
<asp:Label ID="Label3" runat="server" Text="B">
</asp:Label>
<asp:TextBox ID="TextBox2" runat="server"> </asp:TextBox>
<br />
<asp:Label ID="Label4" runat="server" Text="C">
</asp:Label>
<asp:TextBox ID="TextBox3" runat="server"> </asp:TextBox>
<br />
<asp:Label ID="Label5" runat="server" Text="D"> </asp:Label>
<asp:TextBox ID="TextBox4" runat="server"> </asp:TextBox>
<br /> <br /> <br />
<asp:TextBox ID="TextBox5" runat="server"> </asp:TextBox>
<br />
<asp:Button ID="Button1" runat="server"
onclick="Button1_Click" Text="OK" /> <br /> </form>
</body>
</html>
OUTPUT

B) Create an application to demonstrate string operations.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace p1
{
public partial class WebForm2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
}
protected void TextBox2_TextChanged(object sender,
EventArgs e)
{
}
protected void Button1_Click1(object sender, EventArgs e)
{
string str1;
str1 = TextBox1.Text;
string[] words=str1.Split(' ');
for(int i = 0; i<words.Length; i++)
{
TextBox2.Text=TextBox2.Text+words[i]+"\r\n";
}
}
}
}

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


CodeBehind="string_operations.aspx.cs"
Inherits="p1.WebForm2" %>
<!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 text="0">
<form id="form1" runat="server">
<div> &nbsp;
<asp:TextBox ID="TextBox1" runat="server">
</asp:TextBox> <br />
<asp:TextBox ID="TextBox2" runat="server"
TextMode="MultiLine"> </asp:TextBox>
<br /> <br />
<asp:Button ID="Button1" runat="server"
onclick="Button1_Click1" style="height: 26px" Text="Button" />
<br />
</div>
</form>
</body>
</html>
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.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace p1
{
struct student
{
public string name, id, cname ;
public string dob;
}
public partial class WebForm3 : System.Web.UI.Page
{
static student[] s = new student[2];
static int i;
protected void Button2_Click(object sender, EventArgs e)
{
Response.Write("i=" + i);
s[i].id = TextBox1.Text;
s[i].name = TextBox2.Text;
s[i].cname = TextBox3.Text;
s[i].dob = TextBox4.Text;
i++;
}
protected void Button1_Click(object sender, EventArgs e)
{
for (int y = 0; y < i; y++)
{
Response.Write("i=" + y + "<br>");
Response.Write("Student id: " + s[y].id + "<br>");
Response.Write("student name: " + s[y].name + "<br> " );
Response.Write("Couse Name : " + s[y].cname + "<br>");
Response.Write("Date of Birth: " + s[y].dob + "<br>");
}
}
}
}

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


CodeBehind="Std_info.aspx.cs" Inherits="p1.WebForm3" %>
<!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:Label ID="Label1" runat="server" Text="Student Id">
</asp:Label>
<asp:TextBox ID="TextBox1" runat="server"> </asp:TextBox>
</div>
<asp:Label ID="Label2" runat="server" Text=" Student Name">
</asp:Label>
<asp:TextBox ID="TextBox2" runat="server">
</asp:TextBox> <br />
<asp:Label ID="Label3" runat="server" Text="Course Name">
</asp:Label>
<asp:TextBox ID="TextBox3" runat="server"> </asp:TextBox>
<br />
<asp:Label ID="Label4" runat="server" Text="Date of Birth">
</asp:Label>
<asp:TextBox ID="TextBox4" runat="server"> </asp:TextBox>
<br />
<br />
<br />
<asp:Button ID="Button1" runat="server"
onclick="Button1_Click" Text="display" />
<asp:Button ID="Button2" runat="server" Text="OK"
onclick="Button2_Click" />
</form>
</body>
</html>

OUTPUT
[i] Fibonacci Series

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

}
protected void Button1_Click(object sender, EventArgs e)
{
int f1 = 0, f2 = 1, f3, n, I ;
n = int.Parse(TextBox1.Text);
i = 0;
Response.Write("Fibonacci Series :");
Response.Write(f1 + "\t" + f2);
while (i <= n)
{
f3 = f1 + f2;
Response.Write("\t" + f3);
f1 = f2;
f2 = f3;
i++;
}
}
}
}
<%@ Page Language="C#" AutoEventWireup="true"
CodeBehind="Fibonacci_Series.aspx.cs"
Inherits="p1.Fibonacci_Series" %>
<!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="Enter a
number"> </asp:Label>
<asp:TextBox ID="TextBox1" runat="server"> </asp:TextBox>
<br />
<br />
<br />
<asp:Button ID="Button1" runat="server"
onclick="Button1_Click" Text="Button" />
</form>
</body>
</html>
OUTPUT

[II] Test for prime numbers.


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

protected void Button1_Click(object sender, EventArgs e)


{
int n, i;
n = int.Parse(TextBox1.Text);
for (i = 2; i <= n - 1; i++)
{
if ((n % i) == 0)
break;
}
if (n == 1)
Label2.Text = n + "is neither prime nor composite";
else if (i < n - 1)
Label2.Text = n + "is not prime number";
else
Label2.Text = n + "is prime number";
}
}
}
<%@ Page Language="C#" AutoEventWireup="true"
CodeBehind="prime_number.aspx.cs"
Inherits="p1.prime_number" %>
<!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:Label ID="Label1" runat="server" Text="Enter a number">
</asp:Label>
<asp:TextBox ID="TextBox1" runat="server"> </asp:TextBox>
<br /> <br />
<asp:Label ID="Label2" runat="server"> </asp:Label>
<br /> <br /> <br />
<asp:Button ID="Button1" runat="server"
onclick="Button1_Click" Text="Button" />
</form>
</body>
</html>
OUTPUT

[III] Test for vowels.


using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace p1
{
public partial class Test_vowels : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
string ch;
int count = 0;
ch = TextBox1.Text;
for ( int i = 0; i < ch.Length; i++)
{
if (( ch.Substring(i, 1) == "a") ||
( ch.Substring(i, 1) == "e") ||
( ch.Substring(i, 1) == "i") ||
( ch.Substring(i, 1) == "o") ||
( ch.Substring(i, 1) == "u"))
{
count++;
}
}
Response.Write("Give string:" + ch);
Label2.Text = "Total number of vowels:" + count;
}
}
}
<%@ Page Language="C#" AutoEventWireup="true"
CodeBehind="Test_vowels.aspx.cs" Inherits="p1.Test_vowels"
%>
<!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:Label ID="Label1" runat="server" Text="Enter a
character"> </asp:Label>
<asp:TextBox ID="TextBox1" runat="server"> </asp:TextBox>
<br /> <br />
<asp:Label ID="Label2" runat="server"> </asp:Label> <br />
<br />
<asp:Button ID="Button1" runat="server"
onclick="Button1_Click" Text="Button"/>
</div>
</form>
</body>
</html>
OUTPUT

[IV] foreach loop with arrays.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace p1
{
public partial class foreach_loop_arrays :
System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
int[] a = { 1, 2, 3, 4 };
foreach (int i in a)
Response.Write(i);
}
}
}

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


CodeBehind="foreach_loop_arrays.aspx.cs"
Inherits="p1.foreach_loop_arrays" %>
<!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:Button ID="Button1" runat="server"
onclick="Button1_Click" Text="Button" />
</div>
</form>
</body>
</html>
OUTPUT

[V] Reverse a number and find sum of digits of a number.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace p1
{
public partial class Reverse_number : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
int n, m, r = 0, d, sum = 0;
n = int.Parse(TextBox1.Text);
m = n;
while (n > 0)
{
d = n % 10;
r = r * 10 + d;
sum = sum + d;
n = n / 10;
}
Label2.Text = "Reverse of" + m + "=" + r + "<br>";
Label3.Text = " Sum of its digits:" + sum;
}
}
}

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


CodeBehind="Reverse_number.aspx.cs"
Inherits="p1.Reverse_number" %>
<!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:Label ID="Label1" runat="server" Text="Enter a
number"> </asp:Label>
<asp:TextBox ID="TextBox1" runat="server"> </asp:TextBox>
<br />
<asp:Label ID="Label3" runat="server"> </asp:Label> <br />
<br />
<asp:Label ID="Label2" runat="server"> </asp:Label> <br />
<asp:Button ID="Button1" runat="server"
onclick="Button1_Click" Text="OK" /> </div>
</form>
</body>
</html>

OUTPUT

Practical No.: 2
A) Create simple application to perform following
operation
[I] Finding factorial Value.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
class fact
{
public int n, f;
public fact()
{
f = 1;
}
public void cal()
{
int i;
for(i = 1; i <=n; i++)
{
f = f * i;
}
}
}

namespace P2
{
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
fact f1= new fact();
f1.n = int.Parse(TextBox1.Text);
f1.cal();
Label2.Text = f1.f.ToString();
}
}
}

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


codefile="Finding_factorial_Value.aspx.cs"Inherits="WebApplic
ation2.A.Finding_factorial_Value" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div> </div>
<asp:Label ID="Label1" runat="server" Text="Enter a
Number"> </asp:Label>
<asp:TextBox ID="TextBox1" runat="server"> </asp:TextBox>
<br /> <br />
<asp:Label ID="Label2" runat="server"> </asp:Label>
<br /> <br />
<asp:Button ID="Button1" runat="server"
OnClick="Button1_Click" Text="OK" />
</form>
</body>
</html>
OUTPUT

[II] Money Conversion

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

}
public class curConv
{
public double Dolr(double r)
{
r = r * 0.015;
return r;
}

public double Euros(double r)


{
r = r* 0.012;
return r;
}
public double Pound(double r)
{
r = r* 0.011;
return r;
}
public double Yen(double r)
{
r = r * 1.64;
return r;
}
}

protected void Button1_Click(object sender, EventArgs e)


{
curConv s = new curConv();
double r = Convert.ToDouble(TextBox1.Text);
double rate = s.Dolr(r);
Label2.Text = rate.ToString();
}
protected void Button2_Click(object sender, EventArgs e)
{
curConv s = new curConv();
double r = Convert.ToDouble(TextBox1.Text);
double rate = s.Euros(r);
Label3.Text = rate.ToString();
}

protected void Button3_Click(object sender, EventArgs e)


{
curConv s = new curConv();
double r = Convert.ToDouble(TextBox1.Text);
double rate = s.Pound(r);
Label4.Text = rate.ToString();
}

protected void Button4_Click(object sender, EventArgs e)


{
curConv s = new curConv();
double r = Convert.ToDouble(TextBox1.Text);
double rate = s.Yen(r);
Label5.Text = rate.ToString();
}
}
}

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


codefile="Money_Conversion.aspx.cs"
Inherits="WebApplication2.WebForm2" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Label ID="Label1" runat="server" Text="Enter Amount
in Rupees :"> </asp:Label>
<asp:TextBox ID="TextBox1" runat="server">
</asp:TextBox> <br /> <br />
<asp:Button ID="Button1" runat="server"
OnClick="Button1_Click" Text="US Dollars :" />
<asp:Label ID="Label2" runat="server"> </asp:Label>
<br />
<br />
<asp:Button ID="Button2" runat="server"
OnClick="Button2_Click" Text="Euros:" />
<asp:Label ID="Label3" runat="server"> </asp:Label>
<br />
<br />
<asp:Button ID="Button3" runat="server"
OnClick="Button3_Click" Text="Bitish Pounds:" />
<asp:Label ID="Label4" runat="server"> </asp:Label>
<br />
<br />
<asp:Button ID="Button4" runat="server"
OnClick="Button4_Click" Text="Japanese Yen :" />
<asp:Label ID="Label5" runat="server"> </asp:Label>
</div>
</form>
</body>
</html>

OUTPUT
[III] Quadratic Equation.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
class QuadraticEquation
{
public double a, b, c, r1,r2;
public double compute()
{
double d1;
d1 = b * b -4 * a * c;
if (d1 == 0 )
{
r1 = r2 = (-b) / (2 *a);
return d1;
}
else if (d1 > 0 )
{
r1 = (-b + Math.Sqrt(d1)) / (2 *a);
return d1;
}
else
{
r1 = (-b) / (2 * a);
r2 = Math.Sqrt(-d1) / (2 *a);
return d1;
}
}
}
namespace P2
{
public partial class Quadratic_Equation :
System.Web.UI.Page
{
QuadraticEquation q;
protected void Page_Load(object sender, EventArgs e)
{
q = new QuadraticEquation();
}

protected void TextBox1_TextChanged(object sender,


EventArgs e)
{
q.a = Convert.ToInt16(TextBox1.Text);
q.b = Convert.ToInt16(TextBox2.Text);
q.c = Convert.ToInt16(TextBox3.Text);
double d = q.compute();
if ( d == 0)
{
Response.Write("\nRoots are Real and Equal <br>");
Response.Write("Frist nd Second root is " + q.r1);
}
else if (d < 0)
{
Response.Write("\nRoots are Real and Distinct <br>");
Response.Write("\nFrit root is :" + q.r2);
Response.Write("\nSecond root is :" + q.r2 + "<br>");
}
else
{
Response.Write("\nRoots are Imaginary<br>");
Response.Write("\nFrit root is :" + q.r1 + "<br>");
Response.Write("\nSecond root is :" + q.r2 + "<br>");
}
}
}
}

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


codefile="Quadratic_Equation .aspx.cs"
Inherits="WebApplication2.A.Quadratic_Equation" %>
<!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>
<asp:TextBox ID="TextBox2"runat="server"> </asp:TextBox>
<asp:TextBox ID="TextBox3"runat="server">
</asp:TextBox>
<asp:TextBox ID="TextBox4"runat="server"> </asp:TextBox>
<asp:Button ID="Button1" runat="server"
OnClick="Button1_Click" Text="OK" />
</div> </form>
</body>
</html>
OUTPUT

[IV] Temperature Conversion


using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public class converttemp
{
public float celsius, faren;
public converttemp()
{
celsius = 0;
faren = 0;
}
public void converttofaren()
{
faren = ((celsius * 9.0f / 5.0f) + 32.0f);
}
public void converttocel()
{
celsius = (faren - 32) * (5.0f / 9.0f);
}
}
namespace P2
{
public partial class Temperature_Conversion :
System.Web.UI.Page
{
converttemp c;
protected void Page_Load(object sender, EventArgs e)
{
c = new converttemp();
}
protected void Button1_Click(object sender, EventArgs e)
{
char ch;
ch = Convert.ToChar(TextBox1.Text);
if (ch == 'c')
{
c.celsius = float.Parse(TextBox2.Text);
c.converttofaren();
Label2.Text = "celsius to Farenhe:" + c.faren;
}
else
{
c.faren = float.Parse(TextBox2.Text);
c.converttocel();
Label2.Text = "Farenheit to Celsius:" + c.celsius;
} } } }

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


codefile="Temperature_Conversion.aspx.cs"
Inherits="WebApplication2.A.Temperature_Conversion" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div> </div>
<asp:Label ID="Label1" runat="server" Text="Enter
Temperature"> </asp:Label>
<asp:TextBox ID="TextBox1" runat="server asp:TextBox>
<br /> <br />
<asp:Label ID="Label2" runat="server"> </asp:Label>
<asp:TextBox ID="TextBox2" runat="server"> </asp:TextBox>
<br /> <br />
<asp:Button ID="Button1" runat="server"
OnClick="Button1_Click" Text="Result" />
</form>
</body>
</html>
OUTPUT

B) Create simple application to demonstrate use of


following concepts.
[I] Function Overloading
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
class Overloading
{
public int sum(int a, int b)
{
int x;
return x = a + b;
}
public int sum(int a, int b, int c)
{
int y;
return y = a + b + c;
}
public float sum(float a, float b)
{
float u;
return u = a + b;
}
public float sum(float a, float b, float c)
{
float v;
return v = a + b + c;
}
}
namespace P2
{
public partial class Function_Overloading :
System.Web.UI.Page
{
Overloading o;
protected void Page_Load(object sender, EventArgs e)
{
o = new Overloading();
}
protected void Button1_Click(object sender, EventArgs e)
{
Label1.Text = Convert.ToString(o.sum(10, 20));
Label2.Text = Convert.ToString(o.sum(10, 20, 30));
Label3.Text = Convert.ToString(o.sum(23.1f, 32.5f));
Label4.Text = Convert.ToString(o.sum(12.0f, 23.1f, 32.5f));
} } }

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


Codefile="Function_overloading.aspx.cs"
Inherits="WebApplication2.B.Function_overloading" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div> &nbsp;
<asp:Button ID="Button1" runat="server"
OnClick="Button1_Click" Text="Function Overloading" />
&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br
/>
<asp:Label ID="Label1" runat="server" Text="Label">
</asp:Label> <br /> <br />
<asp:Label ID="Label2" runat="server" Text="Label">
</asp:Label> <br /> <br />
<asp:Label ID="Label3" runat="server" Text="Label">
</asp:Label> <br /> <br />
<asp:Label ID="Label4" runat="server" Text="Label">
</asp:Label> <br /> <br /> <br /> </div>
</form> </body> </html>
OUTPUT

[II] Inheritance (all types)


(a) Single Inheritance
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public class A
{
public int sqr(int Val1)
{
return Val1 * Val1;
}
}
public class B : A
{
public int cub(int Val1)
{
int v1 = sqr(Val1);
return v1* Val1;
}
}

namespace WebApplication2
{
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
B s = new B();
int n = Convert.ToInt32(TextBox1.Text);
int x = s.sqr(n);
int Y = s.cub(n);
Label4.Text = x.ToString();
Label5.Text = Y.ToString();
}
}
}

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


CodeBehind="Single.aspx.cs"
Inherits="WebApplication2.WebForm1" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org /1999/xhtml" >
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Label ID="Label1" runat="server" Text="Enter Number">
</asp:Label>
<asp:TextBox ID="TextBox1" runat="server"
OnTextChanged="TextBox1_TextChanged"> </asp:TextBox>
<asp:Button ID="Button1" runat="server"
OnClick="Button1_Click" Text="Result" /> <br /> <br /> <br />
<asp:Label ID="Label2" runat="server" Text="Square of a
Number :"> </asp:Label>
<asp:Label ID="Label4" runat="server"> </asp:Label>
<br /> <br />
<asp:Label ID="Label3" runat="server" Text="Cub of a number
:"> </asp:Label>
<asp:Label ID="Label5" runat="server"> </asp:Label>
<br />
<br />
<br />
<br />
<asp:Button ID="Button2" runat="server"
OnClick="Button2_Click" Text="Button" />
<br />
<br />
<br /> <br />
<br /><br />
</div>
</form>
</body>
</html>

OUTPUT

(b) Multiple inheritance


using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public class S
{
public int pow2(int Val1)
{
return Val1 * Val1;
}
}
public class P : S
{
public int pow3(int Val1)
{
int v1 = pow2(Val1);
return v1 * Val1;
}
}
public class Q : P
{
public int pow4(int Val1)
{
int v1 = pow3(Val1);
return v1 * Val1;
}
}
namespace WebApplication2._2B
{
public partial class Multilevel : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
Q s = new Q();
int n = Convert.ToInt32(TextBox1.Text);
int a = s.pow2(n);
int b = s.pow3(n);
int c = s.pow4(n);
Label8.Text = a.ToString();
Label9.Text = b.ToString();
Label10.Text =c.ToString();
}
}
}

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


CodeBehind="Multilevel.aspx.cs"
Inherits="WebApplication2._2B.Multilevel" %>
<!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="Label4" runat="server" Text="Enter Number">
</asp:Label>
<asp:TextBox ID="TextBox1"runat="server"> </asp:TextBox>
&nbsp;
<asp:Button ID="Button1" runat="server"
OnClick="Button1_Click" Text="Result" />
<br /> <br />
<asp:Label ID="Label5" runat="server" Text="Number is power
of 2 :"> </asp:Label>
<asp:Label ID="Label8" runat="server"> </asp:Label>
<br /> <br />
<asp:Label ID="Label6" runat="server" Text="Number is power
of 3 :"> </asp:Label>
<asp:Label ID="Label9" runat="server"> </asp:Label>
<br />
<br />
<asp:Label ID="Label7" runat="server" Text="Number is power
of 2 :"> </asp:Label>
<asp:Label ID="Label10" runat="server"> </asp:Label>
</div>
</form>
</body>
</html>

OUTPUT
C) Hierarchical Inheritance

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public class x
{
public int a;
public int b;
}
public class y : x
{
public int add( int val1 , int val2)
{
a = val1;
b = val2;
return a + b;
}
}
public class z : y
{
public int sub(int val1, int val2)
{ a = val1;
b = val2;
return a - b;
}
}
namespace WebApplication2
{
public partial class Hierarchical : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
y s1 = new y();
z s2 = new z();
int m = Convert.ToInt32(TextBox1.Text);
int n = Convert.ToInt32(TextBox2.Text);
int x = s1.add(m, n);
int y = s2.sub(m,n);
Label3.Text = x.ToString();
Label4.Text = y.ToString();
}
}
}

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


CodeBehind="Hierarchical.aspx.cs"
Inherits="WebApplication2.Hierarchical" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Label ID="Label1" runat="server" Text="Enter A">
</asp:Label>
<asp:TextBox ID="TextBox1"runat="server"> </asp:TextBox>
<br />
<br />
<asp:Label ID="Label2" runat="server" Text="Enter B">
</asp:Label>
<asp:TextBox ID="TextBox2"runat="server"> </asp:TextBox>
<br />
<br />
<asp:Button ID="Button1" runat="server"
OnClick="Button1_Click" style="margin-bottom: 0px"
Text="Result" />
<br /> <br /><br />
<asp:Label ID="Label5" runat="server">
A +B = </asp:Label> &nbsp;
<asp:Label ID="Label3" runat="server"> </asp:Label>
&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs;
<br /> <br />&nbsp;
<asp:Label ID="Label6" runat="server">
A -B = </asp:Label>
<asp:Label ID="Label4" runat="server"> </asp:Label>
<br /> <br /> <br /><br />
</div>
</form>
<p> &nbsp;</p>
</body>
</html>

OUTPUT
[iii] Constructor Overloadin

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

public class add


{
public int r;
public add(int a)
{
r = a + a;
}
public add(int a, int b)
{
r = a + b;
}
public add(int a, int b, int c)
{
r = a + b + c;
}
}

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

protected void Button1_Click(object sender, EventArgs e)


{
add obj1 = new add(2);
add obj2 = new add(2, 3);
add obj3 = new add(2, 3, 4);
Label1.Text= obj1.r.ToString();
Label2.Text= obj2.r.ToString();
Label3.Text= obj3.r.ToString();
}
}
}

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


CodeBehind="Constructor_Overloading.aspx.cs"
Inherits="WebApplication2.C.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:Button ID="Button1" runat="server"
OnClick="Button1_Click" Text="Constructor Overloading:" />
<br /><br />
<asp:Label ID="Label1" runat="server"> </asp:Label> <br />
<br />
<asp:Label ID="Label2" runat="server"> </asp:Label> <br />
<br />
<asp:Label ID="Label3" runat="server"> </asp:Label>
</div>
<p> &nbsp;</p>
</form>
</body>
</html>
OUTPUT
(iv) Interfaces

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
interface Area
{
double show(double s, double t);
}
class Rect : Area
{
public double show(double s, double t)
{
return s * t;
}
}
class Circle : Area
{
public double show(double s, double t)
{
return(3.14*s* s);
}
}
namespace WebApplication2.B
{
public partial class WebForm2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Rect r1 = new Rect();
double x = r1.show(3, 4);
Circle c1 = new Circle();
double y = c1.show(3, 4);
Label4.Text = x.ToString();
Label5.Text = y.ToString();
}
}
}

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


CodeBehind="Interface.aspx.cs"
Inherits="WebApplication2.B.WebForm2" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Label ID="Label1" runat="server" Text="Area of a circle
and rectangle using interface"> </asp:Label>
<br /> <br />
<asp:Label ID="Label2" runat="server" Text="Area of a cricle:">
</asp:Label>
<asp:Label ID="Label4" runat="server"> </asp:Label> <br />
<br />
<asp:Label ID="Label3" runat="server" Text="Area of rectangle
:"> </asp:Label>
<asp:Label ID="Label5" runat="server"> </asp:Label> </div>
</form>
</body> </html>
OUTPUT

(C) Create simple application to demonstrate use of following


concepts .
[i] Using Delegates and events

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

namespace WebApplication2.C
{
public partial class Delegate : System.Web.UI.Page
{
public delegate string dele();
public static string Display1()
{
string s1 = "Suraj Panday";
return s1;
}
public static string display2()
{
string s1 = "Ram sharma";
return s1;
}
protected void Page_Load(object sender, EventArgs e)
{
dele d1 = new dele(Display1);
d1();
dele d2 = new dele(display2);
d2();
Label1.Text = d1();
Label2.Text = d2();
}
}
}

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


CodeBehind="Delegate.aspx.cs"
Inherits="WebApplication2.C.Delegate" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Label ID="Label1" runat="server" Text="Label">
</asp:Label>
<br />
<asp:Label ID="Label2" runat="server" Text="Label">
</asp:Label>
</div>
</form>
</body>
</html>

OUTPUT
[ii] Exception handing.

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

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

protected void Button1_Click(object sender, EventArgs e)


{
try
{
int a = Convert.ToInt32(TextBox1.Text);
int[] b = { 12, 23, 33 };
int resultVal = (b[3] / a);
Label3.Text = "The result is :" + resultVal.ToString();
}
catch (System.DivideByZeroException ex)
{
Label3.Text = ex.ToString();
}catch (System.IndexOutOfRangeException ex)
{
Label3.Text = ex.ToString();
}
}
}
}

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


CodeBehind="Exception_handling.aspx.cs"
Inherits="WebApplication2.C.WebForm1" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Label ID="Label1" runat="server" Text="Division of two
numbers :"> </asp:Label>
<br /> <br />
<asp:Label ID="Label2" runat="server" Text="Num1 :">
</asp:Label>
<asp:TextBox ID="TextBox1" runat="server"> </asp:TextBox>
<br /> <br /> <asp:Button ID="Button1" runat="server"
OnClick="Button1_Click" Text="Result" />
<br /> <br />
<asp:Label ID="Label3" runat="server"> </asp:Label> </div>
</form></body></html>
OUTPUT
Practical No.: 3

A) Create a simple web page with various server controls to


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

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace P3.A
{
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 s;
if(RadioButton1.Checked == true)
{
s = RadioButton1.Text;
}
if (RadioButton2.Checked == true)
{
s = RadioButton2.Text;
}
else
{
s = RadioButton3.Text;
}
Label5.Text += "in" + s;
}
protected void DropDownList1 _SelectedIndexChanged(object
sender, EventArgs e)
{
Label5.Text = "You have been enrolled in" +
DropDownList1.SelectedItem;
}
}
}

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


Codefile="WebForm1.aspx.cs" Inherits="P3.A.WebForm1" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML
1.0Transitional//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:Label ID="Label1" runat="server" Text="RollNo">
</asp:Label>
<asp:TextBox ID="TextBox1"runat="server"> </asp:TextBox>
<br />
<asp:Label ID="Label2" runat="server" Text="Name">
</asp:Label>
<asp:TextBox ID="TextBox2"runat="server"> </asp:TextBox>
<br />
<asp:Label ID="Label3" runat="server" Text="Class">
</asp:Label> &nbsp;
<asp:RadioButton ID="RadioButton1"
runat="server" GroupName="A" Text="FY" />
<asp:RadioButton ID="RadioButton2"
runat="server" GroupName="A" Text="SY" />
<asp:RadioButton ID="RadioButton3" runat="server"
GroupName="A" Text="TY" />
<br />
<asp:Label ID="Label4" runat="server" Text="Course">
</asp:Label>
<asp:DropDownList ID="DropDownList1"
runat="server"onselectedindexchanged="DropDownList1_Sele
ctedIndexChanged">
<asp:ListItem>BSC-IT</asp:ListItem>
<asp:ListItem>Bcom</asp:ListItem>
<asp:ListItem>BFM</asp:ListItem>
</asp:DropDownList>
<br /> <br />
<asp:Button ID="Button1" runat="server" Text="Button"
onclick="Button1_Click" />
<br />
<br />
<asp:Label ID="Label5" runat="server"> </asp:Label>
</div>
</form>
</body>
</html>

OUTPUT
B) Demonstrate the use of Calendar control to perform
following operations.
[i] Display messages in a calendar control.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace P3.B
{
public partial class Display_message : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e){
} protected void Calendar1_DayRender (object sender,
DayRenderEventArgs e)
{ if (e.Day.Date.Day == 8)
e.Cell.Controls.Add(new LiteralControl ("</br>Holiday")); }
protected void Calendar1_SelectionChanged
(object sender, EventArgs e)
{}
} }

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


Codefile="Display_message.aspx.cs"
Inherits="P3.B.Display_message" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML
1.0Transitional//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:Calendar ID="Calendar1" runat="server" OnDayRender =
"Calendar1_DayRender" onselectionchanged
="Calendar1_SelectionChanged">
</asp:Calendar>
</form>
</body>
</html>

OUTPUT
[II] Display vacation in a calendarcontrol.

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

namespace P3.B
{
public partial class Display_Vacation : System.Web.UI.Page
{

protected void Page_Load(object sender, EventArgs e)


{

protected void Calendar1_DayRender


(object sender,DayRenderEventArgs e)
{
if ((e.Day.Date >= new DateTime(2023, 10, 18)) &&
(e.Day.Date <= new DateTime(2023, 10, 25)))
{
e.Cell.BackColor = System.Drawing
.Color.Blue;
e.Cell.BackColor = System.Drawing
.Color.Pink;
e.Cell.BorderWidth = new Unit(3);
}
}
protected void Calendar1_SelectionChanged
(object sender, EventArgs e)
{
}
}
}

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


Codefile="Display_Vacation.aspx.cs"
Inherits="P3.B.Display_Vacation" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML
1.0Transitional//EN""http://www.w3.org/T/
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:Calendar ID="Calendar1"
runat="server"OnDayRender="Calendar1_DayRender"onselect
ionchanged="Calendar1_SelectionChanged">
<DayHeaderStyle Font-Bold="True" Font-Size="8pt" />
<NextPrevStyle Font-Bold="True" Font-Size="8pt"
ForeColor="#333333"
VerticalAlign="Bottom" />
<OtherMonthDayStyle ForeColor="#999999"/>
<SelectedDayStyle BackColor="#333399" ForeColor="red" />
<TitleStyle BackColor="White" BorderColor="Black"
BorderWidth="4px"
Font-Bold="True" Font-Size="12pt" ForeColor="#333399" />
<TodayDayStyle BackColor="#CCCCCC" />
</asp:Calendar>

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

III) Selected day in a calendar control using style.

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

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

protected void Calendar1_DayRender


(object sender, DayRenderEventArgs e)
{
if((e.Day.Date >= new DateTime(2023, 10, 18)) && (e.Day.Date
<= new DateTime(2023, 10, 25)))
{
e.Cell.BackColor = System.Drawing
.Color.Blue;
e.Cell.BackColor = System.Drawing
.Color.Red;
e.Cell.BorderWidth = new Unit(3);
if(e.Day.IsOtherMonth)
{
e.Cell.Controls.Clear();

}
}
}

}
}

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


Codefile="selected_day.aspx.cs" Inherits="P3.B.selected_day"
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML
1.0Transitional//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:Calendar ID="Calendar1" runat="server"
OnDayRender="Calendar1_DayRender" > </asp:Calendar>

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

OUTPUT
IV) Difference between two calendardates.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace P3.B
{
public partial class WebForm2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
TimeSpan t = Calendar1.SelectedDate -
Calendar2.SelectedDate;
Label1.Text += t.Days.ToString(); }
}
}

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


Codefile="Two_Calendar.aspx.cs" Inherits="P3.B.WebForm2"
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML
1.0Transitional//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:Calendar ID="Calendar1" runat="server">
</asp:Calendar>
<asp:Calendar ID="Calendar2" runat="server">
</asp:Calendar>
<asp:Button ID="Button1" runat="server"
onclick="Button1_Click" Text="Button" />
<br /> <br />
<asp:Label ID="Label1" runat="server" Text="Number Of Days
is :"> </asp:Label>
</div>
</form>
</body>
</html>
OUTPUT
C) Demonstrate the use of Treeview control perform
following operations.
[i] Treeview control and datalist .

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace P3.C
{
public partial class WebForm1 : System.Web.UI.Page {
protected void Page_Load(object sender, EventArgs e) {
}
protected void Button1_Click(object sender, EventArgs e)
{ TreeNodeCollection T;
T = TreeView1.CheckedNodes;
DataList2.DataSource = T;
DataList2.DataBind();
DataList2.Visible = true; }
} }

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


Codefile="Treeview_Control.aspx.cs"
Inherits="P3.C.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>
<asp:TreeView ID="TreeView1" runat="server">
<Nodes>
<asp:TreeNode Text="BSC-IT" Value="BSC-IT"
Checked="True" ShowCheckBox="True">
<asp:TreeNode Text="FYBSC-IT" Value="FYBSC-IT"
Checked="True" ShowCheckBox="True">
</asp:TreeNode>
<asp:TreeNode Checked="True" ShowCheckBox="True"
Text="SYBSC-IT"
Value="SYBSC-IT"> </asp:TreeNode>
<asp:TreeNode Checked="True" ShowCheckBox="True"
Text="TYBSC-IT"
Value="TYBSC-IT"> </asp:TreeNode>
</asp:TreeNode>
<asp:TreeNode Text="Bcom" Value="Bcom" Checked="True"
ShowCheckBox="True">
<asp:TreeNode Text="FYBcom"Value="FYBcom"
Checked="True" ShowCheckBox="True"> </asp:TreeNode>
<asp:TreeNode Checked="True" ShowCheckBox="True"
Text="SYBcom" Value="SYBcom"> </asp:TreeNode>
<asp:TreeNode Checked="True" ShowCheckBox="True"
Text="TYBcom" Value="TYBcom"> </asp:TreeNode>
</asp:TreeNode>
</Nodes> </asp:TreeView>
<asp:DataList ID="DataList2" runat="server">
<ItemTemplate> <%# Eval("Text") %>
</ItemTemplate> </asp:DataList><br />
</div>
<asp:Button ID="Button1" runat="server"
onclick="Button1_Click" Text="Button" Width="56px" />
</form>
</body>
</html>
OUTPUT
[II] Treeview operations

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace P3.C
{
public partial class Treeview_operations : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{ }
protected void TreeView1_
SelectedNodeChanged (object sender, EventArgs e) {
Response.Write("You have selected the option:" +
TreeView1.SelectedValue); }
protected void TreeView1_
TreeNodeCollapsed (object sender, TreeNodeEventArgs e) {
Response.Write("The value Collapsed Was:" + e.Node.Value);
}
}
}

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


Codefile="Treeview_operations.aspx.cs"
Inherits="P3.C.Treeview_operations" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML
1.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:TreeView ID="TreeView1" runat="server"
OnTreeNodeCollapsed =
"TreeView1_SelectedNodeChanged">
<Nodes>
<asp:TreeNode Checked="True" ShowCheckBox="True"
Text="Bcom" Value="Bcom">
<asp:TreeNode Checked="True" Selected="True"
Text="FYBcom" Value="FYBcom"> </asp:TreeNode>
<asp:TreeNode Checked="True" ShowCheckBox="True"
Text="SYBcom" Value="SYBcom"> </asp:TreeNode>
<asp:TreeNode Checked="True" ShowCheckBox="True"
Text="TYBcom" Value="TYBcom"> </asp:TreeNode>
</asp:TreeNode>
<asp:TreeNode Checked="True" ShowCheckBox="True"
Text="BSC-IT" Value="BSC-IT">
<asp:TreeNode Checked="True" ShowCheckBox="True"
Text="FYBSC-IT"
Value="FYBSC-IT"> </asp:TreeNode>
<asp:TreeNode Checked="True" ShowCheckBox="True"
Text="SYBSC-IT"
Value="SYBSC-IT"> </asp:TreeNode>
<asp:TreeNode Checked="True" ShowCheckBox="True"
Text="TYBSC-IT"
Value="TYBSC-IT"> </asp:TreeNode>
</asp:TreeNode>
</Nodes>
</asp:TreeView>

</div>
</form>
</body>
</html>
OUTPUT
Practical No.: 4

A) Create a Registration from to demonstrate use of various


validation controls.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace p4.A
{ public partial class WebForm2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
} protected void Button1_Click(object sender, EventArgs
e)
{ Response.Write("Submitted"); }
}
}

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


CodeBehind="Validation_Controls.aspx.cs"
Inherits="p4.A.WebForm2" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;
<asp:Label ID="Label1" runat="server" Text="Enter Name">
</asp:Label> <asp:TextBox ID="TextBox1" runat="server">
</asp:TextBox> <asp:RequiredFieldValidator
ID="RequiredFieldValidator1" runat="server" ErrorMessage="
Name Required" ControlToValidate="TextBox1"
ForeColor="Red">
</asp:RequiredFieldValidator> <br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;
<asp:Label ID="Label2" runat="server" Text="Enter password">
</asp:Label> <asp:TextBox ID="TextBox2" runat="server"
TextMode="Password"> </asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator2"
runat="server" ErrorMessage=" password Required"
ControlToValidate="TextBox2" ForeColor="Red">
</asp:RequiredFieldValidator> <br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;
<asp:Label ID="Label3" runat="server" Text="Conform
password"> </asp:Label> <asp:TextBox ID="TextBox3"
runat="server" TextMode="Password"> </asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator3"
runat="server" ErrorMessage="Conform Required"
ControlToValidate="TextBox3" ForeColor="Red">
</asp:RequiredFieldValidator> nbsp;
<asp:CompareValidator ID="CompareValidator1"
runat="server" ControlToCompare="TextBox2"
ControlToValidate="TextBox3" ErrorMessage="Enter some
password">
</asp:CompareValidator> <br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;
<asp:Label ID="Label4" runat="server" Text="Enter Your Age">
</asp:Label> <asp:TextBox ID="TextBox4" runat="server">
</asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator4"
runat="server" ErrorMessage=" Enter Age Requiredr"
ControlToValidate="TextBox4" ForeColor="Red">
</asp:RequiredFieldValidator> &nbsp; <asp:RangeValidator
ID="RangeValidator1" runat="server"
ControlToValidate="TextBox4" ErrorMessage="Age Required
should be between into 21 to 30" MaximumValue="30"
MinimumValue="18" Type="Integer"> </asp:RangeValidator>
<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<asp:Label ID="Label6" runat="server" Text="User Id">
</asp:Label>
<asp:TextBox ID="TextBox6"runat="server">
</asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator6"
runat="server" ErrorMessage=" User Id Required"
ControlToValidate="TextBox6" ForeColor="Red">
</asp:RequiredFieldValidator><br />
&nbsp;<br /> <br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp; <asp:Button ID="Button1" runat="server"
Text="Button" Height="30px" Width="90px"
OnClick="Button1_Click" /><br />
</div>
</form>
<p> &nbsp;</p></body></html>
OUTPUT
B) Create a web form to demonstrate the Adrotator Control.

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

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

}
}
}

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


CodeBehind="Adrotator_Control.aspx.cs"
Inherits="p4.B.WebForm1" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
</div>
<asp:AdRotator ID="AdRotator1" runat="server"
DataSourceID="XmlDataSource1" />
<asp:XmlDataSource ID="XmlDataSource1"
runat="server"DataFile="~/B/XMLFile1.xml>
</asp:XmlDataSource>
</form>
</body>
</html>

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


<Advertisements>
<Ad>
<ImageUrl>Computer.jpg</ImageUrl>
<NavigatrUrl></NavigatrUrl>
<AlternateText>Computer</AlternateText>
<Impressions>50</Impressions>
<keyword>Computer</keyword>
</Ad>
<Ad>
<ImageUrl>Flower.jpg</ImageUrl>
<NavigatrUrl></NavigatrUrl>
<AlternateText>Flower</AlternateText>
<Impressions>50</Impressions>
<keyword>Flower</keyword>
</Ad>
</Advertisements>
OUTPUT
C) Create a web form to demonstrate use User Controls.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace p4.C
{
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
TextBox2.Text = "Hello:" + TextBox1.Text;
}
}
}

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


CodeBehind="User_Controls.aspx.cs"
Inherits="p4.C.WebForm1" %>
<%@ Register Src="~/C/WebUserControl1.ascx"
TagPrefix="uc1" TagName="WebUserControl1" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:TextBox ID="TextBox1" runat="server"> </asp:TextBox>
<asp:Button ID="Button1" runat="server"
OnClick="Button1_Click" Text="Button" />
<asp:TextBox ID="TextBox2" runat="server"> </asp:TextBox>
<br />
<uc1:WebUserControl1 runat="server" id="WebUserControl1"
/> </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 p4.C
{
public partial class WebUserControl1 :
System.Web.UI.UserControl
{

protected void Page_Load(object sender, EventArgs e)


{

}
protected void Button1_Click(object sender, EventArgs e)
{
TextBox2.Text = "Welcome:" + TextBox1.Text;

}
}
}

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


CodeBehind="WebUserControl1.ascx.cs"
Inherits="p4.C.WebUserControl1" %>
<asp:TextBox ID="TextBox1" runat="server"> </asp:TextBox>
<asp:Button ID="Button1" runat="server"
OnClick="Button1_Click" Text="Button" style="height: 26px" />
<asp:TextBox ID="TextBox2" runat="server"> </asp:TextBox>
OUTPUT
Practical no.: 5

A) Create a web Form to demonstrate use of Website


Navigation Controls.

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

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


CodeBehind="WebForm1.aspx.cs" Inherits="p5.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 />
<asp:Menu ID="Menu1" runat="server"
DataSourceID="SiteMapDataSource1">
</asp:Menu> </div>
<asp:SiteMapDataSource ID="SiteMapDataSource1"
runat="server" />
</form>
<p>
&nbsp;</p>
</body>
</html>

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

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

}
}
}
<%@ Page Language="C#" AutoEventWireup="true"
CodeBehind="WebForm2.aspx.cs" Inherits="p5.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:SiteMapDataSource ID="SiteMapDataSource1"
runat="server" />
<br />welcome to online store
</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 p5
{
public partial class WebForm3 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

}
}
}

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


CodeBehind="WebForm3.aspx.cs" Inherits="p5.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:SiteMapDataSource ID="SiteMapDataSource1"
runat="server" />
<br />hi welcome to online shopping : mobiles
</div>
</form>
</body>
</html>
<?xml version="1.0" encoding="utf-8" ?>
<siteMap
xmlns="http://schemas.microsoft.com/AspNet/SiteMap-File-1.0"
>

<siteMapNode url="WebForm1.aspx" title="Home"


description="">

<siteMapNode url="WebForm2.aspx" title="second page"


description="" />

<siteMapNode url="WebForm3.aspx" title="Third page"


description="" />

</siteMapNode>
</siteMap>

B) Create a web application to demonstrate use of Master Page


withapplying Styles and Themes for page beautification.

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

}
}
}

<%@ Page Title="" Language="C#"


MasterPageFile="~/B/Site1.Master" AutoEventWireup="true"
Codefile="WebForm1.aspx.cs" Inherits="p5.B.WebForm1"
Theme="Skin1" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head"
runat="server">
</asp:Content>
<asp:Content ID="Content2"
ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
<asp:Label ID="Label1" runat="server" Text="select the date"
Font-Size="Larger" ForeColor="Black"> </asp:Label>

<asp:Calendar ID="Calendar1" runat="server"


BackColor="#FFFFCC" BorderColor="White"> </asp:Calendar>
<asp:HyperLink ID="HyperLink1" runat="server"
NavigateUrl="~/B/WebForm2.aspx" Font-
Size="Larger">next</asp:HyperLink>
</asp:Content>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

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

<%@ Page Title="" Language="C#"


MasterPageFile="~/B/Site1.Master" AutoEventWireup="true"
CodeBehind="WebForm2.aspx.cs" Inherits="p5.B.WebForm2"
Theme="Skin1" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head"
runat="server">
</asp:Content>
<asp:Content ID="Content2"
ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
<asp:Label ID="Label1" runat="server" Text="Label" Font-
Size="Larger" ForeColor="Red"> </asp:Label>
<asp:TextBox ID="TextBox1" runat="server"> </asp:TextBox>
</asp:Content>
body {
background-color: lightpink;
font:italic;
}

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

namespace p5.B
{
public partial class Site1 : System.Web.UI.MasterPage
{
protected void Page_Load(object sender, EventArgs e) {
}
}
}

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


CodeBehind="Site1.master.cs" Inherits="p5.B.Site1" %>
<!DOCTYPE html>
<html>
<head runat="server">
<title></title>
<asp:ContentPlaceHolder ID="head" runat="server">
</asp:ContentPlaceHolder>
</head>
<body>
<link href="StyleSheet1.css"rel="stylesheet"type="text/css"
/>
<form id="form1" runat="server">
<div>
<asp:ContentPlaceHolder ID="ContentPlaceHolder1"
runat="server">
</asp:ContentPlaceHolder>
</div>
</form>
</body>
</html>
OUTPUT
C) Create a web application to demonstrate use of various
States of ASP.NET Pages.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace p5.C
{
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");
}
}
}

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


CodeBehind="WebForm1.aspx.cs" Inherits="p5.C.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" />
</div>
<asp:Label ID="Label1" runat="server" Text="Label">
</asp:Label>
<br />
<br />
<asp:Label ID="Label2" runat="server" Text="Label">
</asp:Label>
<br />
<br />
<br />
<asp:Button ID="Button1" runat="server"
OnClick="Button1_Click" Text="view state"/>
<p>
<asp:Button ID="Button2" runat="server"
OnClick="Button2_Click" Text="hidden field" />
</p>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<br />
<br />
<br />
<asp:Button ID="Button3" runat="server"
OnClick="Button3_Click" Text="cookies" />
</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 p5.C
{
public partial class WebForm2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if(Request.Cookies["name"] != null)
Response.Write("Welcome:" + Request
.Cookies["name"].Value);

}
}
}

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


CodeBehind="WebForm2.aspx.cs" Inherits="p5.C.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>
Practical no.: 6

A) Create a web application bind data in a multiline textbox


by querying in another textbox.

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

namespace P6
{
public partial class WebForm1 : System.Web.UI.Page
{
SqlConnection cn = new SqlConnection ("Data
Source=DESKTOP-MCVLTG2 \\ SQLEXPRESS;Initial
Catalog= Emp6;
Integrated Security=True;Pooling=False");
SqlCommand cmd = new SqlCommand();
SqlDataReader ds;
protected void Page_Load(object sender, EventArgs e)
{
cn.Open();
cmd.Connection = cn;
}

protected void Button1_Click(object sender, EventArgs e)


{
cmd.CommandText = "Select * from Emp_6 where name='" +
TextBox1.Text + "' ";
ds = cmd.ExecuteReader();
while (ds.Read())
{
TextBox2.Text +=ds[0].ToString() + "\t" + TextBox2.Text +
ds[1].ToString() + "\t" + TextBox2.Text + ds[2].ToString() + "\n";
}
}
}
}

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


CodeBehind="WebForm1.aspx.cs" Inherits="P6.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> </div>
<asp:TextBox ID="TextBox1" runat="server"> </asp:TextBox>
&nbsp;
<asp:TextBox ID="TextBox2" runat="server"
TextMode="MultiLine"> </asp:TextBox>
&nbsp;&nbsp;&nbsp;
<asp:Button ID="Button1" runat="server"
onclick="Button1_Click" Text="Button" />
<asp:SqlDataSource ID="SqlDataSource1" runat="server">
</asp:SqlDataSource>
</form>
</body>
</html>
OUTPUT
B)Create a web application to display records by using
database

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;

namespace P6.B
{
public partial class WebForm1 : System.Web.UI.Page
{
SqlConnection cn = new SqlConnection
("Data Source=DESKTOP-MCVLTG2\\
SQLEXPRESS;Initial Catalog=Emp6;
Integrated Security=True;Pooling=False");

SqlCommand cmd = new SqlCommand();


SqlDataReader ds;

protected void Page_Load(object sender, EventArgs e)


{
cn.Open();
cmd.Connection = cn;
}

protected void Button1_Click(object sender, EventArgs e)


{
cmd.CommandText = "Select name from Emp_6 where Id='" +
TextBox1.Text + "' ";
Label1.Text = cmd.ExecuteScalar() .ToString();

}
}
}

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


CodeBehind="WebForm1.aspx.cs" Inherits="P6.B.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>
<asp:TextBox ID="TextBox1" runat="server"> </asp:TextBox>
<asp:Button ID="Button1" runat="server"
onclick="Button1_Click" Text="Button" />
&nbsp;&nbsp;
<asp:Label ID="Label1" runat="server"> </asp:Label>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ConnectionStrings:Emp6ConnectionStr
ing %>"
SelectCommand="SELECT * FROM [emp_66]">
</asp:SqlDataSource>

</div>
</form>
</body>
</html>
OUTPUT
C) Demonstrate the use of datalist control.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace P6.C
{
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{ }
protected void DataList1_
SelectedIndexChanged(object sender, EventArgs e)
{ }
protected void SqlDataSource1_Selecting
(objectsender,SqlDataSourceSelectingEventArgs e)
{ }
}
}

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


CodeBehind="WebForm1.aspx.cs" Inherits="P6.C.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>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$
ConnectionStrings:Emp6ConnectionString2 %>"
SelectCommand="SELECT * FROM [emp_6]"
onselecting="SqlDataSource1_Selecting">
</asp:SqlDataSource> <br /><br />
<asp:DataList ID="DataList1" runat="server"
DataSourceID="SqlDataSource1"

onselectedindexchanged="DataList1_SelectedIndexChanged">
<ItemTemplate>
Id:<asp:Label ID="IdLabel" runat="server" Text='<%# Eval("Id")
%>' /> <br />
name:<asp:Label ID="nameLabel" runat="server"Text='<%#
Eval("name")%>' /> <br />
salary:<asp:Label ID="salaryLabel" runat="server" Text='<%#
Eval("salary") %>' /> <br /> <br />
</ItemTemplate>
</asp:DataList>
</div>
</form>
</body>
</html>
OUTPUT
Practical no.: 7
Aim: Working with Database
(A) Create a web application to display
Databinding using Dropdownlist control.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
namespace P7.A
{
public partial class WebForm1 : System.Web.UI.Page
{
SqlConnection cn = new SqlConnection
("Data Source=DESKTOP-MCVLTG2\\
SQLEXPRESS;Initial Catalog=Emp7;
Integrated Security=True;Pooling=False");
SqlCommand cmd = new SqlCommand();
SqlDataReader ds;
protected void Page_Load(object sender, EventArgs e)
{
cn.Open();
cmd.Connection = cn;
}

protected void Button1_Click(object sender, EventArgs e)


{

cmd.CommandText = "Select * from Emp_7 ";


ds = cmd.ExecuteReader();
DropDownList1.DataSource = ds;
DropDownList1.DataTextField = "name";
DropDownList1.DataBind();
}
protected void DropDownList1_
SelectedIndexChanged (object sender, EventArgs e)
{
TextBox1.Text = DropDownList1.Text;

}
}
}

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


CodeBehind="Display_databinding.aspx.cs"
Inherits="P7.A.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>
&nbsp;
<asp:TextBox ID="TextBox1"runat="server"> </asp:TextBox>
&nbsp; &nbsp; &nbsp; &nbsp;
<asp:Button ID="Button1" runat="server"
onclick="Button1_Click" Text="Button" />
&nbsp;&nbsp;&nbsp;
<asp:Label ID="Label1" runat="server"> </asp:Label>
&nbsp;
<asp:DropDownList ID="DropDownList1" runat="server"
onselectedindexchanged="DropDownList1_SelectedIndexChan
ged"> </asp:DropDownList>
<br />
<br />
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$
ConnectionStrings:Emp7ConnectionString2 %>"
SelectCommand="SELECT * FROM [emp_7]" >
</asp:SqlDataSource>
</div>
</form>
</body>
</html>

OUTPUT
(B) Create a web application for to display the phone no of an
author using database.

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;

namespace P7.B
{
public partial class WebForm1 : System.Web.UI.Page
{
SqlConnection cn = new SqlConnection
("Data Source=DESKTOP-MCVLTG2\\
SQLEXPRESS;Initial Catalog=Emp7;
Integrated Security=True");
SqlCommand cmd = new SqlCommand();
SqlDataReader ds;

protected void Page_Load(object sender, EventArgs e)


{
cn.Open();
cmd.Connection = cn;
}

protected void Button1_Click1(object sender, EventArgs e)


{
cmd.CommandText = "Select phoneno from emp_77 where
name = '" + TextBox1.Text + "'";
Label1.Text = cmd.ExecuteScalar()
.ToString();

}
}
}

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


CodeBehind="WebForm1.aspx.cs" Inherits="P7.B.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>
<asp:TextBox ID="TextBox1"runat="server"> </asp:TextBox>
&nbsp;&nbsp;&nbsp;<asp:Button ID="Button1" runat="server"
Text="OK" onclick="Button1_Click1" />
&nbsp;&nbsp;&nbsp;<asp:Label ID="Label1" runat="server">
</asp:Label> </div>
</form>
</body>
</html>
OUTPUT
C) Create a web application for inserting and deleting record
from a database.(Using Execute-Non Query).

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;

namespace P7.C
{
public partial class WebForm1 : System.Web.UI.Page
{
SqlConnection cn = new SqlConnection ("Data
Source=DESKTOP-MCVLTG2\\ SQLEXPRESS;Initial
Catalog=Emp7; Integrated Security=True");
SqlCommand cmd = new SqlCommand();
SqlDataReader ds;
SqlParameter @p1, @p2;

protected void Button3_Click(object sender, EventArgs e)


{
cmd.CommandText = "Select * from emp_7;";
ds = cmd.ExecuteReader();
GridView1.DataBind();
}

protected void Button1_Click(object sender, EventArgs e)


{
@p1 = new SqlParameter();
@p1.ParameterName = "Rollno";
@p1.SqlDbType = System.Data. SqlDbType.Int;

@p2 = new SqlParameter();


@p2.ParameterName = "name";
@p2.SqlDbType = System.Data. SqlDbType.VarChar;
cmd.Parameters.AddWithValue("@p1", TextBox1.Text);
cmd.Parameters.AddWithValue("@p2", TextBox2.Text);
cmd.CommandText = "insert into emp_7 (Rollno, name)
values('"+TextBox1.Text +"','"+TextBox2.Text +"')";
cmd.ExecuteNonQuery();

protected void Page_Load(object sender, EventArgs e)


{
cn.Open();
cmd.Connection = cn;
}

protected void Button2_Click1(object sender, EventArgs e)


{
cmd.CommandText = "delete from emp_7 where Rollno = '" +
TextBox1.Text + "'";
cmd.ExecuteNonQuery();
}

}
}

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


CodeBehind="WebForm1.aspx.cs" Inherits="P7.C.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> <asp:TextBox ID="TextBox1" runat="server">
</asp:TextBox>
<br />
<br />
<asp:TextBox ID="TextBox2"runat="server"> </asp:TextBox>
<br /> <br />
<br /> <br />
</div>
<asp:Button ID="Button1" runat="server"
onclick="Button1_Click" Text="Insert" />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<asp:Button ID="Button2" Text="Delete"
runat="server"onclick="Button2_Click1" />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<asp:Button ID="Button3" runat="server"
onclick="Button3_Click" Text="View" />
<asp:GridView ID="GridView1" runat= "server"
AutoGenerateColumns="False"
DataSourceID="SqlDataSource1"
EnableModelValidation="True">
<Columns>
<asp:BoundField DataField="Rollno" HeaderText="Rollno"
SortExpression = "Rollno" />
<asp:BoundField DataField="name" HeaderText="name"
SortExpression="name"/>
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings :
Emp7ConnectionString3 %>"
SelectCommand="SELECT * FROM [emp_7]">
</asp:SqlDataSource>
<br />
<br />
</form>
</body>
</html>
OUTPUT

Pr
Practical no.: 8

A) Create a web application to demonstrate various uses and


properties of SqlDataSource.

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;
namespace P8.A
{
public partial class WebForm1 : System.Web.UI.Page
{
SqlCommand cmd = new SqlCommand();
SqlDataReader ds;
SqlDataSource s = new SqlDataSource();
protected void Page_Load(object sender, EventArgs e)
{
s.ConnectionString = "Data Source=DESKTOP-
MCVLTG2\\SQLEXPRESS;Initial Catalog=Emp8;
Integrated Security=True";
}
protected void Button1_Click(object sender, EventArgs e)
{
s.SelectCommand = "Select * from Emp_8 ";
GridView1.DataBind();
}
protected void Button2_Click(object sender, EventArgs e)
{
SqlParameter p1 = new SqlParameter(),
p2 = new SqlParameter(),
p3 = new SqlParameter(),
p4 = new SqlParameter();
s.InsertParameters.Add("p1",System.Data.
DbType.Int32, TextBox1.Text);
s.InsertParameters.Add("p2", System.Data.DbType.String,
TextBox2.Text);
s.InsertParameters.Add("p3", System.Data
.DbType.String, TextBox3.Text);
s.InsertParameters.Add("p4", System.Data.
DbType.String, TextBox4.Text);
s.InsertCommand = "insert into Emp_8 values(@p1, @p2,
@p3, @p4)";
s.Insert();
}
protected void Button3_Click(object sender, EventArgs e)
{
SqlParameter p1 = new SqlParameter(),
p2 = new SqlParameter();
s.UpdateParameters.Add("p2", System.Data.DbType.String,
TextBox2.Text);
s.UpdateParameters.Add("p1", System.Data
.DbType.Int32, TextBox1.Text);
s.UpdateCommand = "update Emp_8 SET name=@p2 where
Id=@p1";
s.Update();
}
protected void Button4_Click(object sender, EventArgs e)
{
SqlParameter p1 = new SqlParameter();
s.DeleteParameters.Add("p1", System.Data.
DbType.Int32, TextBox1.Text);
s.DeleteCommand="delete Emp_8 where Id=
@p1";
s.Delete();
}
}
}

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


CodeBehind="Properties_Sqldatasource.aspx.cs"
Inherits="P8.A.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>
<asp:Label ID="Label1" runat="server" Text="Srno">
</asp:Label>
<asp:TextBox ID="TextBox1"
runat="server"></asp:TextBox><br /><br />
<asp:Label ID="Label2" runat="server" Text="name">
</asp:Label>
<asp:TextBox ID="TextBox2"runat="server"> </asp:TextBox>
<br /> <br />
<asp:Label ID="Label4" runat="server" Text="City">
</asp:Label>
<asp:TextBox ID="TextBox3"runat="server"> </asp:TextBox>
<br /> <br />
<asp:Label ID="Label5" runat="server" Text="Class">
</asp:Label>
<asp:TextBox ID="TextBox4"runat="server"> </asp:TextBox>
<br /> <br />
<asp:Button ID="Button1" runat="server"
onclick="Button1_Click" Text="View" />
&nbsp;&nbsp; <asp:Button ID="Button2" runat="server"
onclick="Button2_Click" Text="Insert" />
&nbsp;&nbsp;&nbsp;&nbsp;
<asp:Button ID="Button3" runat="server"
onclick="Button3_Click" Text="modify" />
&nbsp;&nbsp;&nbsp;&nbsp;
<asp:Button ID="Button4" runat="server" Text="Delete"
onclick="Button4_Click" />
<br /> <br /> <br />
<asp:GridView ID="GridView1"
runat="server"AutoGenerateColumns="False"
DataSourceID="SqlDataSource1"
EnableModelValidation="True">
<Columns>
<asp:BoundField DataField="Id" HeaderText="Id"
SortExpression="Id" />
<asp:BoundField DataField="name" HeaderText="name"
SortExpression="name" />
<asp:BoundField DataField="City" HeaderText="City" Sor
tExpression="City" />
<asp:BoundField DataField="class" HeaderText="class"
SortExpression="class" />
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$
ConnectionStrings:Emp8ConnectionString2 %>"
SelectCommand="SELECT * FROM [emp_8]">
</asp:SqlDataSource>
<br /> <br />
</div>
</form>
</body>
</html>
OUTPUT
B) Create a web application to demonstrate data binding
using DetailsView and FormView Control.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace P8
{
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{ }
protected void DetailsView1_
PageIndexChanging(object sender, DetailsViewPageEventArgs
e)
{
}
}
}

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


CodeBehind="DetailsView_FormViewControl.aspx.cs"
Inherits="P8.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:FormView ID="FormView1" runat="server"
AllowPaging="True"
DataSourceID="SqlDataSource1"
EnableModelValidation="True">
<EditItemTemplate>
Id:<asp:TextBox ID="IdTextBox" runat="server"Text='<%#
Bind("Id") %>' />
<br />
name:<asp:TextBox ID="nameTextBox"
runat="server"Text='<%# Bind("name")%>'/>
<br />
City:<asp:TextBox ID="CityTextBox" runat="server"Text='<%#
Bind("City")%>'/>
<br />
class:<asp:TextBox ID="classTextBox"
runat="server"Text='<%# Bind("class")%>' /> <br />
<asp:LinkButton ID="UpdateButton" runat="server"
CausesValidation="True"
CommandName="Update" Text="Update" />
&nbsp;<asp:LinkButton ID="UpdateCancelButton"
runat="server"
CausesValidation="False" CommandName="Cancel"
Text="Cancel" />
</EditItemTemplate>
<InsertItemTemplate>
Id:<asp:TextBox ID="IdTextBox" runat="server" Text='<%#
Bind("Id") %>' /> <br />
name:<asp:TextBox ID="nameTextBox"
runat="server"Text='<%# Bind("name")%>'/>
<br />
City:<asp:TextBox ID="CityTextBox" runat="server"Text='<%#
Bind("City")%>'/>
<br />
class:<asp:TextBox ID="classTextBox"
runat="server"Text='<%# Bind("class")%>' /> <br />
<asp:LinkButton ID="InsertButton" runat="server"
CausesValidation="True"
CommandName="Insert" Text="Insert" />
&nbsp;<asp:LinkButton ID="InsertCancelButton" runat="server"
CausesValidation="False" CommandName="Cancel"
Text="Cancel" />
</InsertItemTemplate>
<ItemTemplate>
Id:<asp:Label ID="IdLabel" runat="server" Text='<%# Bind("Id")
%>' /> <br />
name:<asp:Label ID="nameLabel" runat="server"Text='<%#
Bind("name")%>'/>
<br />
City:<asp:Label ID="CityLabel" runat="server"Text='<%#
Bind("City")%>'/>
<br />
class:<asp:Label ID="classLabel" runat="server"Text='<%#
Bind("class")%>' /> <br />

</ItemTemplate>
</asp:FormView><br />
<asp:DetailsView ID="DetailsView1" runat="server"
AllowPaging="True"
AutoGenerateRows="False" DataSourceID="SqlDataSource1"
EnableModelValidation="True"
Height="50px"onpageindexchanging
="DetailsView1_PageIndexChanging" Width="125px">
<Fields>
<asp:BoundField DataField="Id" HeaderText="Id"
SortExpression="Id" />
<asp:BoundField DataField="name"
HeaderText="name"SortExpression="name" />
<asp:BoundField DataField="City"
HeaderText="City"SortExpression="City" />
<asp:BoundField DataField="class"
HeaderText="class"SortExpression="class"/></Fields>
<HeaderTemplate> Emp list
</HeaderTemplate>
</asp:DetailsView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$
ConnectionStrings:Emp8ConnectionString4 %>"
SelectCommand="SELECT * FROM [emp_8]">
</asp:SqlDataSource>
</form>
</body>
</html>

OUTPUT
C) Create a web application to display Using Disconnected
Data Access and Databinding using GridView.

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;

namespace P8.C
{
public partial class WebForm1 : System.Web.UI.Page
{
SqlConnection cn = new SqlConnection
("Data Source=DESKTOP-MCVLTG2\\
SQLEXPRESS;Initial Catalog=Emp8;
Integrated Security=True");
SqlDataAdapter da;
DataSet ds = new DataSet();
protected void Page_Load(object sender, EventArgs e)
{

protected void Button1_Click(object sender, EventArgs e)


{
da = new SqlDataAdapter("Select * from Emp_8", cn);
da.Fill(ds, "x");
GridView1.DataSource = ds;
GridView1.DataBind();
}

}
}

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


CodeBehind="Properties_Sqldatasource.aspx.cs"
Inherits="P8.C.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>
<asp:GridView ID="GridView1" runat="server" >
</asp:GridView>
<br /> <br /> <br />
<br /> <br /> <br />
<asp:Button ID="Button1" runat="server"
onclick="Button1_Click" Text="Button" />
</div>
</form>
</body>
</html>

OUTPUT
.
Practical no.: 9

A) Create a web application to demonstrate use of


GridView control template and GridView hyperlink.

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;
namespace P9.A
{ public partial class WebForm1 : System.Web.UI.Page
{ protected void Page_Load(object sender, EventArgs e) {
}protected void Unnamed1_Selected
IndexChanged(object sender, EventArgs e){
} } }

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


Codefile="GridView_cntrol.aspx.cs" Inherits="P9.A.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 />
<asp:GridView ID="GridView1" runat="server"
AutoGenerateColumns="False"
DataKeyNames="Id"DataSourceID="SqlDataSource1"
EnableModelValidation="True">
<Columns>
<asp:CommandField ShowDeleteButton="True"
ShowEditButton="True" />
<asp:BoundField DataField="Id" HeaderText="Id"
ReadOnly="True" SortExpression="Id" />
<asp:TemplateField HeaderText="name"
SortExpression="name">
<EditItemTemplate>
<asp:DropDownList ID="DropDownList1" runat="server"
DataSourceID ="SqlDataSource2" DataTextField="name"
DataValueField="name" SelectedValue='<%#
Bind("name") %>'> </asp:DropDownList> <br />
<asp:SqlDataSource ID="SqlDataSource2" runat="server"
ConnectionString="<%$
ConnectionStrings:Emp9ConnectionString2 %>"
SelectCommand="SELECT DISTINCT [name] FROM
[emp_9]"> </asp:SqlDataSource>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%#
Bind("name") %>'> </asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="class"
HeaderText="class"SortExpression="class/>
</Columns>
</asp:GridView>
</div>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$
ConnectionStrings:Emp9ConnectionString2 %>"
DeleteCommand="DELETE FROM [emp_9] WHERE [Id] =
@Id"InsertCommand="INSERT INTO [emp_9] ([Id], [name],
[class]) VALUES (@Id, @name, @class)"
SelectCommand="SELECT * FROM [emp_9]"
UpdateCommand="UPDATE [emp_9] SET [name] =@name,
[class] = @class WHERE [Id] = @Id">
<DeleteParameters>
<asp:Parameter Name="Id" Type="Int32" />
</DeleteParameters>
<InsertParameters>
<asp:Parameter Name="Id" Type="Int32" />
<asp:Parameter Name="name"Type="String"/>
<asp:Parameter Name="class"Type="String" />
</InsertParameters> <UpdateParameters>
<asp:Parameter Name="name"Type="String"/>
<asp:Parameter Name="class"Type="String" />
<asp:Parameter Name="Id" Type="Int32" />
</UpdateParameters> </asp:SqlDataSource>
</form>
</body>
</html>

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

namespace P9.A
{

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


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

}
}
}

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

CodeBehind="Gridview_hyperlinkaspx.aspx.cs"
Inherits="P9.A.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>

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


AutoGenerateColumns="False"
DataKeyNames="Id" DataSourceID="SqlDataSource1"
EnableModelValidation="True">
<Columns>
<asp:HyperLinkField DataNavigateUrlFields="Id"

DataNavigateUrlFormatString="WebForm3.aspx?Id=(0)"
DataTextField="name"
Text="name" />
</Columns>
</asp:GridView>
<br />
<br />
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$
ConnectionStrings:Emp9ConnectionString2 %>"
SelectCommand="SELECT [Id], [name] FROM
[emp_9]"></asp:SqlDataSource>
<asp:AccessDataSource ID="AccessDataSource1"
runat="server">
</asp:AccessDataSource>

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

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

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

protected void GridView1_SelectedIndexChanged(object


sender, EventArgs e)
{
}
}

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


Codefile="WebForm3.aspx.cs" Inherits="P9.A.WebForm3" %>

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


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

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:DetailsView ID="DetailsView1" runat="server"
AutoGenerateRows="False"
DataKeyNames="Id"DataSourceID="SqlDataSource1"
EnableModelValidation="True"
Height="50px" Width="125px">
<Fields>
<asp:BoundField DataField="Id" HeaderText="Id"
ReadOnly="True"
SortExpression="Id" />
<asp:BoundField DataField="name" HeaderText="name"
SortExpression="name" />
<asp:BoundField DataField="class"
HeaderText="class"SortExpression="class" />
</Fields>
</asp:DetailsView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$
ConnectionStrings:Emp9ConnectionString3 %>"
SelectCommand="SELECT * FROM [emp_9]">
</asp:SqlDataSource>
</div>
</form>
</body>
</html>

OUTPUT
B) Create a web application to demonstrate use of GridView
button column and GridView events.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace P9.B
{ public partial class WebForm11 : System.Web.UI.Page
{ protected void Page_Load(object sender, EventArgs e)
{
}
protected void GridView1_RowCommand
(object sender, GridViewCommandEventArgs e) {
if (e.CommandName == "B1") {
GridView1.Rows[Convert.ToInt16(e.CommandArgument)].Back
Color = System.Drawing.Color.Blue;
}
}
}
}

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


CodeBehind="WebForm1.aspx.cs"
Inherits="P9.B.WebForm11" %>

<!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="GridView1" runat="server"
AutoGenerateColumns="False"
DataKeyNames="Id"DataSourceID="SqlDataSource1"
EnableModelValidation="True"
onrowcommand="GridView1_RowCommand">
<Columns>
<asp:BoundField DataField="Id" HeaderText="Id"
ReadOnly="True"
SortExpression="Id" />
<asp:BoundField DataField="Name" HeaderText="Name"
SortExpression="Name" />
<asp:BoundField DataField="Class" HeaderText="Class"
SortExpression="Class" />
<asp:ButtonField CommandName=" B1" Text="Button" />
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$
ConnectionStrings:Emp9ConnectionString3 %>"
SelectCommand="SELECT * FROM [emp_99]">
</asp:SqlDataSource>

</div>
</form>
</body>
</html>
OUTPUT
C) Create a web application to demonstrate GridView paging
and Creating own table format using GridView.

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

namespace P10.B
{
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
System.Threading.Thread.Sleep(2000);
}

protected void Button1_Click(object sender, EventArgs e)


{
TextBox1.Text = DateTime.Now.
ToLongTimeString();

}
}
}
<%@ Page Language="C#" AutoEventWireup="true"
Codefile="WebForm1.aspx.cs" Inherits="P10.B.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:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<br />
<br />
<asp:Button ID="Button1" runat="server"
OnClick="Button1_Click" Text="Show Time"/>
<br />
<br />
<br />
<asp:TextBox ID="TextBox1" runat="server" Height="22px"
Width="128px"> </asp:TextBox>
<br />
<br />
<br />
<br />
<asp:UpdateProgress ID="UpdateProgress1" runat="server">
<ProgressTemplate>
Please wait some time
</ProgressTemplate>
</asp:UpdateProgress>
<br />
<br />
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
</asp:UpdatePanel>
</div>
</form>
</body>
</html>

OUTPUT
Practical no.: 10
A) Create a web application to demonstrate reading and
writing operation with XML.

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


xmlns="Pooja"><rollNo xmlns="1" /></Name></Student>

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.Xml;
namespace P10
{
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
XmlReader red = XmlReader.Create
((@"P:\\pratical\\AWP\\P10\\P10\\A\\XMLFile1.xml"));
while(red.Read())
{
if(red.NodeType.Equals(XmlNodeType.Element))
{
string s = Label1.Text + "";
Label1.Text = s + red.Name;
}
}
red.Close();
}
protected void Button2_Click(object sender, EventArgs e)
{
using (XmlWriter xml = XmlWriter.Create
(@"P:\\pratical\\AWP\\P10\\P10\\A\\XMLFile1.xml"))
{
xml.WriteStartElement("Student");
xml.WriteStartElement("Name", "Pooja");
xml.WriteStartElement("rollNo", "1");
xml.WriteEndElement();
}
Response.Write("OK");
}
}
}

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


CodeBehind="WebForm1.aspx.cs" Inherits="P10.WebForm1"
%>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<br />
<asp:Label ID="Label1" runat="server"> </asp:Label>
<br />
<asp:Button ID="Button1" runat="server" Text="Read XML"
OnClick="Button1_Click" style="margin-top: 0px" />
<br />
</div>
<asp:GridView ID="GridView1" runat="server"
AutoGenerateColumns="False" >
<Columns>
<asp:BoundField DataField="name" HeaderText="name" />
<asp:BoundField DataField="rollNo" HeaderText="rollNo" />
</Columns>
</asp:GridView>
<br />
<br />
<asp:Button ID="Button2" runat="server" Text="Write XML"
OnClick="Button2_Click" />
</form>
</body>
</html>

OUTPUT
C)Create web application to demonstrate use of various Ajax
controls.

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.Xml;
namespace P10.B {
public partial class WebForm1 : System.Web.UI.Page {
protected void Page_Load(object sender, EventArgs e) {
System.Threading.Thread.Sleep(2000);
}
protected void Button1_Click(object sender, EventArgs e) {
TextBox1.Text = DateTime.Now
.ToLongTimeString();
}
}
}

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


Codefile="WebForm1.aspx.cs" Inherits="P10.B.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:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<br />
<br />
<asp:Button ID="Button1" runat="server"
OnClick="Button1_Click" Text="Show Time" />
<br />
<br />
<br />
<asp:TextBox ID="TextBox1" runat="server"
Height="22px" Width="128px"></asp:TextBox>
<br />
<br />
<br />
<br />
<asp:UpdateProgress ID="UpdateProgress1"
runat="server">
<ProgressTemplate>
Please wait some time
</ProgressTemplate>
</asp:UpdateProgress>
<br />
<br />
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
</asp:UpdatePanel>
</div>
</form>
</body>
</html>

OUTPUT
Practical no.: 11

Step 1: Open Visual Studio and Create New Project by Clicking


New->Project
Step 2: Select 'Class Library' from the list and click Ok.
Step 3:Now you will see the following s

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

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

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

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

}
protected void Button1_Click(object sender, EventArgs e)
{
Class1 c1 = new Class1();
Label1.Text = "Addition" + c1.addd(10, 34);
}
}
}

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


CodeBehind="DLL.aspx.cs" Inherits="P111.WebForm1" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Label ID="Label1" runat="server"
Text="Label"></asp:Label>
<br />
<asp:Button ID="Button1" runat="server"
OnClick="Button1_Click" Text="Button" />
</div>
</form>
</body>
</html>

OUTPUT

You might also like