0% found this document useful (0 votes)
22 views61 pages

Awp Practical

The document contains code examples for several C# applications that demonstrate common programming concepts and operations: 1. An application that gets 4 integer values from the user and displays their product. 2. An application that demonstrates string operations like concatenation, length, uppercase/lowercase conversion, and trimming. 3. An application that gets student information (ID, name, course, date of birth) and displays it. 4. Applications that generate Fibonacci sequences, test for prime numbers, test for vowels in a character, and use a foreach loop with an array. 5. Applications that reverse a number, find the sum of its digits, and find the sum of the reverse number.

Uploaded by

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

Awp Practical

The document contains code examples for several C# applications that demonstrate common programming concepts and operations: 1. An application that gets 4 integer values from the user and displays their product. 2. An application that demonstrates string operations like concatenation, length, uppercase/lowercase conversion, and trimming. 3. An application that gets student information (ID, name, course, date of birth) and displays it. 4. Applications that generate Fibonacci sequences, test for prime numbers, test for vowels in a character, and use a foreach loop with an array. 5. Applications that reverse a number, find the sum of its digits, and find the sum of the reverse number.

Uploaded by

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

PRACTICAL NO:01

1) Create an application that obtain 4 integer value from the user


and display the product.

INPUT:
namespace ConsoleApp5
{
class Program
{
static void Main(string[] args)
{
int num1, num2, num3, num4, prod;
Console.Write("Enter number 1"); num1
= Int32.Parse(Console.ReadLine());
Console.Write("Enter number 2"); num2 =
Convert.ToInt32(Console.ReadLine()); Console.Write("Enter number 3");
num3 = Convert.ToInt32(Console.ReadLine());
Console.Write("Enter number 4"); num4 = Convert.ToInt32(Console.ReadLine());
prod = num1 * num2 * num3 * num4;
Console.WriteLine(num1 + "*" + num2 + "*" + num3 + "*" + num4 + "=" + prod);
Console.ReadKey();
}
}
}

OUTPUT:
2) Create an application to demonstrate string operations.

INPUT:

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

namespace String_2_
{
class Program
{
static void Main(string[] args)
{
string name, nam, concat;
Console.Write("Enter a String1:");
name = Console.ReadLine();
Console.Write("Enter a String2:");
nam = Console.ReadLine();
concat = name + nam;
Console.WriteLine("Concat:" + concat);
int len= concat.Length;
Console.WriteLine("Length:" + len);
Console.WriteLine("Uppercase:" + concat.ToUpper());
Console.WriteLine("Lowercase:" + concat.ToLower());
Console.WriteLine("Trim:" + concat.Trim());
Console.ReadKey();
}
}
}

OUTPUT:

3) Create an application that receive 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 enter.

INPUT:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Globalization;
using System.Reflection.Emit;

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

protected void Button1_Click(object sender, EventArgs e)


{
Label5.Text = "Student ID:" + TextBox4.Text;
Label2.Text = "Student Name:" + TextBox2.Text;
Label3.Text = "Course Name:" + TextBox3.Text;
Label4.Text = "DOB" + Calendar1.SelectedDate.ToShortDateString();
}
protected void Button2_Click(object sender, EventArgs e)
{
Label5.Text = "";
Label2.Text = "";
Label3.Text = "";
TextBox4.Text = "";
TextBox2.Text = "";
TextBox3.Text = "";
Calendar1.SelectedDates.Clear();
}
}
}

OUTPUT:
4) Create an application to demonstrate following operations:

1) Generate Fibonacci series.

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

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

}
protected void Button1_Click1(object sender, EventArgs e)
{
int a, b, c, i,number;
a = 0;
b = 1;
Label2.Text = a.ToString() + b.ToString();
number = Convert.ToInt32(TextBox1.Text);
for(i = 1; i <= number; ++i)
{
c = a + b;
Label2.Text = Label2.Text + c.ToString();
a = b;
b = c;
}

}
}
}

OUTPUT:
2)Test for prime numbers.

