0% found this document useful (0 votes)
137 views37 pages

Awp Practical 4,5,6,7

Here are the steps to demonstrate the use of Calendar control to perform the following operations: 1. Add a Calendar control to the ASP.NET web form: <asp:Calendar ID="Calendar1" runat="server"></asp:Calendar> 2. Set the Calendar control's properties like Title, SelectedDate etc. 3. Handle the Calendar control's SelectionChanged event to display the selected date: protected void Calendar1_SelectionChanged(object sender, EventArgs e) { lblSelectedDate.Text = Calendar1.SelectedDate.ToShortDateString(); } 4. Add a button and handle its click event to programmatically select a date: protected void

Uploaded by

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

Awp Practical 4,5,6,7

Here are the steps to demonstrate the use of Calendar control to perform the following operations: 1. Add a Calendar control to the ASP.NET web form: <asp:Calendar ID="Calendar1" runat="server"></asp:Calendar> 2. Set the Calendar control's properties like Title, SelectedDate etc. 3. Handle the Calendar control's SelectionChanged event to display the selected date: protected void Calendar1_SelectionChanged(object sender, EventArgs e) { lblSelectedDate.Text = Calendar1.SelectedDate.ToShortDateString(); } 4. Add a button and handle its click event to programmatically select a date: protected void

Uploaded by

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

23-9-2020

Practical 4
Practical 4-A
4a - Create simple application to demonstrate use of Delegates and events.
Delegatesandevents.aspx file
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="DelegatesAndEvents.aspx.cs"
Inherits="DelegatesAndEvents" %>

<!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="lblResult1" runat="server"></asp:Label>


<br />
<br />
<asp:Label ID="lblResult2" runat="server"></asp:Label>
<br />

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

Delegatesandevents.aspx.cs file

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

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


{
protected void Page_Load(object sender, EventArgs e)
{
dele d1 = new dele(display1);
d1();

dele d2 = new dele(display2);


d2();
1
lblResult1.Text = d1();

lblResult2.Text = d2();
}

public delegate string dele();

public static string display1()


{
string s1 = "Advanced Web Programming";
return s1;
}

public static string display2()


{
string s2 = "Data Structures";
return s2;
}

2
Design

Output

23-9-2020
3
Practical 4-B
4b - Create simple application to demonstrate use of Exception handling.
ExceptionHandling.aspx file
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Exception Handling.aspx.cs"
Inherits="Exception_Handling" %>

<!DOCTYPE html>

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

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; DIVISION OF TWO NUMBERS<br />


<br />
<asp:Label ID="Label1" runat="server" Text="Enter the number :"></asp:Label>
&nbsp;&nbsp;&nbsp;
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<br />
<br />
&nbsp;&nbsp;&nbsp;
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Perform Division" />
<br />
<br />
<asp:Label ID="lblResult" runat="server"></asp:Label>

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

ExceptionHandling.aspx.cs file
using System;
usingSystem.Collections.Generic;
usingSystem.Linq;
usingSystem.Web;
usingSystem.Web.UI;
usingSystem.Web.UI.WebControls;

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


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

4
}

protected void Button1_Click(object sender, EventArgs e)


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

}
}

5
Design

Output

23-9-2020
Practical 4-C
6
4c - Create simple application to demonstrate use of Hierarchical Inheritance.

HierarchicalInheritance.aspx file

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


Inherits="Heirarchiachal_Inheritance" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; HIERARCHIACAL&nbsp; INHERITANCE<br />
<br />
Enter a :&nbsp;&nbsp;&nbsp;&nbsp;
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<br />
<br />
Enter b :&nbsp;&nbsp;&nbsp;&nbsp;
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<asp:Button ID="btnResult" runat="server" OnClick="btnResult_Click" Text="Calculate" />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<br />
<br />
a + b = <asp:Label ID="Label1" runat="server"></asp:Label>
<br />
<br />
a-b=
<asp:Label ID="Label2" runat="server"></asp:Label>
</form>
</body>
</html>

HierarchicalInheritance.aspx.cs file

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

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


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

