Nothing Special   »   [go: up one dir, main page]

Rushi Awp

Download as pdf or txt
Download as pdf or txt
You are on page 1of 61

TY-BSC-IT ADVANCE WEB PROGRAMMING 226771

Practical 1(a): Create an application that obtains four int value from the user and displays the
product.

Source Code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

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

private void btnResult_Click(object sender, EventArgs e)


{
int r;

1
TY-BSC-IT ADVANCE WEB PROGRAMMING 226771

r = Convert.ToInt32(textBox1.Text) * Convert.ToInt32(textBox2.Text) *
Convert.ToInt32(textBox3.Text) * Convert.ToInt32(textBox4.Text);
label5.Text = "Result " + r.ToString();
}
private void btnReset_Click(object sender, EventArgs e)
{
textBox1.Text = "";
textBox2.Text = "";
textBox3.Text = "";
textBox4.Text = "";
label5.Text = "";

}
}
}

Output :

2
TY-BSC-IT ADVANCE WEB PROGRAMMING 226771

Practical 1(b): Create an application to demonstrate the string applications.

Source Code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

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

private void btnResult_Click(object sender, EventArgs e)


{
string s = textBox1.Text;
label1.Text = "String length : " + s.Length;
label2.Text = "Substring : " + s.Substring(4,3);
label3.Text = "Upper String : " + s.ToUpper();
label4.Text = "Lower String : " + s.ToLower();

3
TY-BSC-IT ADVANCE WEB PROGRAMMING 226771

string rev = "";


for (int i = s.Length - 1; i >= 0; i--)
{
rev = rev + s[i];

}
label5.Text = "Reverse String : " + rev.ToString();
label6.Text = "Replace 's' by 't' i String : " + s.Replace('s','t');
label7.Text = "Insert 'u' in String : " + s.Insert(3, "u");
label8.Text = "String Truncate : " + s.Trim();
label9.Text = "Remove string : " + s.Remove(4);
label10.Text = "Index of String : " + s.IndexOf('e');
}

private void btnReset_Click(object sender, EventArgs e)


{
label1.Text = "";
label2.Text = "";
label3.Text = "";
label4.Text = "";
label5.Text = "";
label6.Text = "";
label7.Text = "";
label8.Text = "";
label9.Text = "";
label10.Text = "";
textBox1.Text = "";

}
}
}

4
TY-BSC-IT ADVANCE WEB PROGRAMMING 226771

Output :

5
TY-BSC-IT ADVANCE WEB PROGRAMMING 226771

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


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

i) Generate Fibonacci series.

Source Code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Pract3
{
public partial class Form1 : Form
{

6
TY-BSC-IT ADVANCE WEB PROGRAMMING 226771

public Form1()
{
InitializeComponent();
}

private void Form1_Load(object sender, EventArgs e)


{
label12.Text = "";
string[] ColorNames = new string[] { "Red", "Yellow", "Black", "Green", "Blue", "Pink"
};
foreach (string ColorName in ColorNames)
{
label12.Text = label12.Text + " " + ColorNames.ToString();
}
}

private void btnFibo_Click(object sender, EventArgs e)


{
int a, b, c, i, n;
a = 0;
b = 1;
label6.Text = a.ToString() + b.ToString();
n = Convert.ToInt32(textBox1.Text);
for (i = 1; i <= n; i++)
{
c = a + b;
label6.Text = label6.Text + c.ToString();
a = b;
b = c;
}
}

private void btnPrime_Click(object sender, EventArgs e)


{
int i, c=0, j, num;
num = Convert.ToInt32(textBox2.Text);
for (j = 1; j <= num; j++) {
i = num % j;
if (i == 0)
{
c = c + 1;
}
}
if (c == 2)
label7.Text = "The given number is prime";
else

7
TY-BSC-IT ADVANCE WEB PROGRAMMING 226771

label7.Text = "The given number is not prime ";


}

private void btnRev_Click(object sender, EventArgs e)


{
long num, i, sum = 0;
num = Convert.ToInt32(textBox3.Text);
while (num > 0) {
i = num % 10;
sum = i + sum * 10;
num = num / 10;
}
label8.Text = sum.ToString();

private void btnSum_Click(object sender, EventArgs e)


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

}
}

private void button1_Click(object sender, EventArgs e)


{
char c = Convert.ToChar(textBox5.Text);
switch (c) {
case 'a':
label10.Text = "a is vowel";
break;
case 'e':
label10.Text = "e is vowel";
break;
case 'i':
label10.Text = "i is vowel";
break;
case 'o':
label10.Text = "o is vowel";
break;

8
TY-BSC-IT ADVANCE WEB PROGRAMMING 226771

case 'u':
label10.Text = "u is vowel";
break;
default:
label10.Text = "It is not vowel";
break;
}
}
}
}