INPUT:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection.Emit;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace prime_number
{
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 flag = 0, m = 0; int n = int.Parse(TextBox1.Text); m = n / 2;
for (int i = 2; i <= m; i++)
{
if (n % i == 0)
{
Label1.Text = "Number is not prime:"; flag = 1; break;
}
}
if (flag == 0)
{
Label1.Text = "Number is prime:";
}

}
}
}

OUTPUT:

3) Test for vowels.

INPUT:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection.Emit;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace pract1_d2_
{
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
char c = Convert.ToChar(TextBox1.Text);
switch (c)
{
case 'a':
Label1.Text = "a is a vowel"; break;
case 'e':
Label1.Text = "e is a vowel"; break;
case 'i':
Label1.Text = "i is a vowel"; break;
case 'o':
Label1.Text = "o is a vowel"; break;
case 'u':
Label1.Text = "u is a vowel"; break;
default:
Label1.Text = "It is no vowel"; break;
}
}
}
}

OUTPUT:
4)Use of foreach loop with array.

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

namespace WebApplication1
{
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Label1.Text = "";
String[] Colorsnames = new string[] { "Red", "Yellow", "Black", "Green", "Blue" }; foreach (String ColorName in
Colorsnames)
{
Label1.Text = Label1.Text + " " + ColorName.ToString();
}
}
}
}

OUTPUT:
5) Reverse a number and find sum of digits of a number. \

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

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

}
protected void Button1_Click(object sender, EventArgs e)
{
long num, i, sum = 0;
num = Convert.ToInt32(TextBox1.Text);
while (num > 0)
{
i = num % 10;
sum = i + sum * 10;
num = num / 10;

}
Label2.Text = sum.ToString();
}
}
}

OUTPUT:
6) sum of reverse number

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

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

protected void Button1_Click(object sender, EventArgs e)


{
long num, i, sum = 0;
num = Convert.ToInt32(TextBox1.Text);
while(num > 0)
{
i = num % 10; sum = i + sum;
num = num / 10;

}
Label2.Text = sum.ToString();
}
}
}

OUTPUT:

PRACTICAL NO:02

A) Create simple application to perform following operations.

1) Money Conversion.

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

namespace currency_conveter
{
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 m;
int n = int.Parse(TextBox1.Text);
m = n * 82;
Label2.Text = m.ToString();
}
}
}

OUTPUT:

2) Temperature Conversion
INPUT:

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

namespace WebApplication3
{
public class tempConv
{
public double ctof(double temp)
{
temp = 9.0 / 5.0 * temp + 32;
return temp;
}
public double ftoc(double temp)
{
temp = (temp - 32) * 5 / 9;
return temp;
}
}

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


{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
tempConv s = new tempConv();
double n = Convert.ToDouble(TextBox1.Text);
double x = s.ctof(n);
Label1.Text = x.ToString();

protected void Button2_Click(object sender, EventArgs e)


{
tempConv s = new tempConv();
double n = Convert.ToDouble(TextBox2.Text);
double x = s.ftoc(n);
Label2.Text = x.ToString();
}
}
}

OUTPUT:
3) Finding factorial value

INPUT:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection.Emit;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace factorial
{
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 i, number;
int fact = 1;
number = int.Parse(TextBox1.Text);
for (i = 1; i <= number; i++)
{
fact = fact * i;
Label2.Text = fact.ToString();
}
}
}
}

4) Quadratic Equation.

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

namespace WebApplication4
{
public partial class WebForm1 : System.Web.UI.Page
{
public void demo()
{
double a, b, c, r1, r2, x;
double det;
a = Convert.ToInt32(TextBox1.Text);
b = Convert.ToInt32(TextBox2.Text);
c = Convert.ToInt32(TextBox3.Text);
det = (b * b) - (4 * a * c); if (det > 0)
{
x = Math.Sqrt(det);
r1 = (-b + x) / (2 * a);
r2 = (-b - x) / (2 * a);
Label3.Text = "there are two roots::";
Label1.Text = r1.ToString();
Label2.Text = r2.ToString();
}
else if (det == 0)
{
x = Math.Sqrt(det);
r1 = (-b + x) / (2 * a);
Label1.Text = "there is only one root::";
Label2.Text = r1.ToString();
}
else
{
Label1.Text = "there is no root!!!";
}
}
protected void Page_Load(object sender, EventArgs e)
{
}

protected void Button1_Click(object sender, EventArgs e)


{
demo();
}
}
}