protected void btnResult_Click(object sender, EventArgs e)


{
B b = new B();

C c = new C();

int m = Convert.ToInt32(TextBox1.Text);
int n = Convert.ToInt32(TextBox2.Text);

int x = b.add(m, n);


int y = c.sub(m, n);

Label1.Text = x.ToString();
Label2.Text = y.ToString();
}

public class A
{
publicint a;
publicint b;
}

public class B : A
{
publicint add(int x, int y)
{
a = x;
b = y;
return a + b;
}
}

public class C : A
{
publicint sub(int x, int y)
{
a = x;
b = y;
return a - b;
}
}

8
Design

Output

23-9-2020
Practical 4-D
4d - Create simple application to demonstrate use of Multilevel Inheritance.

MultilevelInheritance.aspx file
9
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Multilevel Inheritance.aspx.cs"
Inherits="Multilevel_Inheritance" %>

<!DOCTYPE html>

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

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


&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<asp:Button ID="btnResult" runat="server" OnClick="btnResult_Click" style="height: 26px" Text="Calculate" />
<br />
<br />
Number is a power of 2 : <asp:Label ID="Label2" runat="server"></asp:Label>
<br />
<br />
Number is a power of 3:
<asp:Label ID="Label3" runat="server"></asp:Label>
<br />
<br />
Number is a power of 4 :
<asp:Label ID="Label4" runat="server"></asp:Label>

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

MultilevelInheritance.aspx.cs

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

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


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

protected void btnResult_Click(object sender, EventArgs e)


10
{
C c = new C();
int n = Convert.ToInt32(TextBox1.Text);
int x = c.pow2(n);
int y = c.pow3(n);
int z = c.pow4(n);

Label2.Text = x.ToString();
Label3.Text = y.ToString();
Label4.Text = z.ToString();
}
}

public class A
{
publicint pow2(intval)
{
returnval * val;
}
}

public class B : A
{
publicint pow3(intval)
{
int v = pow2(val);

return v * val;
}
}

public class C : B
{
publicint pow4(intval)
{
int v = pow3(val);
return v * val;
}
}

Design

11
Output

23-9-2020
Practical 4-E
4e - Create simple application to demonstrate use of Single Inheritance.

SingleInheritance.aspx file

12
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Single Inheritance.aspx.cs"
Inherits="Single_Inheritance" %>

<!DOCTYPE html>

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

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; SINGLE LEVEL INHERITANCE<br />


<br />

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


&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<asp:TextBox ID="txtNumber" runat="server"></asp:TextBox>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<asp:Button ID="btnCalculate" runat="server" OnClick="btnCalculate_Click" Text="Calculate" />
<br />
<br />
Square of a number : <asp:Label ID="lblSquare" runat="server"></asp:Label>
<br />
<br />
Cube of a number : <asp:Label ID="lblCube" runat="server"></asp:Label>

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

SingleInheritance.aspx.cs file

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

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


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

protected void btnCalculate_Click(object sender, EventArgs e)


{
B b = new B();
int n = Convert.ToInt32(txtNumber.Text);

13
int x = b.sqr(n);
int y = b.cube(n);

lblSquare.Text = x.ToString();

lblCube.Text = y.ToString();

}
}

public class A
{
publicintsqr(intval)
{
returnval * val;
}
}

public class B:A


{
publicint cube(intval)
{
int v = sqr(val);
returnval * v;
}
}

Design

14
Output

14-10-2020
Practical 5

Practical 5-A
15
5a - Demonstrate the use of Calendar control to perform following operations.
i) Demonstrate the use of Calendar control to
perform following operations. Display
messages in a calendar control.
ii) Display vacation in a calendar control.
iii) Selected day in a calendar control using
style.
iv) Difference between two calendar dates.

CalendarControl.aspx file
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Calendar Control.aspx.cs" Inherits="Calendar_Control"
%>

<!DOCTYPE html>

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

<br />

<asp:Calendar ID="Calendar1" runat="server" BackColor="#FFFFCC" BorderColor="#FFCC66" BorderWidth="1px"


