[go: up one dir, main page]

0% found this document useful (0 votes)
120 views49 pages

Adin AWP PracticalManual

The document contains code for several C# and ASP.NET practical assignments involving basic and object-oriented programming concepts. It includes code to get user input and perform operations like calculating the product of numbers, string manipulation, storing student records in an array, Fibonacci series, checking for prime numbers and vowels, reversing numbers and summing digits. The code demonstrates classes, objects, properties, methods, loops, conditional statements, arrays and other programming fundamentals.

Uploaded by

Ghost Knight
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)
120 views49 pages

Adin AWP PracticalManual

The document contains code for several C# and ASP.NET practical assignments involving basic and object-oriented programming concepts. It includes code to get user input and perform operations like calculating the product of numbers, string manipulation, storing student records in an array, Fibonacci series, checking for prime numbers and vowels, reversing numbers and summing digits. The code demonstrates classes, objects, properties, methods, loops, conditional statements, arrays and other programming fundamentals.

Uploaded by

Ghost Knight
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/ 49

Mohammed

Adin Dawood
Shaikh
Roll no: 345
TYIT
AWP Practical
Manual
1
Page
Practical 1 :Working with basic C# and ASP.NET
Practical 1a : Create an application that four int values from the user and displays the product
Design:

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

public partialclassPractical1a :System.Web.UI.Page


{
protected voidPage_Load(object sender, EventArgs e)
{

protected void Button1_Click(object sender, EventArgs e)


{
int num1 = Convert.ToInt32(TextBox1.Text.ToString());
int num2 = Convert.ToInt32(TextBox2.Text.ToString());
int num3 = Convert.ToInt32(TextBox3.Text.ToString());
int num4 = Convert.ToInt32(TextBox4.Text.ToString());
int product = num1 * num2 * num3 * num4;
result.Text = "Product of numbers:" + product;
}
}

Output:
2

--------------------------------------------------------------------------------
Page
Practical 1b : Create an application to demonstrate string operations.
Design:

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

public partialclassPractical1b :System.Web.UI.Page


{
protected voidPage_Load(object sender, EventArgs e)
{

protected voidSubmit_Click(object sender, EventArgs e)


{
String str1 = TextBox1.Text.ToString();
String str2 = TextBox2.Text.ToString();

if (DropDownList1.SelectedItem.Text.Equals("Concate"))
{
result.Text = "Concatinate String : " + (str1 + str2);
}
elseif (DropDownList1.SelectedItem.Text.Equals("UpperCase"))
{
result.Text = "<br>" + "Upper case of String :" + "<br>" + (str1.ToUpper() + "" + str2.ToUpper());
}
elseif (DropDownList1.SelectedItem.Text.Equals("LowerCase"))
{
result.Text = "<br>" + "Lower case of String :" + "<br>" + (str1.ToLower() + "" + str2.ToLower());
}
elseif (DropDownList1.SelectedItem.Text.Equals("Length"))
{
result.Text = "<br>" + "Length of first string " + str1 + "<br>" + str1.Length;
}
elseif (DropDownList1.SelectedItem.Text.Equals("IsEmpty"))
{
if(String.IsNullOrEmpty(str1)&&String.IsNullOrEmpty(str2))
{
3

result.Text = "<br>" + "Both the textbox is empty";


Page
}
elseif(String.IsNullOrEmpty(str1))
{
result.Text = "TextBox 1 is Empty";
}
elseif(String.IsNullOrEmpty(str2))
{
result.Text = "TextBox 2 is Empty";
}
else
{
result.Text = "None of the TextBox is Empty";
}
}
elseif (DropDownList1.SelectedItem.Text.Equals("Reverse"))
{
String reverse1 = newstring(str1.Reverse().ToArray());
String reverse2 = newstring(str2.Reverse().ToArray());
result.Text = "Reverse of 1st string :" + reverse1;

}
}
}

Output:

4
Page
--------------------------------------------------------------------------
Practical 1c : 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.
Design:

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

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


{
struct student
{
public string id, name, cname, dob;
}
;
static student[] s = new student[5];
static int i;

protected void Page_Load(object sender, EventArgs e)


{

}
5
Page

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("Course Name= " + s[y].cname + "<br>");
Response.Write("Date Of Birth= " + s[y].dob + "<br>");
}
}
}

Output:

--------------------------------------------------------------------------