OUTPUT:
B) Create simple application to demonstrate use of following
concepts.

1) Function Overloading.

INPUT:

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

namespace function_overloadding
{
public partial class WebForm1 : System.Web.UI.Page
{
public int add(int a)
{
return a + a;
}
public int add(int a, int b)
{
return a + b;
}
public int add(int a, int b, int c)
{
return a + b + c;
}
protected void Page_Load(object sender, EventArgs e)
{
int x, y, z; x = add(2); y = add(2,3);
z = add(2, 3, 4);
Label1.Text = x.ToString();
Label2.Text = y.ToString();
Label3.Text = z.ToString();
}
}
}

OUTPUT:

2) Inheritance (all type).

*Single Inheritance
INPUT:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection.Emit;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

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

protected void Button1_Click(object sender, EventArgs e)


{
C s = new C();
int n = Convert.ToInt32(TextBox1.Text);
int x = s.sqr(n);
int y = s.cubn(n);

Label2.Text = x.ToString();
Label3.Text = y.ToString();

}
}
public class A
{
public int sqr(int val1)
{
return val1 * val1;
}
}
public class B: A
{
public int cubn(int val1)
{
int v1 = sqr(val1);
return v1 * val1;
}
}
}

OUTPUT:
*Multilevel Inheritance

INPUT:

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

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

protected void Button1_Click(object sender, EventArgs e)


{
C s = new C();
int n = Convert.ToInt32(TextBox1.Text);
int x = s.sqr(n);
int y = s.cubn(n);
int z = s.pow(n);
Label2.Text = x.ToString();
Label3.Text = y.ToString();
Label4.Text = z.ToString();

}
}
public class A
{
public int sqr(int val1)
{
return val1 * val1;
}
}
public class B : A
{
public int cubn(int val1)
{
int v1 = sqr(val1);
return v1 * val1;
}
}
public class C : B
{
public int pow(int val1) { int v1 = cubn(val1); return v1 * val1; }
}
}

*Hierarchical Inheritance
INPUT:

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

namespace pract2
{
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 s1 = new B();
C s2 = new C();

int m = Convert.ToInt32(TextBox1.Text);
int n = Convert.ToInt32(TextBox2.Text);
int x = s1.add(m, n);
int y = s2.sub(m, n);
Label2.Text = x.ToString();
Label3.Text = y.ToString();

}
}
public class A
{
public int a; public int b;
}
public class B : A
{
public int add(int val1, int val2)
{
a = val1;
b = val2;
return a + b;
}
}
public class C : A
{
public int sub(int val1, int val2)
{
a = val1;
b = val2;
return a - b;
}
}
}
OUTPUT:

5) Constructor Overloading.

INPUT:

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

namespace Constructor
{
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(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();

}
}
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;
}
}
}

OUTPUT:
6) Interfaces.

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

namespace Interface
{
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);
}
}
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Rect r1 = new Rect();
double x = r1.show(5, 4);
Circle c1 = new Circle();
double y = c1.show(3, 4);
Label1.Text = x.ToString();
Label2.Text = x.ToString();

}
}
}

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

1) Using Delegates and events

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

namespace Deligets
{
public partial class WebForm1 : System.Web.UI.Page
{
public delegate void simpleDeligates();

public void CallingFunction()


{
Response.Write("First Function is called....<br>");
}
public void SetFunction()
{
Response.Write("Second Function is called...");
}
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
simpleDeligates sd = new simpleDeligates(CallingFunction);
sd(); sd += new simpleDeligates(SetFunction);
sd();

}
}
}

2) Exception handling.

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

namespace Exception
{
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;
resultVal = (b[3] / a);
Label1.Text = "The result is:" + resultVal.ToString();

}
catch (System.DivideByZeroException ex)
{
Label1.Text = ex.ToString();
}
catch (System.IndexOutOfRangeException ex)
{
Label1.Text = ex.ToString();
}

}
}
}

OUTPUT:
PRACTICAL NO:03
A) 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

INPUT:

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