Output :

9
TY-BSC-IT ADVANCE WEB PROGRAMMING 226771

Practical 1d: Create an application that receives the (Student Id, Student Name, Course Name,
Date of Birth) information from a set of students.

Source Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace calander1
{
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
Label6.Text = "Student ID : " + TextBox1.Text;
Label7.Text = "Student Name : " + TextBox2.Text;
Label8.Text = "Course Name : " + TextBox3.Text;
Label9.Text = "Date of Birth : " + Calendar1.SelectedDate.ToShortDateString();
}
protected void Button2_Click(object sender, EventArgs e)
{
Label1.Text = "";
Label2.Text = "";

10
TY-BSC-IT ADVANCE WEB PROGRAMMING 226771

Label3.Text = "";
Label4.Text = "";
TextBox1.Text = "";
TextBox2.Text = "";
TextBox3.Text = "";
Calendar1.SelectedDates.Clear();
}
}
}

Output:-

11
TY-BSC-IT ADVANCE WEB PROGRAMMING 226771

Practical 2

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

12
TY-BSC-IT ADVANCE WEB PROGRAMMING 226771

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

(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 conCurv

13
TY-BSC-IT ADVANCE WEB PROGRAMMING 226771

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

protected void BtnDol_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 BtnEur_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 BtnPound_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 BtnYen_Click(object sender, EventArgs e)


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

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

14
TY-BSC-IT ADVANCE WEB PROGRAMMING 226771

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 * 0.015;
return r;

}
}
}

15
TY-BSC-IT ADVANCE WEB PROGRAMMING 226771

Output:

16
TY-BSC-IT ADVANCE WEB PROGRAMMING 226771

iii) Quadratic Equation


The Standard form of a Quadratic Equation looks like this:

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

namespace Practical2aiii
{
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);
Label1.Text = "There are two roots::";
Label2.Text = r1.ToString();
Label3.Text = r2.ToString();
}
else if (det == 0)

17
TY-BSC-IT ADVANCE WEB PROGRAMMING 226771

{
x = Math.Sqrt(det);
r1 = (-b + x) / (2 * a);
Label1.Text = "There are only one root::";
Label2.Text = r1.ToString();
}
else
{
Label1.Text = "There is no root!!";
}
}
protected void Page_Load(object sender, EventArgs e)
{

protected void TextBox1_TextChanged(object sender, EventArgs e)


{

protected void Button1_Click(object sender, EventArgs e)


{
demo();
}
}
}

18
TY-BSC-IT ADVANCE WEB PROGRAMMING 226771

(iv): Temperature Conversion

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

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

protected void TextBox2_TextChanged(object sender, EventArgs e)


{

protected void Btn1_Click(object sender, EventArgs e)


{
tempConv s = new tempConv();
double n = Convert.ToDouble(TextBox1.Text);
double x = s.ctof(n);
lbl4.Text = x.ToString();
}

protected void Btn2_Click(object sender, EventArgs e)

19
TY-BSC-IT ADVANCE WEB PROGRAMMING 226771

{
tempConv s = new tempConv();
double n = Convert.ToDouble(TextBox1.Text);
double x = s.ctof(n);
Lbl5.Text = x.ToString();
}
}
}
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;
}
}

Output:

Practical 2b
(i) Function Overloading

20
TY-BSC-IT ADVANCE WEB PROGRAMMING 226771

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