DayNameFormat="Shortest" Font-Names="Verdana" Font-Size="8pt" ForeColor="#663399" Height="200px"
ShowGridLines="True" Width="220px" OnDayRender="Calendar1_DayRender"
OnSelectionChanged="Calendar1_SelectionChanged">
<DayHeaderStyleBackColor="#FFCC66" Font-Bold="True" Height="1px" />
<NextPrevStyle Font-Size="9pt" ForeColor="#FFFFCC" />
<OtherMonthDayStyleForeColor="#CC9966" />
<SelectedDayStyleBackColor="#CCCCFF" Font-Bold="True" />
<SelectorStyleBackColor="#FFCC66" />
<TitleStyleBackColor="#990000" Font-Bold="True" Font-Size="9pt" ForeColor="#FFFFCC" />
<TodayDayStyleBackColor="#FFCC66" ForeColor="White" />
</asp:Calendar>
<br />
Your Selected Date : <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
&nbsp;<br />
<br />
Today&#39;s Date :
<asp:Label ID="Label2" runat="server" Text="Label"></asp:Label>
<br />
<br />
Christmas Vacation Starts :
<asp:Label ID="Label3" runat="server" Text="Label"></asp:Label>
<br />
<br />
16
Days remaining for Christmas vacation :
<asp:Label ID="Label4" runat="server" Text="Label"></asp:Label>
<br />
<br />
Days remaining for new year :
<asp:Label ID="Label5" runat="server" Text="Label"></asp:Label>
<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<asp:Button ID="btnResult" runat="server" OnClick="btnResult_Click" Text="Result" />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<asp:Button ID="btnReset" runat="server" Text="Reset" OnClick="btnReset_Click" />

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

CalendarControl.aspx.cs file

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

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


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

protected void btnResult_Click(object sender, EventArgs e)


{
Calendar1.Caption = "SIDRANAAZ QAZI";

Calendar1.FirstDayOfWeek = FirstDayOfWeek.Sunday;
Calendar1.NextPrevFormat = NextPrevFormat.ShortMonth;
Calendar1.TitleFormat = TitleFormat.Month;

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

Label3.Text = "Christmas Vacation Start: 12-24-2020";


TimeSpan d = new DateTime(2020, 12, 24) - DateTime.Now;
Label4.Text = "Days Remaining For Christmas Vacation:" + d.Days.ToString();

TimeSpan d1 = new DateTime(2020, 12, 31) - DateTime.Now;


Label5.Text = "Days Remaining for New Year:" + d1.Days.ToString();

if (Calendar1.SelectedDate.ToShortDateString() == "12-24-2020")
17
Label3.Text = "<b>CHRISTMAS VACATION STARTS</b>";

if (Calendar1.SelectedDate.ToShortDateString() == "12-02-2021")
Label3.Text = "<b>CHRISTMAS VACATION ENDS</b>";
}

protected void Calendar1_DayRender(object sender, 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 = "Teachers-Day-wishes-Messages-greetings.jpg";
g1.Height = 70;
g1.Width = 70;
e.Cell.Controls.Add(g1);
}
if (e.Day.Date.Day == 24 &&e.Day.Date.Month == 12)
{
Calendar1.SelectedDate = new DateTime(2020, 12, 24);
Calendar1.SelectedDates.SelectRange(Calendar1.SelectedDate, Calendar1.SelectedDate.AddDays(10));
Label lbl1 = new Label();
lbl1.Text = "<br>CHRISTMAS!";
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();
}
}

Design

18
Output

19
20
14-10-2020

Practical 5-B
5b - Create a simple web page with various sever controls to demonstrate
setting and use of their properties.

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

<!DOCTYPE html>

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

VIEW STATE DATA :