namespace Calendar
{
public partial class WebForm1 : 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 == 18)
e.Cell.Controls.Add(new LiteralControl("</br>okkk"));

}
protected void Button1_Click(object sender, EventArgs e)
{
DateTime Ganapati_vacation_start = new DateTime(2023, 09, 30);
DateTime New_Year = new DateTime(2024, 01, 01);
TimeSpan Days_Left_for_Ganapati_vacation = Ganapati_vacation_start –
DateTime.Today;
TimeSpan Days_left_for_new_year = New_Year - DateTime.Today;
Label2.Text = Calendar1.TodaysDate.ToString("dd/mm/yyyy");
Label3.Text = Ganapati_vacation_start.ToString("dd/mm/yyyy");
Label4.Text = Days_Left_for_Ganapati_vacation.ToString("dd");
Label5.Text = Days_left_for_new_year.ToString("dd");
}
protected void Calendar1_SelectionChanged(object sender, EventArgs e)
{
Label1.Text = Calendar1.SelectedDate.ToString();
}
}
}

OUTPUT:

B) Demonstrate the use of Treeview control perform following


operations:
a) Treeview control and details

b) Treeview operations
INPUT:

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

namespace _3_b_
{
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;
DataList1.DataSource = T;
DataList1.DataBind();
DataList1.Visible = true;
}
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 collapse was:" + e.Node.Value);
}

}
}

OUTPUT:
C) Working with web form and control. a) Create a simple web page
with various sever controls to demonstrate setting and use of their
properties. (Example : AutoPostBack)

INPUT:

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

namespace _3a
{
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;
}
Label1.Text += " in " + s;
}
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
Label1.Text = "Your enrollment for " + DropDownList1.SelectedItem;
}
}

OUTPUT:
PRACTICAL NO:04

A) Create a Registration form to demonstrate use of various


Validation

INPUT:

#SOURCE
<%@ Page Language="C#" AutoEventWireup="true"
CodeBehind="WebForm1.aspx.cs" Inherits="PRACT4A.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 Name"></asp:Label>
:<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="TextBox1"
ErrorMessage="Name Required">
</asp:RequiredFieldValidator>
<br />
<br />
<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" ControlToValidate="TextBox2"
ErrorMessage="Password Required"></asp:RequiredFieldValidator>
<br />
<br />
<asp:Label ID="Label3" runat="server" Text="Confirm Password"></asp:Label>
:<asp:TextBox ID="TextBox3" runat="server" TextMode="Password"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server" ControlToValidate="TextBox3"
ErrorMessage="Password Required"></asp:RequiredFieldValidator>
<asp:CompareValidator ID="CompareValidator1" runat="server" ControlToCompare="TextBox2"
ControlToValidate="TextBox3" ErrorMessage="Password Dose Not Match"></asp:CompareValidator>
<br />
<br />
<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" ControlToValidate="TextBox4"
ErrorMessage="Age Required"></asp:RequiredFieldValidator>
<asp:RangeValidator ID="RangeValidator1" runat="server" ControlToValidate="TextBox4" ErrorMessage="Enter Age
Between 21-30" MaximumValue="30" MinimumValue="21" Type="Integer"></asp:RangeValidator>
<br />
<br />
<asp:Label ID="Label5" runat="server" Text="Enter Your Email id"></asp:Label>
:<asp:TextBox ID="TextBox5" runat="server" TextMode="Email"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator5" runat="server" ControlToValidate="TextBox5"
ErrorMessage="Email id Required"></asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" ControlToValidate="TextBox5"
ErrorMessage="Enter Email Properly" ValidationExpression="\w+([-
+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"></asp:RegularExpressionValidator>
<br />
<br />
<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" ControlToValidate="TextBox6"
ErrorMessage="User id Required"></asp:RequiredFieldValidator>
<br />
<br />
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Submit" />
<br />
</div>
</form>
</body>
</html>

//CONFIG