namespace FunctionOverloading
{
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);
Label2.Text = x.ToString();
Label3.Text = y.ToString();
Label4.Text = z.ToString();

21
TY-BSC-IT ADVANCE WEB PROGRAMMING 226771

}
}

Output:

(b) Inheritance
(i) Single Inheritance

22
TY-BSC-IT ADVANCE WEB PROGRAMMING 226771

Source Code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

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

private void btnresult_Click(object sender, EventArgs e)

23
TY-BSC-IT ADVANCE WEB PROGRAMMING 226771

{
B s = new B();
int n = Convert.ToInt32(textBox1.Text);
int x = s.sqr(n);
int y = s.cube(n);
label4.Text = x.ToString();
label5.Text = y.ToString();

}
}
public class A
{
public int sqr(int Val1)
{
return Val1 * Val1;

}
}
public class B : A
{
public int cube(int Val1)
{
int v1 = sqr(Val1);

return v1 * Val1;
}

}
}

OUTPUT:

24
TY-BSC-IT ADVANCE WEB PROGRAMMING 226771

(ii) Multilevel Inheritance:

25
TY-BSC-IT ADVANCE WEB PROGRAMMING 226771

Soruce Code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

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

26
TY-BSC-IT ADVANCE WEB PROGRAMMING 226771

private void btn_Multi_Click(object sender, EventArgs e)


{
C s = new C();
int n = Convert.ToInt32(textBox1.Text);
int x = s.pow2(n);
int y = s.pow3(n);
int z = s.pow4(n);

label5.Text = x.ToString();
label6.Text = y.ToString();
label7.Text = z.ToString();

}
public class A
{
public int pow2(int Val1){
return Val1* Val1;

}
}
public class B : A
{
public int pow3(int Val1){
int v1 = pow2(Val1);

return v1* Val1;


}
}
public class C : B {
public int pow4(int Val1) {
int v1 = pow3(Val1);
return v1 * Val1;
}
}
}
}

OUTPUT:

27
TY-BSC-IT ADVANCE WEB PROGRAMMING 226771

28
TY-BSC-IT ADVANCE WEB PROGRAMMING 226771

(iii) Hierarchical Inheritance :

Source Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace hexainheritance
{
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);
Label5.Text = x.ToString();
Label6.Text = y.ToString();

29
TY-BSC-IT ADVANCE WEB PROGRAMMING 226771

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

30
TY-BSC-IT ADVANCE WEB PROGRAMMING 226771

Output:

31
TY-BSC-IT ADVANCE WEB PROGRAMMING 226771

(c): Constructure overloading:

Source Code:
using System;
using System.Collections.Generic;
using System.Linq;
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)
{
add obj1 = new add(2);
add obj2 = new add(2,3);
add obj3 = new add(2,3,4);
Label2.Text = obj1.r.ToString();
Label3.Text = obj2.r.ToString();
Label4.Text = obj2.r.ToString();

}
}
public class add
{
public int r;
public add(int a)
{
r = a + a;

32
TY-BSC-IT ADVANCE WEB PROGRAMMING 226771

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

Output:

(d) Interfaces:

33
TY-BSC-IT ADVANCE WEB PROGRAMMING 226771

Source Code:

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 WebForm1 : 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();

}
}
interface Area
{
double show(double s, double t);
}

34
TY-BSC-IT ADVANCE WEB PROGRAMMING 226771

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

Output:

Practical 2(c):

35
TY-BSC-IT ADVANCE WEB PROGRAMMING 226771

(i)using delegates and event:

Source Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace _2cpractical
{
public partial class WebForm1 : System.Web.UI.Page
{
public delegate string dele();
public static string display1()
{
string s1 = "Yashshree Sambare";
return s1;
}
public static string display2()
{
string s2 = "Vedshree Sambare";
return s2;
}
protected void Page_Load(object sender, EventArgs e)
{
dele d1 = new dele(display1);
d1();
dele d2 = new dele(display2);

36
TY-BSC-IT ADVANCE WEB PROGRAMMING 226771

d2();
Label1.Text = d1();
Label2.Text = d2();

}
}
}

Output:

(ii)Exception handling:

37
TY-BSC-IT ADVANCE WEB PROGRAMMING 226771

Source Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace practical2cii
{
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);
Label3.Text = "The result is : " + resultVal.ToString();
}
catch(System.DivideByZeroException ex)
{
Label3.Text = ex.ToString();
}
catch(System.IndexOutOfRangeException ex)

38
TY-BSC-IT ADVANCE WEB PROGRAMMING 226771

{
Label3.Text = ex.ToString();
}
}
}
}

Output:

Practical 3(a)

39
TY-BSC-IT ADVANCE WEB PROGRAMMING 226771

Practical 3(a): Create a simple web Page with various server controls to demonstrate setting and
use of their properties.
WebForm1.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace practi3a
{
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
string str = "vinit choughule";
if (ViewState["name"]==null)
{
ViewState["name"] = str;
}
}
}

protected void Button1_Click(object sender, EventArgs e)


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

protected void Button2_Click(object sender, EventArgs e)


{
TextBox1.Text = "";
for(int i=0;i<ListBox1.Items.Count;i++)
{
if (ListBox1.Items[i].Selected==true)
{
TextBox1.Text = TextBox1.Text + "" + ListBox1.Items[i].Text + "\n";
}
}
}

protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)


{

40
TY-BSC-IT ADVANCE WEB PROGRAMMING 226771

Label2.Text = DropDownList1.SelectedItem.Text;
}

protected void DropDownList2_SelectedIndexChanged(object sender, EventArgs e)


{
Label2.Font.Size = int.Parse(DropDownList2.SelectedItem.Text);
}

protected void RadioButton1_CheckedChanged(object sender, EventArgs e)


{
Label2.BackColor = System.Drawing.Color.Red;
}

protected void RadioButton2_CheckedChanged(object sender, EventArgs e)


{
Label2.BackColor=System.Drawing.Color.Green;
}

protected void RadioButton3_CheckedChanged(object sender, EventArgs e)


{
Label2.BackColor = System.Drawing.Color.Blue;
}

protected void CheckBox1_CheckedChanged(object sender, EventArgs e)


{
Label2.Font.Bold = true;
}

protected void CheckBox2_CheckedChanged(object sender, EventArgs e)


{
Label2.Font.Italic = true;
}

protected void CheckBox3_CheckedChanged(object sender, EventArgs e)


{
Label2.Font.Underline = true;
}
}
}

OUTPUT:

41
TY-BSC-IT ADVANCE WEB PROGRAMMING 226771

42
TY-BSC-IT ADVANCE WEB PROGRAMMING 226771

Practical 3(b): Demonstrate the use of Calendar control to perform followingoperations.


a) Display messages in a calendar control
b) Display vacation in a calendarcontrol
c) Selected day in a calendar control using style
d) Difference between two calendardates

Source Code:
Calender properties set for this example:
<asp:Calendar ID="Calendar1" runat="server" BackColor="#FFFFCC"
BorderColor="#FFCC66" BorderWidth="1px" DayNameFormat="Shortest"
Font-Names="Verdana" Font-Size="8pt" ForeColor="#663399" Height="200px"
NextPrevFormat="ShortMonth" > ShowGridLines="True" Width="300px"
>
<DayHeaderStyle BackColor="#FFCC66" Font-Bold="True" Height="1px" />
<NextPrevStyle BorderStyle="Solid" BorderWidth="2px" Font-Size="9pt"
ForeColor="#FFFFCC" />
<OtherMonthDayStyle BackColor="#FFCC99" BorderStyle="Solid"

ForeColor="#CC9966" />
<SelectedDayStyle BackColor="Red" Font-Bold="True" />
<SelectorStyle BackColor="#FFCC66" />
<TitleStyle BackColor="#990000" Font-Bold="True" Font-Size="9pt"

ForeColor="#FFFFCC" />

43
TY-BSC-IT ADVANCE WEB PROGRAMMING 226771

<TodayDayStyle BackColor="#FFCC66" ForeColor="White" />


<WeekendDayStyle Height="50px" />
</asp:Calendar>