Practical 1c(ii): Create an application to demonstrate following strings:


a)Generate Fibonacci Series.
b)Test for prime numbers.
c)Test for vowels.
d)Use of foreach loops.
e)Reverse a number and find sum of digits of a number.

Design:
6
Page
1d.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partialclass_1d :System.Web.UI.Page


{
protected voidPage_Load(object sender, EventArgs e)
{

protected void Button1_Click(object sender, EventArgs e)


{
if (DropDownList1.SelectedItem.Text.Equals("Fibonacci"))
{
intusrInputNum = Convert.ToInt32(TextBox1.Text.ToString());
intfstNo = 0;
intsecNo = 1;
int sum = 0;
Response.Write("fibonacciseries :" + fstNo + "," + secNo);
inti = 2;
while (i<usrInputNum)
{
sum = fstNo + secNo;
Response.Write("," + sum);
fstNo = secNo;
secNo = sum;
i++;
}
}

elseif (DropDownList1.SelectedItem.Text.Equals("Prime"))
{
int num1 = Convert.ToInt32(TextBox1.Text.ToString());
inti;
for (i = 2; i< num1 - 1; i++)
if (num1 % i == 0)
break;
if (i< num1 - 1)
{
result.Text = "IS NOT A PRIME NO";

else
{
result.Text = "A PRIME NUMBER";
}

elseif (DropDownList1.SelectedItem.Text.Equals("vowels"))
{
string str = TextBox1.Text.ToString().ToLower();
int c = 0;
for (inti = 0; i<str.Length; i++)
{
if ((str.Substring(i, 1)) == "a" || (str.Substring(i, 1)) == "e" || (str.Substring(i, 1)) == "i" ||
(str.Substring(i, 1)) == "o" || (str.Substring(i, 1)) == "u")
7

{
Page

c++;
}
}

result.Text = ("Total number of vowels in " + str + " is " + c);


}

elseif (DropDownList1.SelectedItem.Text.Equals("Reverse and find sum of digits"))


{
int num1 = Convert.ToInt32(TextBox1.Text.ToString());
int rev = 0;
int sum = 0;
while (num1 != 0)
{
int remainder = num1 % 10;
rev = rev * 10 + remainder;
sum = remainder + sum;
num1 = num1 / 10;
}
result.Text = "<br>" + "Reverse of entered number is " + rev + "<br>" + "sum of digits is " + sum;

elseif(DropDownList1.SelectedItem.Text.Equals("foreach loop"))
{
string s = TextBox1.Text.ToString();
foreach (char c in s)

{
Response.Write("<br>" + c);

}}}
Output: (a)

(b) (c)
8
Page
(d) (e)

---------------------------------------------------------------------------------
---------------------------------------------------------------------------------

9
Page
Practical 2 : Working with Object Oriented C# and ASP.NET
Practical 2a : Create simple application to perform following operation
i) Finding factorial Value
Design :

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

public partialclass_2ai :System.Web.UI.Page


{
protected voidPage_Load(object sender, EventArgs e)
{

protected void Button1_Click(object sender, EventArgs e)


{
int n = Int32.Parse(TextBox1.Text);
facto fa = newfacto(n);
TextBox2.Text = fa.f.ToString();
}
}
Facto.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

publicclassfacto
{
publicinti, f = 1, n;
publicfacto(intnum)
{
n = num;
for (i = 1; i<= n; i++)
{
f = f * i;
}
}
10

}
Page
Output:

--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

ii) Money Conversion


Design:

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

public partialclass_2aii :System.Web.UI.Page


{
protected voidPage_Load(object sender, EventArgs e)
{

protected void Button1_Click(object sender, EventArgs e)


{
double a = Double.Parse(TextBox5.Text);
Convobj = newConv(a);
TextBox1.Text = Convert.ToString(obj.d);
obj.dtr();
TextBox2.Text = Convert.ToString(obj.r);
obj.rtd();
TextBox3.Text = Convert.ToString(obj.e);
obj.etr();
11

TextBox4.Text = Convert.ToString(obj.r);
obj.rte();
}
Page

}
Conv.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

publicclassConv
{
publicdouble d, r, e, a;
publicConv(double amount)
{
a = amount;
}
publicvoidrtd()
{
d = a / 69;
}
publicvoiddtr()
{
r = a * 69;
}
publicvoidrte()
{
e = a / 82.36;
}
publicvoidetr()
{
r = a * 82.36;
}

}
Output:

-------------------------------------------------------------------------------------------------------------------------------------------------------------
iii) Quadratic Equation.
Design:
12
Page
2iv.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partialclass_2aiv :System.Web.UI.Page


{
protected voidPage_Load(object sender, EventArgs e)
{

protected void Button1_Click(object sender, EventArgs e)


{
int a, b, c;
a = Int32.Parse(TextBox1.Text);
b = Int32.Parse(TextBox2.Text);
c = Int32.Parse(TextBox3.Text);
quadeqtnqe = newquadeqtn(a, b, c);
Response.Write(qe.msg);

}
}
quadeqtn.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

publicclassquadeqtn
{
publicdouble d, x1, x2;
publicstringmsg;
publicquadeqtn(int a, int b, int c)
{
d = b * b - 4 * a * c;
if (d == 0)
{
x1 = -b / (2.0 * a);
x2 = x1;
msg = "Both the roots are real and different <br> 1st Root is : " + x1 + "<br> 2nd Root is : " + x2 +
"<br>";
}
elseif (d > 0)
{
x1 = (-b + Math.Sqrt(d)) / (2 * a);
x2 = (-b - Math.Sqrt(d)) / (2 * a);
msg = "Both the roots are real and different <br> 1st Root is :" + x1 + "<br> 2nd Root is : " + x2 +
"<br>";
}
else
{
msg = "Root are imaginary, No solution.";

}
}
}
13
Page
Output:

--------------------------------------------------------------------------------------------------------------------------------------

iv) Temperature Conversion


Design:

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

public partialclass_2aiii :System.Web.UI.Page


{
protected voidPage_Load(object sender, EventArgs e)
{

protected void Button1_Click(object sender, EventArgs e)


{
double c = Double.Parse(TextBox1.Text);
14

Convobj = newConv(c);
obj.ctf();
Page

TextBox2.Text = obj.f.ToString();
}
protected void Button2_Click(object sender, EventArgs e)
{
double c = Double.Parse(TextBox3.Text);
Convobj = newConv(c);
obj.ftc();
TextBox4.Text = obj.c.ToString();

}
}
Conv.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

publicclassConv
{
publicdouble temp, f, c;
publicConv(double t)
{
temp = t;
}
publicvoidctf()
{
f = ((temp * 9 / 5)) + 32;
}
publicvoidftc()
{
c = ((temp - 32) * 5) / 9;
}

Output:

------------------------------------------------------------------------------------------------------------------------------------------------------------
15
Page
Practical 2b : Create simple application to demonstrate use of following concepts
i) Function Overloading
Design:

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

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


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

protected void Button1_Click(object sender, EventArgs e)


{
funcol fo = new funcol();
fo.sum(10, 20);
fo.sum(10, 20, 30);
fo.sum(14.2f, 1.8f);
fo.sum(12.0f, 23.1f, 23.43f);
TextBox1.Text = Convert.ToString(fo.x);
TextBox2.Text = Convert.ToString(fo.y);
TextBox3.Text = Convert.ToString(fo.u);
TextBox4.Text = Convert.ToString(fo.v);
}
}

Funcol.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

public class funcol


{
public int x, y;
public float u, v;
public funcol()
{
16

x = y = 0;
u = v = 0.0F;
Page

}
public void sum (int a, int b)
{
x = a + b;
}
public void sum (int a, int b, int c)
{
y = a + b + c;
}
public void sum (float a, float b)
{
u = a + b;
}
public void sum (float a,float b,float c)
{
v = a + b + c;
}
}
Output:

--------------------------------------------------------------------------------------------------------------------------------------

2b ii) Inheritance (all types)


a) Single Level Inheritance
Design:

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

public partialclassPractical2B1 :System.Web.UI.Page


{
Page

protected voidPage_Load(object sender, EventArgs e)


{

protected void Button1_Click(object sender, EventArgs e)


{
basec b = newbasec();
Label1.Text = "Calling base class method from base class object !" + b.parentmethod();
derived d = newderived();
Label2.Text = "Calling base class method from derived class object !" + d.parentmethod();
Label3.Text = "Calling derived class method from derived class object !" + d.childmethod();
}
}
basec.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
publicclassbasec
{
publicbasec()
{

}
publicstringparentmethod()
{
string p = "This is base class method";
return p;
}
}
publicclassderived:basec
{
publicstringchildmethod()
{
string c = "This is derived class method";
return c;
}
}
Output:

-------------------------------------------------------------------------------------------------------------------------------------------------------------
b) MultiLevel Inheritance
18
Page

Design:
Practical2B2.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partialclassPractical2B2 :System.Web.UI.Page


{
protected voidPage_Load(object sender, EventArgs e)
{

protected void Button1_Click(object sender, EventArgs e)


{
Cobj = newC();
Label1.Text = obj.show();
Label2.Text = obj.display();
Label3.Text = obj.output();
}
}
mli.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
publicclassA
{
publicA()
{

}
publicstringshow()
{
return ("First Base Class");
}
}
publicclassB :A
{
publicstringdisplay()
{
return ("Second base class and first derived class");
}
}
publicclassC :B
{
publicstringoutput()
{
return ("Second derived class");
}
}

Output:
19
Page
c) Multiple Inheritance
Design:

inheritance3.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partialclassinheritance3 :System.Web.UI.Page
{

protected voidPage_Load(objectsender,EventArgs e)
{

}
protected void Button1_Click(object sender, EventArgs e)
{
rect r = newrect();
r.sides(Convert.ToInt16(TextBox1.Text), Convert.ToInt16(TextBox2.Text));
intaor = r.area();
TextBox3.Text = Convert.ToString(aor);
}
}
Mp.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
publicclasslengthofrect
{
publicintlen, brth;
publicvoidsides(int l, int b)
{
len = l;
brth = b;
}
}
publicinterfacecalc
{
intarea();
}
publicclassrect :lengthofrect , calc
{
publicintarea()
20

{
returnlen * brth;
Page

}
}
Output:

---------------------------------------------------------------------------------------------------------------------------------------------------------
d) Heirarchical Inheritance
Design:

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

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


{
protected voidPage_Load(object sender, EventArgs e)
{

protected void Button1_Click(object sender, EventArgs e)


{
Qq = newQ();
Label1.Text = " Calling " + q.showP() + " from " + q.showQ();
Rr = newR();
Label2.Text = " Calling " + r.showR() + " from " + r.showR();
}
}

Hci.cs
using System;
using System.Collections.Generic;
using System.Linq;
21

using System.Web;
publicclassP
{
Page

publicstringshowP()
{
string a = "Parent Class";
return a;
}
}
publicclassQ:P
{
publicstringshowQ()
{
string b = "Child1 Class";
return b;
}
}
publicclassR:P
{
publicstringshowR()
{
string c = "Child2 Class";
return c;
}
}
Output:

--------------------------------------------------------------------------------------------------------------------------------------

iii)Constructor Overloading
Design: 22
Page
Constructor Overloading.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partialclassConstructor_Overloading :System.Web.UI.Page


{
protected voidPage_Load(object sender, EventArgs e)
{

protected void Button1_Click(object sender, EventArgs e)


{
Marksheet a = newMarksheet();
Marksheet b = newMarksheet(100);
Marksheet c = newMarksheet(40, 120);
Marksheet d = newMarksheet(30, 80, 50);
Label1.Text = "Marksheet1 = " + a.tot();
Label2.Text = "Marksheet2 = " + a.tot();
Label3.Text = "Marksheet3 = " + a.tot();
Label4.Text = "Marksheet4 = " + a.tot();
}
}
Marksheet.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

public class Marksheet


{
Private float m1, m2, m3;
public Marksheet()
{
m1 = 20;
m2 = 30;
m3 = 40;
}
publicMarksheet(floatms)
{
m1 = ms;
}
Public Marksheet(float ms1, float ms2)
{
m1 = ms1;
m2 = ms2;
}
Public Marksheet(float ms1, float ms2, float ms3)
{
m1 = ms1;
m2 = ms2;
m1 = ms1;
m3 = ms3;
}
Public float tot()
{
23

float t = m1 + m2 + m3;
return t;
Page

}
}
Output:

--------------------------------------------------------------------------------------------------------------------------------------

iv)Interfaces
Design:

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

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


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

protected void Button1_Click(object sender, EventArgs e)


{
Circle c = new Circle();
c.input(float.Parse(TextBox1.Text));
Label2.Text = "Area of Circle is : " + c.ans();
}
24

}
Intrfc.cs
Page

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
public interface calculation
{
float ans();
float input(float r);
}
public class Circle : calculation
{
public float rad, a;
public Circle()
{
rad = 0.0f;
}
public float input(float r)
{
rad = r;
return rad;
}
public float ans()
{
a = rad * rad * 3.14f;
return a;
}
}
Output:

--------------------------------------------------------------------------------------------------------------------------------------

Practical 2c: Create simple application to demonstrate use of following concepts


a) Using Delegates and events

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

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


{
public delegate void SimpleDelegate();
public void firstFunction()
25

{
Label1.Text="1st function called through Simple Delegate()method <br>";
Page

}
public void secondFunction()
{
Label2.Text="2nd function called through Simple Delegate()method <br>";
}
protected void Page_Load(object sender, EventArgs e)
{

}
protected void Button1_Click(object sender, EventArgs e)
{
SimpleDelegate sd1 = new SimpleDelegate(firstFunction);
sd1();
SimpleDelegate sd2 = new SimpleDelegate(secondFunction);
sd2();
}
}

Output: ---------------------------------------------------------

--------------------------------------------------------------------------------------------------------------------------------------

b) Exception Handling
2c ii.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
class NegativeException : Exception
{
public NegativeException(string msg)
:base(msg)
{ }
}
public partial class _2cii : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

protected void Button1_Click(object sender, EventArgs e)


{
int num;
try
{
num = int.Parse(TextBox1.Text);
26

if (num < 0)
{
Page

throw new NegativeException("Negative Number");


}
else
{
Label2.Text = ("Positive Number");
}
}
catch (NegativeException en)
{
Label2.Text = (en.Message);
}
}
}
Output:

---------------------------------------------------------------------------------
---------------------------------------------------------------------------------

27
Page
Practical 3 : Working with web controls
Practical 3a : Create a webpage with Various Server Controls to demonstrate Setting an use of their
Properties (eg:AutoPostBack)

Prac 3A.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

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


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

protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)


{
Label5.Text = "You have been enrolled" + DropDownList1.SelectedItem;
}

protected void Button1_Click(object sender, EventArgs e)


{
string s;
if (RadioButton1.Checked == true)
{
s = RadioButton1.Text;
}
else if (RadioButton2.Checked == true)
{
s = RadioButton2.Text;
}
else
{
s = RadioButton3.Text;
}
Label5.Text = "You have been enrolled in " + s + " " + DropDownList1.SelectedItem;
}
}
Output:
28
Page
Practical 3b: Demonstrate the use of Calendar Control
a) Display messages in a calendar control

3b(i).aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class _3b_i_ : 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(2022, 9, 7))
{
e.Cell.Controls.Add(new LiteralControl("<br/>AWP"));
}
if (e.Day.Date == new DateTime(2022, 9, 26))
{
e.Cell.Controls.Add(new LiteralControl("<br/>First Day of Navratri"));
}
}
protected void Calendar1_SelectionChanged(object sender, EventArgs e)
{
}
}