<configuration>
<appSettings>
<add key="ValidationSettings:UnobtrusiveValidationMode" value="None"></add>
</appSettings>
<system.web>
<compilation debug="true" targetFramework="4.7.2" />
<httpRuntime targetFramework="4.7.2" />
</system.web>
<system.codedom>
<compilers>
<compiler language="c#;cs;csharp" extension=".cs"
type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodePr ovider,
Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=2.0.1.0, Culture=neutral,
PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:default /nowarn:1659;1699;1701"
/>
<compiler language="vb;vbs;visualbasic;vbscript" extension=".vb"
type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.VBCodeProvid er,
Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=2.0.1.0, Culture=neutral,
PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:default /nowarn:41008
/define:_MYTYPE=\&quot;Web\&quot; /optionInfer+" />
</compilers>
</system.codedom>
</configuration>

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

protected void Button1_Click(object sender, EventArgs e)


{
Response.Write("Submit");
}
}
}

OUTPUT:
B) Create Web Form to demonstrate use of Ad-rotator Control

INPUT:

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


<Advertisements>
<Ad>
<ImageUrl>1.jpg</ImageUrl>
<NavigationUrl></NavigationUrl>
<AlternateText>Image one</AlternateText>
<Impression>3</Impression>
<Keyword>camera</Keyword>
</Ad>
<Ad>
<ImageUrl>2.jpg</ImageUrl>
<NavigationUrl></NavigationUrl>
<AlternateText>Image two</AlternateText>
<Impression>3</Impression>
<Keyword>Sajal</Keyword>
</Ad>
</Advertisements>

#SOURCE

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


CodeBehind="WebForm1.aspx.cs" Inherits="_4_2_.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>
</form>
</body>
</html>

OUTPUT:
C) Create Web Form to demonstrate use of user Controls

INPUT:
#USER CONTROL ASPX

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

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

#USER WEBFORM ASPX

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

namespace Pract4C
{
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 Guest" + TextBox1.Text;
}
}
}

#WEBFORM SOURCE
<%@ Page="" Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs"
Inherits="Pract4C.WebForm1" %>
<%@ Register="" Src="~/WebUserControl1.ascx" TagName="WebUserControl" TagPrefix="uc1" %>
<!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>
&nbsp;
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click"
Text="Button" /> &nbsp;
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
<br />
<uc1:WebUserControl runat="server"
id="WebUserControl1"></uc1:WebUserControl>
</div>
<p>
&nbsp;
</p>
</form>
</body>
</html>

OUTPUT:
PRACTICAL NO:05

A) Create Web Form to demonstrate use of Website Navigation controls


and SiteMap.

INPUT:

<?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="Home">
<siteMapNode url="WebForm2.aspx" title="First Page" description="First Page"/>
<siteMapNode url="WebForm3.aspx" title="Second Page" description="Second Page"/>
</siteMapNode>
</siteMap>

OUTPUT:
B) Create a web application to demonstrate use of Master Page with
applying Styles and Themes for page beautification

INPUT:

#WEBFORM1.ASPX

<%@ Page="" Title="" Language="C#" MasterPageFile="~/Site1.Master"


AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs"
Inherits="Pract_5B.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" SkinId="lb1" Text="Select Date:"></asp:Label>
<asp:Calendar ID="Calendar1" runat="server"></asp:Calendar>
<asp:HyperLink ID="HyperLink1" runat="server"
NavigateUrl="~/WebForm2.aspx">Next</asp:HyperLink>
<br />
</asp:Content>

#WEBFORM2.ASPX
<%@ Page="" Title="" Language="C#" MasterPageFile="~/Site1.Master"
AutoEventWireup="true" CodeBehind="WebForm2.aspx.cs"
Inherits="Pract_5B.WebForm2" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server"> </asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
<br/>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
</asp:Content>
//skin1.skin
<asp:Label runat="server" SkinId="lb1" backcolor="skyblue"/>

//stylesheet body

{
backgroundcolor:mistyrose;
font-family:italic;
}

#SITE1.MASTER

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


CodeBehind="Site1.master.cs" Inherits="Pract_5B.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 various State of
ASP.NET Pages

INPUT:

#WEBFORM1.ASPX.CS

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

namespace Pract_5C
{
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (IsPostBack)
{
if (ViewState["count"] != null)
{
int ViewstateVal = Convert.ToInt32(ViewState["count"]) + 1;

Label2.Text = "View State:" + ViewstateVal.ToString();


ViewState["count"] = ViewstateVal.ToString();
}
else
{
ViewState["count"] = "1";
}
}
}