<asp:Label ID="lblViewState" runat="server"></asp:Label>
<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<asp:Button ID="btnGetData" runat="server" OnClick="Button1_Click" Text="Get Data" />
<br />
<br />
&nbsp;
<asp:ListBox ID="lstLanguage" runat="server" AutoPostBack="True" >
<asp:ListItem>C</asp:ListItem>
<asp:ListItem>C++</asp:ListItem>
<asp:ListItem>Python</asp:ListItem>
<asp:ListItem>Java</asp:ListItem>
<asp:ListItem>C#</asp:ListItem>
<asp:ListItem>ASP.Net</asp:ListItem>
<asp:ListItem>Ruby on rail</asp:ListItem>
</asp:ListBox>
&nbsp;&nbsp;&nbsp;
<asp:Button ID="btnAdd" runat="server" OnClick="btnAdd_Click" Text="ADD" />
&nbsp;&nbsp;&nbsp;
<asp:TextBox ID="txtLanguage" runat="server" TextMode="MultiLine"></asp:TextBox>
<br />
<br />
&nbsp; SELECT COLOR :&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<asp:RadioButton ID="RadioButton1" runat="server" OnCheckedChanged="RadioButton1_CheckedChanged"
Text="RED" />
&nbsp;
<asp:RadioButton ID="RadioButton2" runat="server" OnCheckedChanged="RadioButton2_CheckedChanged"
Text="BLUE" />
&nbsp;&nbsp;
21
<asp:RadioButton ID="RadioButton3" runat="server" OnCheckedChanged="RadioButton3_CheckedChanged"
Text="BEIGE" />
<br />
<br />
&nbsp; SELECT SPECIAL FORMATTING :&nbsp;
<asp:CheckBox ID="CheckBox1" runat="server" OnCheckedChanged="CheckBox1_CheckedChanged"
Text="BOLD" />
&nbsp;<asp:CheckBox ID="CheckBox2" runat="server" OnCheckedChanged="CheckBox2_CheckedChanged"
Text="ITALIC" />
&nbsp;
<asp:CheckBox ID="CheckBox3" runat="server" OnCheckedChanged="CheckBox3_CheckedChanged"
Text="UNDERLINE" />
<br />
<br />
&nbsp; SELECT SIZE :
<asp:DropDownList ID="DropDownList1" runat="server"
OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged">
<asp:ListItem>12</asp:ListItem>
<asp:ListItem>14</asp:ListItem>
<asp:ListItem>16</asp:ListItem>
<asp:ListItem>18</asp:ListItem>
<asp:ListItem>20</asp:ListItem>
<asp:ListItem>22</asp:ListItem>
</asp:DropDownList>
&nbsp;&nbsp;&nbsp;
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
<br />
<br />
&nbsp; SELECT NAME :
<asp:DropDownList ID="DropDownList2" runat="server"
OnSelectedIndexChanged="DropDownList2_SelectedIndexChanged">
<asp:ListItem>ROHINI</asp:ListItem>
<asp:ListItem>NIHAR</asp:ListItem>
<asp:ListItem>MEAGEN</asp:ListItem>
<asp:ListItem>RONIT</asp:ListItem>
<asp:ListItem>MAYURESH</asp:ListItem>
<asp:ListItem>SOUMYA</asp:ListItem>
<asp:ListItem>SHARON</asp:ListItem>
</asp:DropDownList>
<br />
<br />
&nbsp; UPLOAD IMAGE :
<asp:Image ID="Image1" runat="server" ImageUrl="http://localhost:51528/Teachers-Day-wishes-Messages-
greetings.jpg" />
</div>
</form>
</body>
</html>

StudentProfile.aspx.cs
using System;
usingSystem.Collections.Generic;
usingSystem.Linq;

22
usingSystem.Web;
usingSystem.Web.UI;
usingSystem.Web.UI.WebControls;

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