Output:

-------------------------------------------------------------------------------------------------------------------------------------------------------------
b) Display vacation in a calendar control

3b(ii).aspx.cs
using System;
29

using System.Collections.Generic;
using System.Linq;
Page

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

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


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

protected void Calendar1_SelectionChanged(object sender, EventArgs e)


{

protected void Calendar1_DayRender1(object sender, DayRenderEventArgs e)


{
if ((e.Day.Date >= new DateTime(2022, 9, 13)) && (e.Day.Date <= new DateTime(2022, 9, 18)))
{
e.Cell.BackColor = System.Drawing.Color.LightBlue;
}
}
}
Output:

c) Selected day in a Calendar control using style

3b c).aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

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


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

}
30

protected void Calendar1_DayRender(object sender, DayRenderEventArgs e)


{
Page

}}
Output:

------------------------------------------------------------------------------------------------------------------------------------

d) Difference between two calendar dates

3b d.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

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


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

protected void Button1_Click(object sender, EventArgs e)


{
TimeSpan t = Calendar2.SelectedDate - Calendar1.SelectedDate;
TextBox1.Text = t.Days.ToString();
}
}
Output:
31
Page
Practical 3c
i)TreeView Control and Datalist

3c a).aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class _3c_a_ : 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;
}
}
Output:

--------------------------------------------------------------------------------------------------------------------------------------

Practical 3c b):TreeView Operations


Design:
32
Page
3c b.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

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


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

protected void TreeView1_SelectedNodeChanged(object sender, EventArgs e)


{
Response.Write("You hav selected the option: " + TreeView1.SelectedValue);
}
protected void TreeView1_TreeNodeCollapsed(object sender, TreeNodeEventArgs e)
{
Response.Write("The value Collapsed was :" + e.Node.Value);
}
}
Output:

--------------------------------------------------------------------------
--------------------------------------------------------------------------
33
Page
Practical 4: Working with Form Controls
Practical 4a: Create a Registration Form to Demonstrate use of various Validation controls.

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

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


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

protected void Button1_Click(object sender, EventArgs e)


{
Response.Write("Successfully submitted");
TextBox1.Text = "";
TextBox2.Text = "";
TextBox3.Text = "";
TextBox4.Text = "";
TextBox5.Text = "";
}
}
Output:

--------------------------------------------------------------------------------------------------------------------------------------
34
Page
Practical 4c: Create Web Form to demonstrate use of User Controls
Design:

WebUserControl.ascx (Design Code)


<%@ Control Language="C#" AutoEventWireup="true" CodeFile="WebUserControl.ascx.cs"
Inherits="WebUserControl" %>
Name:Moyudin Papu Roll No:337
<h1>This is User Control</h1>
<p>Name
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
</p>
<p>City
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
</p>
<p>
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" />
</p>
<p>
<asp:Label ID="Label1" runat="server"></asp:Label>

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

<!DOCTYPE html>
<%@ Register Src="~/WebUserControl.ascx" TagPrefix="uc" TagName="c" %>

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

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

WebUserControl.ascx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
35

public partial class WebUserControl : System.Web.UI.UserControl


{
Page

protected void Page_Load(object sender, EventArgs e)


{
}

protected void Button1_Click(object sender, EventArgs e)


{
Label1.Text = "Your Name is " + TextBox1.Text + "and you are from " + TextBox2.Text;
}
}
Output:

------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------

36
Page
Practical 6 : Working with Database
Practical 6a : Create a web application bind data in a multiline textbox by querying in another textbox.
Design:

6a.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;

public partialclass_6a :System.Web.UI.Page