protected void Button3_Click(object sender, EventArgs e)


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

protected void Button1_Click(object sender, EventArgs e)


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

protected void Button2_Click(object sender, EventArgs e)


{
HttpCookie h = new HttpCookie("name");
h.Value = TextBox1.Text;
Response.Cookies.Add(h);
Response.Redirect("Webform2.aspx");
}
}
}

#WEBFORM2.ASPX.CS
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

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

OUTPUT:
PRACTICAL NO:06
6)working with database.
a) Create a web application bind data in multiline textbox by querying in
another in textbox.

INPUT:
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 practical6a25_01
{
public partial class WebForm1 : System.Web.UI.Page
{
SqlConnection cn = new SqlConnection("Data Source=DESKTOP-
AU0KKJ2\\SQLEXPRESS; Initial Catalog = employee; Integrated Security = True; Pooling=False");
SqlCommand co = new SqlCommand();
SqlDataReader ds;

protected void Page_Load(object sender, EventArgs e)


{
cn.Open(); co.Connection = cn;
}
protected void Button1_Click(object sender, EventArgs e)
{
co.CommandText = "SELECT * FROM emp where name =@name"; co.Parameters.AddWithValue("@name",
TextBox1.Text); ds = co.ExecuteReader(); while (ds.Read())
{
TextBox2.Text += ds[0].ToString() + "\t" + ds[1].ToString() + "\t" + ds[2].ToString() + "\n";
}
}
}
}

OUTPUT:

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


INPUT:
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.Reflection.Emit;

namespace WebApplication20
{

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


{
SqlConnection cn = new SqlConnection("Data Source=DESKTOP-
M1G339B\\MYSQLSERVER; Initial Catalog = db3; Integrated Security = True");
SqlCommand co = new SqlCommand(); SqlDataReader ds;
protected void Page_Load(object sender, EventArgs e)
{
cn.Open(); co.Connection = cn;
}
protected void Button1_Click(object sender, EventArgs e)
{
co.CommandText = "select name from stud where rollno='" + TextBox1.Text + "';";
Label1.Text = co.ExecuteScalar().ToString();
}
}
}

OUTPUT:

c) Demonstrate the use of datalist link control.

INPUT:
<%@ Page Language="C#" AutoEventWireup="true"
CodeBehind="WebForm1.aspx.cs" Inherits="WebApplication21.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:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:db3ConnectionString %>"
SelectCommand="SELECT * FROM [stud]"></asp:SqlDataSource>
<br />
<br />
<asp:DataList ID="DataList1" runat="server"
DataSourceID="SqlDataSource1">
<ItemTemplate>
Rollno:
<asp:Label ID="RollnoLabel" runat="server"
Text='<%# Eval("Rollno") %>' /> <br /> name:
<asp:Label ID="nameLabel" runat="server"
Text='<%# Eval("name") %>' />
<br />
<br />
</ItemTemplate>
</asp:DataList>
</div>
</form>
</body>
</html>

OUTPUT:
PRACTICAL NO:07
A) Create a web application to display the databinding using dropdown list
control.

INPUT:
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 _7a
{
public partial class WebForm1 : System.Web.UI.Page
{
SqlConnection co = new SqlConnection("Data
Source = DESKTOP_TI18BNH\\MYSQLSERVER; Initial Catalog = db1; Integrated Security = True"); SqlCommand cn = new
SqlCommand(); SqlDataReader ds;
protected void Page_Load(object sender, EventArgs e)
{
co.Open(); cn.Connection = co;
}
protected void Button1_Click(object sender, EventArgs e)
{
cn.CommandText = "Select * from student ; "; ds = cn.ExecuteReader(); DropDownList1.DataSource = ds;
DropDownList1.DataTextField = "name";
DropDownList1.DataBind();
}
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
TextBox1.Text = DropDownList1.Text;
}
}
}

OUTPUT:

B) Create a web application to display the phone number of author using


database.

INPUT:
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.Reflection.Emit;