{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
stringstr = "Mayuresh";

if (ViewState["name"] == null)
{
ViewState["name"] = str;
}} // Response.Redirect("https://mail.google.com/mail/u/0/#inbox");
}
protected void Button1_Click(object sender, EventArgs e)
{
lblViewState.Text = ViewState["name"].ToString();
}
protected void btnAdd_Click(object sender, EventArgs e)
{
// txtLanguage.Text = "";
for (inti = 0; i<lstLanguage.Items.Count; i++)
{
if (lstLanguage.Items[i].Selected == true)
{
txtLanguage.Text = txtLanguage.Text + " " + lstLanguage.Items[i].Text + "\n";
}
}}
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
Label1.Font.Size = int.Parse(DropDownList1.SelectedItem.Text);
}
protected void DropDownList2_SelectedIndexChanged(object sender, EventArgs e)
{
Label1.Text = DropDownList2.SelectedItem.Text;
}
protected void RadioButton1_CheckedChanged(object sender, EventArgs e)
{
Label1.BackColor = System.Drawing.Color.Red;
}
protected void RadioButton2_CheckedChanged(object sender, EventArgs e)
{
Label1.BackColor = System.Drawing.Color.Blue;
}
protected void RadioButton3_CheckedChanged(object sender, EventArgs e)
{
Label1.BackColor = System.Drawing.Color.Beige;
}
protected void CheckBox1_CheckedChanged(object sender, EventArgs e)
{
Label1.Font.Bold = true;

23
}
protected void CheckBox2_CheckedChanged(object sender, EventArgs e)
{
Label1.Font.Italic = true;
}
protected void CheckBox3_CheckedChanged(object sender, EventArgs e)
{
Label1.Font.Underline = true;
}}

24
Design

Output

25
21-10-2020

26
Practical 6

Practical 6-A
6 a - Demonstrate the use of Treeview control and Data list control

StudentDetail.xml file

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


<studentdetail>
<student>
<sid>1</sid>
<sname>Sahil</sname>
<sclass>TYIT</sclass>
</student>
<student>
<sid>2</sid>
<sname>Nikhil</sname>
<sclass>TYCS</sclass>
</student>
<student>
<sid>3</sid>
<sname>Krinal</sname>
<sclass>TYIT</sclass>
</student>
<student>
<sid>4</sid>
<sname>Rima</sname>
<sclass>TYCS</sclass>
</student>
</studentdetail>

27
Tree Control
TreeControl.aspx file
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="TreeControl.aspx.cs" Inherits="TreeControl" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
&nbsp;&nbsp;TREE CONTROL NAVIGATION :
Treeview control navigation:<asp:TreeView ID="TreeView1" runat="server" Width="150px" ImageSet="Arrows"
BackColor="#FF66FF" BorderColor="#333399" ForeColor="#009900">
<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"
Target="_blank"></asp:TreeNode>
<asp:TreeNode Text="Constructor Overloading" Value="GREEN" NavigateUrl="~/clsconstrc.aspx"></asp:TreeNode>
<asp:TreeNodeNavigateUrl="~/singleInh.aspx" Text="Inheritance" Value="BLUE"></asp:TreeNode>
<asp:TreeNodeNavigateUrl="~/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" />
<RootNodeStyleBackColor="#00FF99" BorderColor="#006600" BorderStyle="Ridge" />
<SelectedNodeStyle Font-Underline="True" ForeColor="#5555DD" HorizontalPadding="0px" VerticalPadding="0px"
BackColor="#CCFFFF" BorderColor="#990033" BorderStyle="Double" Font-Bold="True" Font-Italic="True" />
</asp:TreeView>
<br />
<asp:TreeView ID="TreeView2" runat="server" ImageSet="Arrows" ShowLines="True">
<HoverNodeStyle Font-Underline="True" ForeColor="#5555DD" />
<Nodes>
<asp:TreeNode Text="HOME" Value="HOME"></asp:TreeNode>
<asp:TreeNodeNavigateUrl="https://www.amazon.com/" Target="_blank" Text="EMPLOYEE" Value="EMPLOYEE">
<asp:TreeNode Text="UPLOAD RESUME" Value="UPLOAD RESUME"></asp:TreeNode>
<asp:TreeNode Text="EDIT RESUME" Value="EDIT RESUME"></asp:TreeNode>
</asp:TreeNode>
<asp:TreeNode Text="ADMIN" Value="ADMIN">
<asp:TreeNode Text="ADD USER" Value="ADD USER"></asp:TreeNode>
<asp:TreeNode Text="DELETE USER" Value="DELETE USER"></asp:TreeNode>
<asp:TreeNode Text="UPDATE USER" Value="UPDATE USER"></asp:TreeNode>
</asp:TreeNode>
<asp:TreeNode Text="EMPLOYER" Value="EMPLOYER">
<asp:TreeNode Text="UPLOAD JOB PROFILE" Value="UPLOAD JOB PROFILE"></asp:TreeNode>
<asp:TreeNode Text="UPDATE JOB PROFILE" Value="UPDATE JOB PROFILE"></asp:TreeNode>
</asp:TreeNode>
</Nodes>