{
protectedString str;
SqlConnection con = newSqlConnection("Data Source=LAPTOP-I0HKVNS0;Initial
Catalog=mynewdatabase;Integrated Security=True");
protected voidPage_Load(object sender, EventArgs e)
{

protected void Button1_Click(object sender, EventArgs e)


{
SqlCommandcmd = newSqlCommand("select * from Table_1 ", con);
con.Open();
SqlDataReaderdr = cmd.ExecuteReader();
while (dr.Read())
{
str += dr["id"] + "" + dr["name"] + "" + dr["address"] + "\n";
}
this.DataBind();
}
}
Output:
37
Page
Practical 6b): Create a web application to display records by using database.

6b.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;

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


{
SqlConnection cn = new SqlConnection("Data Source=LAPTOP-I0HKVNS0;Initial
Catalog=mynewdatabase;Integrated Security=True");
protected void Page_Load(object sender, EventArgs e)
{
SqlCommand cmd = new SqlCommand("select * from Table_3 ", cn);
cn.Open();
SqlDataReader dr = cmd.ExecuteReader();
while(dr.Read())
{
Label2.Text += dr["empid"]+""+dr["firstname"]+""+dr["lastname"]+""+dr["age"]+"<br>";
}
}
}
Output:

------------------------------------------------------------------------------------------------------------------------------------------------------------

Practical 6c : Demonstrate the use of Datalist link control


Design:
38
Page
6c.aspx
<%@PageLanguage="C#"AutoEventWireup="true"CodeFile="6c.aspx.cs"Inherits="_6c"%>

<!DOCTYPEhtml>
<scriptrunat="server">

protected void SqlDataSource1_Selecting(object sender, SqlDataSourceSelectingEventArgs e)


{

}
</script>

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

<asp:DataListID="DataList1"runat="server"DataSourceID="SqlDataSource1">
<ItemTemplate>
id:
<asp:LabelID="idLabel"runat="server"Text='<%# Eval("id") %>'></asp:Label>
<br/>
name:
<asp:LabelID="nameLabel"runat="server"Text='<%# Eval("name") %>'></asp:Label>
<br/>
address:
<asp:LabelID="addressLabel"runat="server"Text='<%# Eval("address") %>'></asp:Label>
<br/>
<br/>
</ItemTemplate>
</asp:DataList>
<br/>
<br/>
<br/>
<asp:SqlDataSourceID="SqlDataSource1"runat="server"ConnectionString="<%$
ConnectionStrings:mynewdatabaseConnectionString%>"SelectCommand="SELECT *FROM
Table_1"OnSelecting="SqlDataSource1_Selecting"></asp:SqlDataSource>
</div>
</form>
</body>
</html>
Output: 39
Page
Practical 7 : Working with Database
Practical 7a: Create a web application to display Databinding using dropdownlist control

7a.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;

public partialclass_7a :System.Web.UI.Page


{
String str;
SqlConnection con = newSqlConnection("Data Source=LAPTOP-I0HKVNS0;Initial
Catalog=mynewdatabase;Integrated Security=True");
protected voidPage_Load(object sender, EventArgs e)
{

protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)


{
Label1.Text = Convert.ToString(DropDownList1.SelectedItem);
}

protected void Button1_Click(object sender, EventArgs e)


{
SqlCommandcmd = newSqlCommand("select * from Table_1", con);
con.Open();
SqlDataReaderdr = cmd.ExecuteReader();
DropDownList1.DataSource = dr;
DropDownList1.DataTextField = "name";
DropDownList1.DataBind();
}
}
Output:

40

------------------------------------------------------------------------------------------------------------------------------------
Page
Practical 7b: Create a web application for to display the phone no of an author using database

7b.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;

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


{
SqlConnection cn = new SqlConnection("Data Source=LAPTOP-I0HKVNS0;Initial
Catalog=mynewdatabase;Integrated Security=True");
protected void Page_Load(object sender, EventArgs e)
{

}
protected void Button1_Click(object sender, EventArgs e)
{
SqlCommand cmd = new SqlCommand("select * from author_details where id = " + TextBox1.Text +
" ", cn);
cn.Open();
SqlDataReader dr = cmd.ExecuteReader();
while(dr.Read())
{
TextBox2.Text = Convert.ToString(dr["phone no"]);
}
}
}
Output:

----------------------------------------------------------------------------------------------------------------------------------------------------------
Practical 7c: Create a web application for inserting and deleting record from database (Using Execute-
Non Query)
Design:
41
Page
7c.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;

public partial class_7c :System.Web.UI.Page


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

protected void Button1_Click(object sender, EventArgs e)


{
try
{
SqlConnection con = newSqlConnection("Data Source=LAPTOP-I0HKVNS0;Initial
Catalog=mynewdatabase;Integrated Security=True");
SqlCommandcmd = newSqlCommand("insert into student_table values('" + TextBox1.Text+ "','" +
TextBox2.Text+ "','" + TextBox3.Text+ "')", con);
con.Open();
cmd.ExecuteNonQuery();
}
catch (SqlException ex)
{
Response.Write(ex.Message);
}
Label4.Text = "data inserted successfully";
}

protected void Button2_Click(object sender, EventArgs e)


{
try
{
SqlConnection con = newSqlConnection("Data Source=LAPTOP-I0HKVNS0;Initial
Catalog=mynewdatabase;Integrated Security=True");
SqlCommandcmd = newSqlCommand("delete from student_table where id = " + TextBox1.Text + "", con);
con.Open();
cmd.ExecuteNonQuery();
}
catch(SqlException ex)
{
Response.Write(ex.Message);
}
Label4.Text = "Data Deleteted Successfully";
}
}
42
Page
Output: Database after inserting data

Database after deleting data

--------------------------------------------------------------------------
-------------------------------------------------------------------------- 43
Page
Practical 8 : Working with Data Controls
Practical 8a : Create a Web Application to Demonstrate Various uses and properties of SqlDataSource

8a.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;

public partialclass_8a :System.Web.UI.Page


{
protected voidPage_Load(object sender, EventArgs e)
{

protected void Button1_Click(object sender, EventArgs e)


{
try
{
SqlConnection con = newSqlConnection("Data Source=LAPTOP-I0HKVNS0;Initial
Catalog=mynewdatabase;Integrated Security=True");
SqlCommandcmd = newSqlCommand("insert into Table_1 values('" + TextBox1.Text + "','" + TextBox2.Text
+ "','" + TextBox3.Text + "')", con);
con.Open();
cmd.ExecuteNonQuery();
}
catch (SqlException ex)
{
Response.Write(ex.Message);
}
Label4.Text = "data inserted successfully";
}

protected void Button2_Click(object sender, EventArgs e)


{
SqlConnection con = newSqlConnection("Data Source=LAPTOP-I0HKVNS0;Initial
Catalog=mynewdatabase;Integrated Security=True");
SqlCommandcmd = newSqlCommand("delete from Table_1 where id = " + TextBox1.Text + "", con);
con.Open();
cmd.ExecuteNonQuery();
Label4.Text = "data deleted successfully";
}
}
44
Page
Output: Database after inserting data

Database after deleting data

-------------------------------------------------------------------------------------------------------------------------------------

Practical 8b : Create a web application to demonstrate data binding using DetailsView and FormView
Control.

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

<!DOCTYPE html>

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

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


ConnectionStrings:mynewdatabaseConnectionString2 %>" SelectCommand="SELECT * FROM
Page

[Table_8b]"></asp:SqlDataSource>
<br />
<br />
<br />
<asp:DetailsView ID="DetailsView1" runat="server" AllowPaging="True" AutoGenerateRows="False"
DataSourceID="SqlDataSource1" Height="50px" Width="125px">
<Fields>
<asp:BoundField DataField="id" HeaderText="id" SortExpression="id" />
<asp:BoundField DataField="name" HeaderText="name" SortExpression="name" />
<asp:BoundField DataField="address" HeaderText="address" SortExpression="address" />
</Fields>
</asp:DetailsView>
<br />
<br />
<asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$
ConnectionStrings:mynewdatabaseConnectionString3 %>" SelectCommand="SELECT * FROM
[Table_8b]"></asp:SqlDataSource>
<br />
<br />
<asp:FormView ID="FormView1" runat="server" AllowPaging="True" DataSourceID="SqlDataSource2">
<EditItemTemplate>
id:
<asp:TextBox ID="idTextBox" runat="server" Text='<%# Bind("id") %>' />
<br />
name:
<asp:TextBox ID="nameTextBox" runat="server" Text='<%# Bind("name") %>' />
<br />
address:
<asp:TextBox ID="addressTextBox" runat="server" Text='<%# Bind("address") %>' />
<br />
<asp:LinkButton ID="UpdateButton" runat="server" CausesValidation="True"
CommandName="Update" Text="Update" />
<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 />
address:
<asp:TextBox ID="addressTextBox" runat="server" Text='<%# Bind("address") %>' />
<br />
<asp:LinkButton ID="InsertButton" runat="server" CausesValidation="True"
CommandName="Insert" Text="Insert" />
<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 />
address:
<asp:Label ID="addressLabel" runat="server" Text='<%# Bind("address") %>' />
<br />

</ItemTemplate>
</asp:FormView>
46

</div>
Page

</form>
</body>
</html>
Output:

---------------------------------------------------------------------------------
---------------------------------------------------------------------------------

47
Page
Prac10_a
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Xml;

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


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

protected void Button1_Click(object sender, EventArgs e)


{
XmlReader red = XmlReader.Create("C:\\destination\\myXmlFile.xml");
while(red.Read())
{
if(red.NodeType.Equals(XmlNodeType.Element))
{
string s = Label1.Text + "";
Label1.Text = s + red.Name;
}
}}

protected void Button2_Click(object sender, EventArgs e)


{
XmlTextWriter textWriter = new XmlTextWriter ("C:\\destination\\myXmlFile.xml", null);
textWriter.WriteStartDocument();
textWriter.WriteStartElement("student");
textWriter.WriteStartElement("name", "");
textWriter.WriteString("Adin Shaikh");
textWriter.WriteEndElement();
textWriter.WriteStartElement("rollno.", "");
textWriter.WriteString("345");
textWriter.WriteEndElement();
textWriter.WriteEndDocument();
textWriter.Close();
}
}

48
Page
Prac_11
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
ClassLibrary1.Class1 c = new ClassLibrary1.Class1();
int sum = c.add(4, 5);
Console.WriteLine("addition is {0}", sum);
Console.ReadKey();
}
}
}

49
Page

You might also like