calndrCtrl.aspx.cs
protected void btnResult_Click(object sender, EventArgs e)
{
Calendar1.Caption = "SAMBARE";
Calendar1.FirstDayOfWeek = FirstDayOfWeek.Sunday;
Calendar1.NextPrevFormat = NextPrevFormat.ShortMonth;
Calendar1.TitleFormat = TitleFormat.Month;

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


Label3.Text = "Ganpati Vacation Start: 9-13-2018";
TimeSpan d = new DateTime(2018, 9, 13) - DateTime.Now;
Label4.Text = "Days Remaining For Ganpati Vacation:"+d.Days.ToString();
TimeSpan d1 = new DateTime(2018, 12, 31) - DateTime.Now;
Label5.Text = "Days Remaining for New Year:"+d1.Days.ToString();
if (Calendar1.SelectedDate.ToShortDateString() == "9-13-2018")
Label3.Text = "<b>Ganpati Festival Start</b>";
if (Calendar1.SelectedDate.ToShortDateString() == "9-23-2018")
Label3.Text = "<b>Ganpati Festival End</b>";
}
protected void Calendar1_DayRender(object sender,
System.Web.UI.WebControls.DayRenderEventArgs e)
{
if (e.Day.Date.Day == 5 && e.Day.Date.Month == 9)
{
e.Cell.BackColor = System.Drawing.Color.Yellow;
Label lbl = new Label();
lbl.Text = "<br>Teachers Day!";
e.Cell.Controls.Add(lbl);
Image g1 = new Image();
g1.ImageUrl = "td.jpg";
g1.Height = 20;
g1.Width = 20;
e.Cell.Controls.Add(g1);

}
if (e.Day.Date.Day == 13 && e.Day.Date.Month == 9)
{
Calendar1.SelectedDate = new DateTime(2018, 9, 12);
Calendar1.SelectedDates.SelectRange(Calendar1.SelectedDate,

44
TY-BSC-IT ADVANCE WEB PROGRAMMING 226771

Calendar1.SelectedDate.AddDays(10));
Label lbl1 = new Label();
lbl1.Text = "<br>Ganpati!";
e.Cell.Controls.Add(lbl1);
}
}
protected void btnReset_Click(object sender, EventArgs e)
{
Label1.Text = "";
Label2.Text = "";
Label3.Text = "";
Label4.Text = "";
Label5.Text = "";
Calendar1.SelectedDates.Clear();
}
protected void Calendar1_SelectionChanged(object sender, EventArgs e)
{
Label1.Text = "Your Selected Date:" + Calendar1.SelectedDate.Date.ToString();
}

OUTPUT:

45
TY-BSC-IT ADVANCE WEB PROGRAMMING 226771

46
TY-BSC-IT ADVANCE WEB PROGRAMMING 226771

Practical 3(c) Demonstrate the use of Treeview control perform following operations.
a) Treeview control and datalist
b) Treeview operations

Add XML File


Website -> Add -> XML File and Name it ‘stdetail’.

stdetail.xml
<?xml version="1.0" encoding="utf-8" ?>
<studentdetail>
<student>
<sid>1</sid>
<sname>Tushar</sname>
<sclass>TYIT</sclass>
</student>
<student>
<sid>2</sid>
<sname>Sonali</sname>
<sclass>TYCS</sclass>
</student>
<student>
<sid>3</sid>
<sname>Yashashree</sname>
<sclass>TYIT</sclass>
</student>
<student>
<sid>4</sid>
<sname>Vedshree</sname>
<sclass>TYCS</sclass>
</student>
</studentdetail>
Default2.aspx
<form id="form1" runat="server">
<div>
Treeview control navigation:<asp:TreeView ID = "TreeView1" runat = "server" Width =
"150px" ImageSet="Arrows">
<HoverNodeStyle Font-Underline="True" ForeColor="#5555DD" />
<Nodes>
<asp:TreeNode Text = "ASP.NET Practs" Value = "New Node">
<asp:TreeNode Text = "Calendar Control" Value = "RED"
NavigateUrl="~/calndrCtrl.aspx">
</asp:TreeNode>
<asp:TreeNode Text = "Constructor Overloading" Value = "GREEN"