28
<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 />
<br />
<br />
Fetch Datalist Using XML data :
<asp:DataList ID="DataList1" runat="server">
<ItemTemplate>
<table border="1" class="table">
<tr>
<td>Roll Number : <%# Eval("sid") %><br />
Name of the student : <%# Eval("sname") %><br />
Class : <%# Eval("sclass")%></td>
</tr>
</table>
</ItemTemplate>
</asp:DataList>
<br />
<asp:DataList ID="DataList2" runat="server">
<ItemTemplate>
<table border="1">
</table>
</ItemTemplate>
</asp:DataList>
<br />
<br />
<br />
<br />
<br />
</div>
</form>
</body>
</html>

TreeControl.aspx.cs file
using System;
usingSystem.Collections.Generic;
usingSystem.Linq;
usingSystem.Web;
usingSystem.Web.UI;
usingSystem.Web.UI.WebControls;
usingSystem.Data;
public partial class TreeControl : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
BindData();
}
}
29
protected void BindData()
{
DataSet ds = new DataSet();
ds.ReadXml(Server.MapPath("Studentdetail.xml"));

if (ds != null &&ds.HasChanges())


{
DataList1.DataSource = ds;
DataBind();
}
else
{
DataList1.DataBind();
}
}
}

30
Design

31
Output

32
After Clicking on Employee it will take you to the Amazon link

21-10-2020

33
Practical 7
Practical 7-A
a) Create Web Form to demonstrate use of Web User Control.

WebUserControl.aspx file

<%@ Page Language=”C#”AutoEventWireup=”true”CodeFile=”WEB USER CONTROL.aspx.cs”


Inherits=”WEB_USER_CONTROL” %>

<%@ Register Src=”~/MyWebUserControl.ascx”TagPrefix=”uc”TagName=”Student” %>


<!DOCTYPE html>

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

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

WebUserControl.aspx.cs file

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

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


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

}
}

MyWebUserControl.ascx file
34
<%@ Control Language=”C#”AutoEventWireup=”true”CodeFile=”MyWebUserControl.ascx.cs”
Inherits=”MyWebUserControl” %>
<h3>This is User Contro1 </h3>
<table>
<tr>
<td>Name</td>
<td>
<asp:TextBox ID=”txtName”runat=”server”></asp:TextBox>
</td>
</tr>
<tr>
<td>City</td>
<td>
<asp:TextBox ID=”txtcity”runat=”server”></asp:TextBox></td>
</tr>
<tr>
<td></td>
<td></td>
</tr>
<tr>
<td></td>
<td>
<asp:Button ID=”txtSave”runat=”server” Text=”Save”OnClick=”txtSave_Click” style=”height: 26px” />
</td>
</tr>
</table>
<br />
<asp:Label ID=”Label1”runat=”server”ForeColor=”black” Text=”“></asp:Label>

MyWebUserControl.ascx.cs file

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

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


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

protected void txtSave_Click(object sender, EventArgs e)


{
Label1.Text = “Your Name is “ +txtName.Text + “ and you are from “ + txtcity.Text;
}
}

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

<!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>

Default.cs file
using System;
usingSystem.Collections.Generic;
usingSystem.Linq;
usingSystem.Web;
usingSystem.Web.UI;
usingSystem.Web.UI.WebControls;

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


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

}
}

36
Design

Output

Shirin Husain

Shirin Husain

37

You might also like