namespace _7b
{
public partial class WebForm1 : System.Web.UI.Page
{
SqlConnection cn = new SqlConnection("Data
Source = DESKTOP_TI18BNH\\MYSQLSERVER; Initial Catalog = db4; Integrated Security = True");
SqlCommand co = new SqlCommand(); SqlDataReader ds;
protected void Page_Load(object sender, EventArgs e)
{
cn.Open(); co.Connection = cn;
}
protected void Button1_Click(object sender, EventArgs e)
{
co.CommandText = "Select phone from author where name='" + TextBox1.Text + "';";
Label1.Text = co.ExecuteScalar().ToString();
}
}
}
OUTPUT:

C) Create a web application for inserting and deleting record from a


database. (Using Execute Non Query)

INPUT:
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 _7cdb
{
public partial class WebForm1 : System.Web.UI.Page
{
SqlConnection cn = new SqlConnection("Data
Source = DESKTOP_63TIL74\\SQLEXPRESS; Initial Catalog = 7c;Integrated Security = True");
SqlCommand co = new SqlCommand();
SqlDataReader ds;
SqlParameter @p1, @p2, @p3, @p4;
protected void Page_Load(object sender, EventArgs e)
{
cn.Open(); co.Connection = cn;
}
protected void Button1_Click(object sender, EventArgs e)
{
@p1 = new SqlParameter();
@p1.ParameterName = "sno";
@p1.SqlDbType = System.Data.SqlDbType.Int;
@p2 = new SqlParameter();
@p2.ParameterName = "name";
@p2.SqlDbType = System.Data.SqlDbType.VarChar;
@p3 = new SqlParameter();
@p3.ParameterName = "city";
@p3.SqlDbType = System.Data.SqlDbType.VarChar;
@p4 = new SqlParameter();
@p4.ParameterName = "class";
@p4.SqlDbType = System.Data.SqlDbType.VarChar; co.Parameters.AddWithValue("@p1", TextBox1.Text);
co.Parameters.AddWithValue("@p2", TextBox2.Text); co.Parameters.AddWithValue("@p3", TextBox3.Text);
co.Parameters.AddWithValue("@p4", TextBox4.Text); co.CommandText = "insert into data(sno,name,city,class)
values(@p1, @p2, @p3, @p4); "; co.ExecuteNonQuery();
}
protected void Button2_Click(object sender, EventArgs e)
{
co.CommandText = "delete from data where sno='" + TextBox1.Text + "';"; co.ExecuteNonQuery();
}
protected void Button3_Click(object sender, EventArgs e)
{
co.CommandText = "select * from data;";
ds = co.ExecuteReader();
GridView1.DataBind();
}
}
}

OUTPUT:
PRACTICAL NO:08
A) create a web application to demonstrate the various uses and
properties of data source.

INPUT:

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 pr8a

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

SqlCommand co = new SqlCommand();

SqlDataReader ds;

SqlDataSource s = new SqlDataSource();

protected void Page_Load(object sender, EventArgs e)

s.ConnectionString = "Data Source=DESKTOP-63TIL74\\SQLEXPRESS;Initial


Catalog = pr8a; Integrated Security = True";

protected void Button1_Click1(object sender, EventArgs e)


{

s.SelectCommand = "select * from students;";


GridView1.DataBind();

protected void Button2_Click1(object sender, EventArgs e)

SqlParameter p1 = new SqlParameter(), p2 = new SqlParameter(), p3 = new SqlParameter(), p4 =


new SqlParameter();

s.InsertParameters.Add("p1", System.Data.DbType.String, 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 student values(@p1,@p2,@p3,@p4);";


s.Insert(); }

protected void Button3_Click1(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.String, TextBox1.Text);

s.UpdateCommand = "update student SET name=@p2 where sno=@p1;";


s.Update(); }

protected void Button4_Click1(object sender, EventArgs e)

SqlParameter p1 = new SqlParameter();

s.DeleteParameters.Add("p1", System.Data.DbType.String, TextBox1.Text);

s.DeleteCommand = "delete student where sno=@p1;";


s.Delete();

OUTPUT:
B) Create a web application to demonstrate data binding using
DetailsView and FormView Control.

CODE:

C) Create a web application to display Using Disconnected Data Access


and Databinding using gridview.

DESIGN:
OUTPUT:

You might also like