47
TY-BSC-IT ADVANCE WEB PROGRAMMING 226771

NavigateUrl="~/clsconstrc.aspx"></asp:TreeNode>
<asp:TreeNode NavigateUrl="~/singleInh.aspx" Text="Inheritance"
Value="BLUE"></asp:TreeNode>
<asp:TreeNode NavigateUrl="~/clsProp.aspx" Text="Class Properties" Value="Class
Properties"></asp:TreeNode>

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

48
TY-BSC-IT ADVANCE WEB PROGRAMMING 226771

Default2.aspx.cs
using System.Data;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
BindData();
}
}
protected void BindData()
{
DataSet ds = new DataSet();
ds.ReadXml(Server.MapPath("stdetail.xml"));
if (ds != null && ds.HasChanges())
{
DataList1.DataSource = ds;
DataList1.DataBind();
}
else
{
DataList1.DataBind();
}
}
}

OUTPUT:-

49
TY-BSC-IT ADVANCE WEB PROGRAMMING 226771

Practical -4

Practical 4(a): Create a Registration form a demonstrated use of various Validation controls.
ValidationPract.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs"
Inherits="Practical4a.WebForm1" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script runat="server">

50
TY-BSC-IT ADVANCE WEB PROGRAMMING 226771

void ValidateBtn_OnClick(object sender,EventArgs e)


{
if(Page.IsValid)
{
Label1.Text = "Thank You";
}
else
{
Label1.Text = "the text must be exactly 8 Character Long!";
}
}
void ServerValidation(object source,ServerValidateEventArgs e)
{
if (e.Value.Length == 8)
e.IsValid = true;
else
e.IsValid = false;
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
Enter your Name:<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server"
ErrorMessage="Please Enter Your Name" ControlToValidate="TextBox1"
ForeColor="Red"></asp:RequiredFieldValidator>
<br />
Enter Your Age:<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
<asp:RangeValidator ID="RangeValidator1" runat="server"
ControlToValidate="TextBox2" ErrorMessage="Not Valid Age" ForeColor="Red"
MaximumValue="100" MinimumValue="18" Type="Integer"></asp:RangeValidator>
<br />
Enter Password:<asp:TextBox ID="TextBox3" runat="server"
TextMode="Password"></asp:TextBox>
<br />
ReEnter Password:<asp:TextBox ID="TextBox4" runat="server"
TextMode="Password"></asp:TextBox>
<asp:CompareValidator ID="CompareValidator1" runat="server"
ControlToCompare="TextBox3" ControlToValidate="TextBox4" ErrorMessage="Password
Should Match!" ForeColor="Red" Operator="LessThan"
Type="Integer"></asp:CompareValidator>
<br />
Email ID:<asp:TextBox ID="TextBox5" runat="server"></asp:TextBox>
<asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server"
ControlToValidate="TextBox5" ErrorMessage="Please Enter Valid Email Address"

51
TY-BSC-IT ADVANCE WEB PROGRAMMING 226771

ForeColor="Red" ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-
.]\w+)*"></asp:RegularExpressionValidator>
<br />
Custom Text:<asp:TextBox ID="TextBox6" runat="server"></asp:TextBox>
<asp:CustomValidator ID="CustomValidator1" runat="server"
ClientValidationFunction="SeverValidation" ControlToValidate="TextBox6"
ErrorMessage="CustomValidator" ForeColor="Red"></asp:CustomValidator>
<asp:Label ID="Label1" runat="server" ForeColor="Red"></asp:Label>
<br />
<asp:Button ID="Button1" runat="server" Text="Validate" />
<br />
<asp:ValidationSummary ID="ValidationSummary1" runat="server" />
</div>
</form>
</body>
</html>

Web.config
<?xml version="1.0" encoding="utf-8"?>
<!--
For more information on how to configure your ASP.NET application, please visit
https://go.microsoft.com/fwlink/?LinkId=169433
-->
<configuration>
<appSettings>
<add key="ValidationSettings:UnobtrusiveValidationMode" value="None"/>
</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.CSharpCodeProvider,
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.VBCodeProvider,
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>

52
TY-BSC-IT ADVANCE WEB PROGRAMMING 226771

</system.codedom>
</configuration>

Output

53
TY-BSC-IT ADVANCE WEB PROGRAMMING 226771

Practical4 (b)

54
TY-BSC-IT ADVANCE WEB PROGRAMMING 226771

XML File
<Advertisements>
<Ad>
<ImageUrl>rose1.jpg</ImageUrl>
<NavigateUrl>http://www.1800flowers.com</NavigateUrl>
<AlternateText>

Order flowers, roses, gifts and more


</AlternateText>
<Impressions>20</Impressions>
<Keyword>flowers</Keyword>
</Ad>
<Ad>
<ImageUrl>rose2.jpg</ImageUrl>
<NavigateUrl>http://www.babybouquets.com.au</NavigateUrl>
<AlternateText>Order roses and flowers</AlternateText>
<Impressions>20</Impressions>
<Keyword>gifts</Keyword>
</Ad>
<Ad>
<ImageUrl>rose3.jpeg</ImageUrl>
<NavigateUrl>http://www.flowers2moscow.com</NavigateUrl>
<AlternateText>Send flowers to Russia</AlternateText>
<Impressions>20</Impressions>
<Keyword>russia</Keyword>
</Ad>
</Advertisements>
Default.aspx
<asp:AdRotator ID="AdRotator1" runat="server" DataSourceID="XmlDataSource1" />
<asp:XmlDataSource ID="XmlDataSource1" runat="server"
DataFile="~/ADFILE.xml"></asp:XmlDataSource>

OUTPUT:

55
TY-BSC-IT ADVANCE WEB PROGRAMMING 226771

56
TY-BSC-IT ADVANCE WEB PROGRAMMING 226771

Practical 4(c): Create Web Form to demonstrate user Controls.


footer.ascx
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="footer.ascx.cs"
Inherits="Pract4c.footer" %>
<table>
<tr>
<td align="center" style="font-family:Cambria;background-color:#00CCFF;
font-size:14px;text-decoration:blink color:#FF0000;font-weight:bold;">
Vinit Choughule</td>
</tr>
</table>
Default.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs"
Inherits="Pract4c.WebForm1" %>

<%@ Register src="footer.ascx" tagname="footer" 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:Label ID="Label1" runat="server" Text="Welcome to the World of
Vinit"></asp:Label>
</div>
<uc1:footer ID="footer1" runat="server" />
</form>
</body>
</html>

Output:

57
TY-BSC-IT ADVANCE WEB PROGRAMMING 226771

Practical 7(a): create a web application to display databinding using drop down list control.
CODE OF C# CODE BEHIND FILE
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;
using System.Web.Configuration;

namespace practical7a
{
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if(!IsPostBack)
{
try
{
string conStr =
WebConfigurationManager.ConnectionStrings["c1"].ConnectionString;
SqlConnection con = new SqlConnection(conStr);
con.Open();
SqlCommand cmd =new SqlCommand("select * from Customer",con);
SqlDataReader dr = cmd.ExecuteReader();
DropDownList1.DataSource = dr;
DropDownList1.DataTextField = "City";
this.DataBind();
}catch(Exception ex)
{
Label1.Text = ex.Message;
}
}
}

protected void Button1_Click(object sender, EventArgs e)


{
Label1.Text="The City You Have Selected is:"+DropDownList1.SelectedValue;
}
}
}

58
TY-BSC-IT ADVANCE WEB PROGRAMMING 226771

Output:

59
TY-BSC-IT ADVANCE WEB PROGRAMMING 226771

Practical 8c: Create a web application to display using Disconnected Data Access and
databinding using Grid view.
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 Practical8c
{
public partial class WebForm1 : System.Web.UI.Page
{
SqlConnection con=new SqlConnection("Data Source=LAPTOP-
NIQ8RJ1U\\SQLEXPRESS;Initial Catalog=you2;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 Products", con);
da.Fill(ds, "Name");
GridView1.DataSource=ds;
GridView1.DataBind();
}
}
}

60
TY-BSC-IT ADVANCE WEB PROGRAMMING 226771

Output:

61

You might also like