Final Awp PDF
Final Awp PDF
Final Awp PDF
Submitted by
Name: ________________________
Roll no: _______________________
Class: _______________________
Subject: _______________________
Submitted to:
(AffiliatedToUniversityofMumbai)
CERTIFICATE
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title></head>
<body>
</div></form></body>
</html>
pract1a.aspx.cs-
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
}}
Output:
Design
Default.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 pract1b : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs
e)
{
}
protected void Submit_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);
}
else if (DropDownList1.SelectedItem.Text.Equals("UpperCase"))
{
result.Text = "<br>" + "Upper case of String :" + "<br>" + (str1.ToUpper() + " " +
str2.ToUpper());
}
else if (DropDownList1.SelectedItem.Text.Equals("LowerCase"))
{
result.Text = "<br>" + "Lower case of String :" + "<br>" + str1.ToLower() + " " +
str2.ToLower();
}
else if (DropDownList1.SelectedItem.Text.Equals("Length"))
{
result.Text = "<br>" + "Length of first string " + str1 + ":<br>" + str1.Length;
}
else if (DropDownList1.SelectedItem.Text.Equals("IsEmpty"))
{
if (String.IsNullOrEmpty(str1) && String.IsNullOrEmpty(str2))
{
result.Text = "<br>" + "Both the textbox is empty";
}
else if (String.IsNullOrEmpty(str1))
{
result.Text = "TextBox 1 is Empty";
}
else if (String.IsNullOrEmpty(str2))
{
result.Text = "TextBox 2 is Empty";
}
else
{
result.Text = "None of the TextBox is Empty";
} }
else
{
String reverse1 = new string(str1.Reverse().ToArray());
String reverse2 = new string(str2.Reverse().ToArray());
result.Text = "Reverse of 1st string :" + reverse1;
} } }
Output:
Default.apsx
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class pract1c : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Submit_Click(object sender, EventArgs e)
{
if (DropDownList1.SelectedItem.Text.Equals("Fibonacci"))
{
int usrInputNumber = Convert.ToInt32(textBox1.Text.ToString());
int firstNo = 0;
int secondNo = 1;
int sum = 0;
Response.Write("fibonnaci series : " + firstNo + ", " + secondNo);
int i = 2;
while (i < usrInputNumber)
{
sum = firstNo + secondNo;
Response.Write(", " + sum);
firstNo = secondNo;
secondNo = sum;
i++;
} }
else if (DropDownList1.SelectedItem.Text.Equals("prime"))
{
int num1 = Convert.ToInt32(textBox1.Text.ToString());
int i;
for (i = 2; i < num1 - 1; i++)
{
if (num1 % i == 0)
break;
}
if (i < num1 - 1)
{
result.Text = "IS NOT A PRIME NUMBER";
}
else
{
result.Text = "A PRIME NUMBER";
}}
else if (DropDownList1.SelectedItem.Text.Equals("vowels"))
{
string str = textBox1.Text.ToString().ToLower();
int c = 0;
for (int i = 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")
{
c++;
} }
result.Text = ("Total number of vowels in " + str + " is " + c);
}
else if (DropDownList1.SelectedItem.Text.Equals("Reverse and Find sum of
Digit"))
{
int num1 = Convert.ToInt32(textBox1.Text.ToString());
int reverse = 0;
int sum = 0;
while (num1 != 0)
{
int remainder = num1 % 10;
reverse = reverse * 10 + remainder;
sum = remainder + sum;
num1 = num1 / 10;
}
result.Text = "<br>" + "Reverse of entered number is " + reverse + "<br>" + "Sum
of digits is" + sum;
}
else{
String s = textBox1.Text.ToString();
foreach (char c in s)
{
Response.Write("<br>" + c);
} }}}
Output:
Practical No:02
Working with Object Oriented C# and ASP .NET
a) Create simple application to perform following operations
i. Finding factorial Value ii. Money Conversion
iii. Quadratic Equation iv. Temperature Conversion
i. Finding factorial Value
Default.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs"
Inherits="Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title></title></head>
<body>
<form id="form1" runat="server">
<div align="center">
<asp:Label ID="Label1" runat="server" Text="Enter a Number:"></asp:Label>
<asp:TextBox ID="TextBox1" runat="server" Width="147px"></asp:TextBox>
<br />
<asp:Button ID="Button1" runat="server" onclick="Button1_Click"
Text="Factorial" /><br />
<asp:Label ID="Label2" runat="server"></asp:Label>
</div></form>
</body>
</html>
Design
Default.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 Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
int n = Int32.Parse(TextBox1.Text);
int num, i, f = 1;
num = n;
for (i = 1; i <= n; i++)
{
f = f * i;
}
Label2.Text = "Factorial is: " + f.ToString();
}
}
Output:
a2.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 a2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
public class conv
{
public double d, r, e, a;
public conv(double amount)
{
a = amount;
}
public void rtd()
{
d = a / 69;
}
public void dtr()
{
r = a * 69;
}
public void rte()
{
e = a / 82.36;
}
public void etr()
{
r = a * 82.36;
}
}
protected void Button1_Click(object sender, EventArgs e)
{
double a = Double.Parse(TextBox1.Text);
conv obj = new conv(a);
obj.rtd();
TextBox2.Text = Convert.ToString(obj.d);
obj.dtr();
TextBox3.Text = Convert.ToString(obj.r);
obj.rte();
TextBox4.Text = Convert.ToString(obj.e);
obj.etr();
TextBox5.Text = Convert.ToString(obj.r);
}
}
Output:
iii.Quadratic Equation.
a3.aspx
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title></head>
<body>
<div align="center">
</div></form>
</body>
</html>
Design-
a3.aspx.cs-
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
{
public double d, x1, x2;
d = b * b - 4 * a * c;
if (d == 0)
x1 = -b / (2.0 * a);
x2 = x1;
msg = "Both the roots are equal<br>1st Root is:" + x1 + "<br>2nd Root is:" + x2 +
"<br>";
else if (d > 0) {
msg = "Both the roots are real and different<br>1st Root is:" + x1 + "<br>2nd
Root is:" + x2 + "<br>";
} else
}}}
{
int a, b, c;
a = Int32.Parse(TextBox1.Text);
b = Int32.Parse(TextBox2.Text);
c = Int32.Parse(TextBox3.Text);
Response.Write(qe.msg);
}}
Output-
iv.Temperature Conversion.
a4.aspx-
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title></head>
<body>
</div></form></body>
</html>
Design-
a4.aspx.cs-
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
{ }
public convert(double t)
temp=t;
} }
double c = Double.Parse(TextBox1.Text);
obj.ctf();
TextBox2.Text = obj.f.ToString();
double c = Double.Parse(TextBox3.Text);
obj.ftc();
TextBox4.Text = obj.c.ToString();
}}
Output-
Practical No:03
Working with Web Forms and Controls
a)Create a simple web page with various sever controls to demonstrate
setting and use of their properties. (Example : AutoPostBack)
Default.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs"
Inherits="Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title></title></head>
<body>
<form id="form1" runat="server"><div>
<asp:Label ID="Label1" runat="server" Text="Name :"></asp:Label>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<br /><br />
<asp:Label ID="Label2" runat="server" Text="RNo."></asp:Label>
:
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
<br /><br />
<asp:Label ID="Label3" runat="server" Text="Class"></asp:Label>
:<asp:RadioButton ID="RadioButton1" runat="server" Text="FY" />
<asp:RadioButton ID="RadioButton2" runat="server" Text="SY" />
<asp:RadioButton ID="RadioButton3" runat="server" Text="TY" />
<br /><br />
<asp:Label ID="Label4" runat="server" Text="Course :"></asp:Label>
<asp:DropDownList ID="DropDownList1" runat="server"
onselectedindexchanged="DropDownList1_SelectedIndexChanged"
AutoPostBack="true">
<asp:ListItem>B.SC(IT)</asp:ListItem>
<asp:ListItem>M.SC(IT)</asp:ListItem>
<asp:ListItem>MCA</asp:ListItem>
</asp:DropDownList>
<br /><br />
<asp:Button ID="Button1" runat="server" Text="Submit"
onclick="Button1_Click"/>
<br />
<asp:Label ID="Label5" runat="server"></asp:Label>
</div> </form> </body>
</html>
Output:
Default.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 Default : 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:
CalndrCntrl.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace Calendar
{
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
Calendar1.Caption = "Vikas Pandey";
Calendar1.FirstDayOfWeek = FirstDayOfWeek.Sunday;
Calendar1.NextPrevFormat = NextPrevFormat.ShortMonth;
Calendar1.TitleFormat = TitleFormat.Month;
Label1.Text = "Your Selected Date:" + Calendar1.SelectedDate.ToString();
Label2.Text = "Todays Date:" + Calendar1.TodaysDate.ToShortDateString();
Label3.Text = "Ganpati Vacation Start: 09-13-2018";
TimeSpan d = new DateTime(2018, 09, 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() == "09-13-2018")
Label3.Text = "<b>Ganpati Festival Start</b>";
if (Calendar1.SelectedDate.ToShortDateString() == "09-23-2018")
Label3.Text = "<b>Ganpati Festival End<b>";
}
protected void Calendar1_DayRender(object sender, DayRenderEventArgs e)
{
if (e.Day.Date.Day == 15 && e.Day.Date.Month == 8)
{
e.Cell.BackColor = System.Drawing.Color.GreenYellow;
Label lbl1 = new Label();
lbl1.Text = "<br>Independance Day!<br>";
e.Cell.Controls.Add(lbl1);
Image g1 = new Image();
g1.ImageUrl = "id.jpg";
g1.Height = 40;
g1.Width = 75;
e.Cell.Controls.Add(g1);
}
if (e.Day.Date.Day == 5 && e.Day.Date.Month == 9)
{
e.Cell.BackColor = System.Drawing.Color.Yellow;
Label lbl1 = new Label();
lbl1.Text = "<br>Teavhers Day!<br>";
e.Cell.Controls.Add(lbl1);
Image g1 = new Image();
g1.ImageUrl = "td.jpg";
g1.Height = 40;
g1.Width = 75;
e.Cell.Controls.Add(g1);
}
if (e.Day.Date.Day == 13 && e.Day.Date.Month == 9)
{
Calendar1.SelectedDate = new DateTime(2018, 09, 12);
Calendar1.SelectedDates.SelectRange(Calendar1.SelectedDate,
Calendar1.SelectedDate.AddDays(10));
Label lbl1 = new Label();
lbl1.Text = "<br>Ganpati!<br>";
e.Cell.Controls.Add(lbl1);
Image g2 = new Image();
g2.ImageUrl = "gc.jpg";
g2.Height = 40;
g2.Width = 75;
e.Cell.Controls.Add(g2);
} }
protected void Button2_Click(object sender, EventArgs e)
{
Label1.Text = "";
Label2.Text = "";
Label3.Text = "";
Label4.Text = "";
Label5.Text = "";
Calendar1.SelectedDates.Clear();
}}}
Output:
prac3c.aspx.cs
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="prac3c.aspx.cs"
Inherits="prac3b" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
protected void Button1_Click(object sender, EventArgs e)
{
TreeNodeCollection T;
T = TreeView1.CheckedNodes;
DataList1.DataSource = T;
DataList1.DataBind();
DataList1.Visible = true;
}
</script>
Output:
b) Treeview operations
prac3b2.aspx
<%@ Page Language="C#" AutoEventWireup="true"
CodeFile="prac3b2.aspx.cs" Inherits="prac3b2" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title></title></head>
<body>
<form id="form1" runat="server"><div>
<asp:TreeView ID="TreeView1" runat="server"
onselectednodechanged="TreeView1_SelectedNodeChanged" ShowLines="True"
ontreenodecollapsed="TreeView1_TreeNodeCollapsed">
<Nodes>
<asp:TreeNode Text="I.T. Department" Value="I.T. Department">
<asp:TreeNode Text="Class Room" Value="Class Room">
<asp:TreeNode Text="601" Value="601"></asp:TreeNode>
<asp:TreeNode Text="602" Value="602"></asp:TreeNode>
</asp:TreeNode>
<asp:TreeNode Text="Lab" Value="Lab">
<asp:TreeNode Text="Lab-1" Value="Lab-1"></asp:TreeNode>
<asp:TreeNode Text="Lab-2" Value="Lab-2"></asp:TreeNode>
</asp:TreeNode>
</asp:TreeNode>
</Nodes>
</asp:TreeView>
</div></form>
</body></html>
Design:
prac3b2.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 prac3b2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void TreeView1_SelectedNodeChanged(object sender, EventArgs e)
{
Response.Write("You have selected the option:" + TreeView1.SelectedValue);
}
protected void TreeView1_TreeNodeCollapsed(object sender, TreeNodeEventArgs
e)
{
Response.Write("The value Collapsed was:" + e.Node.Value);
}
}
Output:
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 _4a
{
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
if(Page.IsValid)
{
Label7.Text = "Thank You";
}
else
{
Label7.Text = "The text must be exactly 8 characters long!";
}
}
void ServerValidation(object source,ServerValidateEventArgs e)
{
if (e.Value.Length == 8)
e.IsValid = true;
else
e.IsValid = false;
}}}
Output:
b)Create Web Form to demonstrate use of Adrotator Control.
WebForm1.aspx
<%@ Page Language="C#" AutoEventWireup="true"
CodeBehind="WebForm1.aspx.cs" Inherits="_4b.WebForm1" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title></head>
<body>
<form id="form1" runat="server"><div>
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager><br />
<asp:Timer ID="Timer1" Interval="2000" runat="server">
</asp:Timer><br />
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
</asp:UpdatePanel><br />
<asp:AdRotator ID="AdRotator1" runat="server"
AdvertisementFile="~/XMLFile1.xml" Height="200px" Width="200px" />
<br /></div></form></body></html>
Design:
XMLFile1.xml
<?xml version="1.0" encoding="utf-8" ?>
<Advertisements><Ad>
<ImageUrl>~/v.png</ImageUrl>
</Ad><Ad>
<ImageUrl>~/v1.png</ImageUrl>
</Ad><Ad>
<ImageUrl>~/v2.jpg</ImageUrl>
</Ad><Ad>
<ImageUrl>~/v3.jpg</ImageUrl>
</Ad><Ad>
<ImageUrl>~/v4.jpg</ImageUrl>
</Ad><Ad>
<ImageUrl>~/v5.jpg</ImageUrl>
</Ad><Ad>
<ImageUrl>~/v6.jpg</ImageUrl></Ad>
</Advertisements>
Output:
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title></head>
<body>
<form id="form1" runat="server"><div><br />
</div></form></body>
</html>
Design
Default.acpx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
{ }
Label4.Text = "Your Name is " + TextBox1.Text + " and you are from " +
TextBox2.Text;
}}
Output:
Practical No:05
Working with Navigation, Beautification and Master page.
a)Create Web Form to demonstrate use of Website Navigation controls and Site
Map.
Pract5a.aspx
<%@ Page Language="C#" AutoEventWireup="true"
CodeBehind="Pract5a.aspx.cs" Inherits="Practical5a.Pract5a" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title></head>
<body>
<form id="form1" runat="server">
<div>
<asp:SiteMapDataSource ID="SiteMapDataSource1" runat="server" />
<br />
<asp:Menu ID="Menu1" runat="server" DataSourceID="SiteMapDataSource1">
</asp:Menu></div>
</form>
</body>
</html>
Design
Pract5a.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace Practical5a
{
public partial class Pract5a : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}}}
Web.sitemap
<?xml version="1.0" encoding="utf-8" ?>
<siteMap xmlns="http://schemas.microsoft.com/AspNet/SiteMap-File-1.0" >
<siteMapNode url="Pract5a.aspx" title="Home" description="Home page of our
website">
<siteMapNode url="clsProp.aspx" title="Page2" description="Page2" />
<siteMapNode url="Default2.aspx" title="Page3" description="Page3" />
<siteMapNode url="Default3.aspx" title="Page4" description="Page4" />
</siteMapNode>
</siteMap>
Add 3 more .aspx files with “Welcome” message
Output:
b). Create a web application to demonstrate use of Master Page with applying
Styles and Themes for page beautification.
MasterPage.master
<%@ Master Language="C#" AutoEventWireup="true"
CodeFile="MasterPage.master.cs" Inherits="MasterPage" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Master Page</title>
<link href="css/my.css" rel="stylesheet" />
<asp:ContentPlaceHolder ID="head" runat="server">
</asp:ContentPlaceHolder>
<style type="text/css">
.auto-style1 {
position: absolute;
top: 373px;
left: 1028px;
bottom: 303px;
}
.auto-style2 {
position: absolute;
top: 537px;
left: 1016px;
z-index: 1;
}
</style></head>
<body>
<!DOCTYPE html>
<form id="form1" runat="server">
<html><head>
<title>Master</title>
<link rel="stylesheet" type="text/css" href="StyleSheet.css">
</head>
<body><header id="header">
<h1>Demo Of Master Page</h1>
</header>
<nav id="nav">
<ul>
<li><a href="home.aspx">Insight</a></li>
<li><a href="#">Products</a></li>
<li><a href="#">Downloads</a></li>
<li><a href="#">Contact Us</a></li>
</ul></nav>
<aside id="side">
<h1>Info</h1>
<a href="#"><p>Product Type 1</p></a>
<a href="#"><p>Product Type 2</p></a>
<a href="#"><p>Product Type 3<a href="#"><asp:ScriptManager
ID="ScriptManager1" runat="server">
</asp:ScriptManager></a></p>
<asp:Button ID="Button2" runat="server" CssClass="auto-style1" style="z-index:
1" Text="Button" />
<asp:Button ID="Button1" runat="server" CssClass="auto-style2" Text="Button"
/>
</aside><div id="con">
<asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server">
</asp:ContentPlaceHolder>
</div>
<footer id="footer">
copyright @Sambare
</footer></body>
</html></form>
</body></html>
MasterDisplay.aspx
<%@ Page Title="" Language="C#" MasterPageFile="~/MasterPage.master"
AutoEventWireup="true" CodeFile="MasterDisplay.aspx.cs"
Inherits="MasterDisplay" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1"
runat="server">
<h1>Home page</h1>
</asp:Content>
StyleSheet.css
#header{
color: blueviolet;
text-align: center;
font-size: 20px;
}
#nav{
background-color:darkseagreen;
padding: 5px;
}
ul{
list-style-type: none;
}
li a {
color:crimson ;
font-size: 30px;
column-width: 5%;
}li
{
display: inline;
padding-left: 2px;
column-width: 20px;
}
a{
text-decoration: none;
margin-left:20px
}
li a:hover{
background-color: aqua;
color:coral ;
padding:1%;
}
#side{
text-align: center;
float: right;
width: 15%;
padding-bottom: 79%;
background-color: #F1FAEE;
}
#article{
background-color: burlywood;
padding: 10px;
padding-bottom: 75%;
}
#footer{
background-color: #C7EFCF;
text-align:center;
padding-bottom: 5%;
font-size: 20px;
}
#con{
border:double;
border-color:burlywood; }
c)Create a web application to demonstrate various states of
ASP.NET Pages.
Default.aspx
Deafult.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 _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (IsPostBack)
{
if (ViewState["count"] != null)
{
int viewstateval = Convert.ToInt32(ViewState["count"]) + 1;
Label1.Text = "ViewState:" + viewstateval.ToString();
ViewState["count"] = viewstateval.ToString();
} }
else {
ViewState["count"] = "1";
} }
protected void Button1_Click(object sender, EventArgs e)
{
Label2.Text = ViewState["count"].ToString();
}
protected void Button2_Click(object sender, EventArgs e)
{
Page.EnableViewState = true;
HiddenField1.Value = "welcome to our website:http://www.google.com" +
"<br/>";
Label1.Text = HiddenField1.Value;
HiddenField1.Value = "0";
int i = 0;
i = (int.Parse(HiddenField1.Value)) + 1;
Label2.Text = i.ToString();
HiddenField1.Value = i.ToString();
}
protected void Button3_Click(object sender, EventArgs e)
{
HttpCookie c1 = new HttpCookie("name");
c1.Value = TextBox1.Text;
Response.Cookies.Add(c1);
Response.Redirect("Default2.aspx");
}
protected void Button4_Click(object sender, EventArgs e)
{
ViewState["name"] = TextBox2.Text;
ViewState["password"] = TextBox3.Text;
TextBox2.Text = TextBox3.Text = string.Empty;
}
protected void Button5_Click(object sender, EventArgs e)
{
if (ViewState["name"] != null)
{
TextBox2.Text = ViewState["name"].ToString();
}
if (ViewState["password"] != null)
{
TextBox3.Text = ViewState["password"].ToString();
}
}}
Default2.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 Default2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (Request.Cookies["name"] != null)
{
Response.Write("Welcome:" + Request.Cookies["name"].Value);
}
}}
Output:
Practical No:06
Working with Database
a)Create a web application bind data in a multiline textbox by querying in another
textbox.
Deafult.aspx
<!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:Button ID="Button1" runat="server" Text="Button"
onclick="Button1_Click" />
<br />
<asp:TextBox ID="TextBox1" runat="server" Text="<%# str %>"
TextMode="MultiLine"></asp:TextBox>
<br />
<br /><br />
</div><br /><br />
</form>
</body></html>
Design:
Deafult.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 partial class _Default : System.Web.UI.Page
{
protected String str;
SqlConnection cn = new SqlConnection("Data
Source=(LocalDB)\\MSSQLLocalDB;AttachDbFilename=F:\\jkwebsite\\pract6a2\
\App_Data\\Database.mdf;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 stud_dtls", cn);
cn.Open();
SqlDataReader dr = cmd.ExecuteReader();
while (dr.Read())
{
str += dr["id"] + " " + dr["name"] + "\n";
}
this.DataBind();
} }
Design.apsx.cs
using System;
using System.Data;
using System.Collections.Generic;
using System.Configuration;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class Default2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
string connStr =
ConfigurationManager.ConnectionStrings["connStr"].ConnectionString;
SqlConnection con = new SqlConnection(connStr);
SqlCommand cmd = new SqlCommand("Select * from customer", con);
con.Open();
SqlDataReader reader = cmd.ExecuteReader();
while (reader.Read())
{
Label1.Text += reader["c_name"].ToString() + " " + reader["c_city"].ToString()
+ " " + reader["c_state"].ToString()+"<br>";
}
reader.Close();
con.Close();
} }
Output:
Output:
Practical No:07
a)Create a web application to display Databinding using
dropdownlist control.
Design
Web.config
<configuration>
<connectionStrings>
<add name="DatabaseConnectionString" connectionString="Data
Source=(LocalDB)\v11.0;AttachDbFilename="C:\Users\Deepak\Documents\
Visual Studio 2012\WebSites\6c\App_Data\Database.mdf";Integrated
Security=True;Connect Timeout=30"
providerName="System.Data.SqlClient" />
<add name="ConnectionString" connectionString="Data
Source=(LocalDB)\v11.0;AttachDbFilename=|DataDirectory|\Database2.mdf;Integ
rated Security=True"
providerName="System.Data.SqlClient" />
</connectionStrings>
<system.web>
<compilation debug="false" strict="false" explicit="true" targetFramework="4.5"
/>
<httpRuntime targetFramework="4.5" />
</system.web>
</configuration>
Default.aspx.cs
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (IsPostBack == false)
{
string DatabaseConnectionString =
ConfigurationManager.ConnectionStrings["DatabaseConnectionString"].Connectio
nString;
SqlConnection con = new SqlConnection(DatabaseConnectionString);
SqlCommand cmd = new SqlCommand("select name from student", con);
con.Open();
SqlDataReader reader = cmd.ExecuteReader();
DropDownList1.DataSource = reader;
DropDownList1.DataTextField = "name";
DropDownList1.DataBind();
reader.Close();
con.Close();
}}
protected void Button1_Click(object sender, EventArgs e)
{
Label1.Text = "You have selected " + DropDownList1.SelectedValue;
}}
Output:
b)Create a web application for to display the phone no of an author
using database.
Default.aspx
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title></head>
<body>
<DeleteParameters>
</DeleteParameters>
<InsertParameters>
</InsertParameters>
<UpdateParameters>
</UpdateParameters>
</asp:SqlDataSource></div>
</form></body></html>
Design
Database:
Defult.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;
SqlDataReader dr;
protected void Page_Load(object sender, EventArgs e)
{ }
cn.Open();
dr = cmd.ExecuteReader();
while (dr.Read())
TextBox2.Text = Convert.ToString(dr["phoneno"]);
}}}
Output:
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Data;
using System.Web.UI.WebControls;
public partial class _7c : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
string connStr =
ConfigurationManager.ConnectionStrings["connStr"].ConnectionString;
SqlConnection con = new SqlConnection(connStr);
string InsertQuery = "insert into bank
values(@b_add,@b_city,@b_name,@b_state,@b_zip)";
SqlCommand cmd = new SqlCommand(InsertQuery,con);
cmd.Parameters.AddWithValue("@b_add", TextBox1.Text);
cmd.Parameters.AddWithValue("@b_city", TextBox2.Text);
cmd.Parameters.AddWithValue("@b_name", TextBox3.Text);
cmd.Parameters.AddWithValue("@b_state", TextBox4.Text);
cmd.Parameters.AddWithValue("@b_zip", TextBox5.Text);
con.Open();
cmd.ExecuteNonQuery();
Label6.Text = "Record Inserted Successfully";
TextBox1.Text = "";
TextBox2.Text = "";
TextBox3.Text = "";
TextBox4.Text = "";
TextBox5.Text = "";
con.Close();
}
protected void Button2_Click(object sender, EventArgs e)
{
string connStr =
ConfigurationManager.ConnectionStrings["connStr"].ConnectionString;
SqlConnection con = new SqlConnection(connStr);
string deleteQuery = "delete from bank where b_add=@b_add";
SqlCommand cmd = new SqlCommand(deleteQuery, con);
cmd.Parameters.AddWithValue("@b_add", TextBox1.Text);
con.Open();
cmd.ExecuteNonQuery();
Label6.Text = "Record Deleted Successfully";
TextBox1.Text = "";
TextBox2.Text = "";
TextBox3.Text = "";
TextBox4.Text = "";
TextBox5.Text = "";
con.Close();
}}
Output:
Practical No:08
Working with data controls
a)Create a web application to demonstrate various uses and properties of
SqlDataSource.
Default.aspx
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head><body>
<form id="form1" runat="server">
<div><br />
<asp:Label ID="Label1" runat="server" Text="Enter Your
Roll_No:"></asp:Label>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox><br />
<asp:Label ID="Label2" runat="server" Text="Enter Your Name:"></asp:Label>
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox><br />
<asp:Label ID="Label3" runat="server" Text="Enter Your Class:"></asp:Label>
<asp:TextBox ID="TextBox3" runat="server"></asp:TextBox><br /><br />
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
DataKeyNames="rollno" DataSourceID="SqlDataSource1">
<Columns>
<asp:BoundField DataField="rollno" HeaderText="rollno" ReadOnly="True"
SortExpression="rollno" />
<asp:BoundField DataField="Name" HeaderText="Name"
SortExpression="Name" />
<asp:BoundField DataField="class" HeaderText="class" SortExpression="class"
/>
</Columns>
</asp:GridView><br />
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click"
Text="Insert" />
<asp:Button ID="Button2" runat="server" OnClick="Button2_Click"
Text="Delete" /><br /><br /><br />
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
SelectCommand="SELECT * FROM [student]" DeleteCommand="DELETE
FROM [student] WHERE [rollno] = @rollno" InsertCommand="INSERT INTO
[student] ([rollno], [Name], [class]) VALUES (@rollno, @Name, @class)"
UpdateCommand="UPDATE [student] SET [Name] = @Name, [class] = @class
WHERE [rollno] = @rollno">
<DeleteParameters>
<asp:Parameter Name="rollno" Type="Int32" />
</DeleteParameters>
<InsertParameters>
<asp:Parameter Name="rollno" Type="Int32" />
<asp:Parameter Name="Name" Type="String" />
<asp:Parameter Name="class" Type="String" />
</InsertParameters>
<UpdateParameters>
<asp:Parameter Name="Name" Type="String" />
<asp:Parameter Name="class" Type="String" />
<asp:Parameter Name="rollno" Type="Int32" />
</UpdateParameters></asp:SqlDataSource>
<br /><br />
</div></form>
</body></html>
Design:
Web.config
<?xml version="1.0"?>
<!--
For more information on how to configure your ASP.NET application, please visit
http://go.microsoft.com/fwlink/?LinkId=169433
-->
<configuration>
<connectionStrings>
<add name="ConnectionString" connectionString="Data
Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\Databas
e.mdf;Integrated Security=True"
providerName="System.Data.SqlClient" />
</connectionStrings>
<system.web>
<compilation debug="true" targetFramework="4.5.2" />
<httpRuntime targetFramework="4.5.2" />
</system.web>
</configuration>
Default.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;
using System.Configuration;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string ConnectionString =
ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
SqlConnection con = new SqlConnection(ConnectionString);
SqlCommand cmd = new SqlCommand("Select * from student", con);
con.Open();
SqlDataAdapter adapter = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
adapter.Fill(ds, "student");
}
protected void Button1_Click(object sender, EventArgs e)
{
SqlDataSource1.InsertParameters["rollno"].DefaultValue = TextBox1.Text;
SqlDataSource1.InsertParameters["Name"].DefaultValue = TextBox2.Text;
SqlDataSource1.InsertParameters["class"].DefaultValue = TextBox3.Text;
SqlDataSource1.Insert();
}
protected void Button2_Click(object sender, EventArgs e)
{
SqlDataSource1.DeleteParameters["rollno"].DefaultValue = TextBox1.Text;
SqlDataSource1.Delete();
} }
Output:
Insert: Delete :
b)Create a web application to demonstrate data binding using
DetailsView and FormView Control.
Default.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs"
Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title></title></head>
<body>
<form id="form1" runat="server">
<div align="center">
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
SelectCommand="SELECT * FROM [student]"
ConflictDetection="CompareAllValues" DeleteCommand="DELETE FROM
[student] WHERE [id] = @original_id AND (([name] = @original_name) OR
([name] IS NULL AND @original_name IS NULL))" InsertCommand="INSERT
INTO [student] ([id], [name]) VALUES (@id, @name)"
OldValuesParameterFormatString="original_{0}" UpdateCommand="UPDATE
[student] SET [name] = @name WHERE [id] = @original_id AND (([name] =
@original_name) OR ([name] IS NULL AND @original_name IS NULL))">
<DeleteParameters>
<asp:Parameter Name="original_id" Type="Int32" />
<asp:Parameter Name="original_name" Type="String" />
</DeleteParameters>
<InsertParameters>
<asp:Parameter Name="id" Type="Int32" />
<asp:Parameter Name="name" Type="String" />
</InsertParameters>
<UpdateParameters>
<asp:Parameter Name="name" Type="String" />
<asp:Parameter Name="original_id" Type="Int32" />
<asp:Parameter Name="original_name" Type="String" />
</UpdateParameters>
</asp:SqlDataSource>
<br />
<asp:DetailsView ID="DetailsView1" runat="server" AllowPaging="True"
DataSourceID="SqlDataSource1" Height="50px" Width="125px"
AutoGenerateRows="False" DataKeyNames="id">
<Fields>
<asp:BoundField DataField="id" HeaderText="id" ReadOnly="True"
SortExpression="id" />
<asp:BoundField DataField="name" HeaderText="name" SortExpression="name"
/>
<asp:CommandField ShowDeleteButton="True" ShowEditButton="True"
ShowInsertButton="True" />
</Fields>
</asp:DetailsView><br />
<asp:SqlDataSource ID="SqlDataSource2" runat="server"
ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
SelectCommand="SELECT * FROM [student]"
ConflictDetection="CompareAllValues" DeleteCommand="DELETE FROM
[student] WHERE [id] = @original_id AND (([name] = @original_name) OR
([name] IS NULL AND @original_name IS NULL))" InsertCommand="INSERT
INTO [student] ([id], [name]) VALUES (@id, @name)"
OldValuesParameterFormatString="original_{0}" UpdateCommand="UPDATE
[student] SET [name] = @name WHERE [id] = @original_id AND (([name] =
@original_name) OR ([name] IS NULL AND @original_name IS NULL))">
<DeleteParameters>
<asp:Parameter Name="original_id" Type="Int32" />
<asp:Parameter Name="original_name" Type="String" />
</DeleteParameters>
<InsertParameters>
<asp:Parameter Name="id" Type="Int32" />
<asp:Parameter Name="name" Type="String" />
</InsertParameters>
<UpdateParameters>
<asp:Parameter Name="name" Type="String" />
<asp:Parameter Name="original_id" Type="Int32" />
<asp:Parameter Name="original_name" Type="String" />
</UpdateParameters>
</asp:SqlDataSource><br />
<asp:FormView ID="FormView1" runat="server" AllowPaging="True"
DataSourceID="SqlDataSource2" DataKeyNames="id">
<EditItemTemplate>
id:
<asp:Label ID="idLabel1" runat="server" Text='<%# Eval("id") %>' /><br />
name:
<asp:TextBox ID="nameTextBox" runat="server" Text='<%# Bind("name") %>'
/><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 />
<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='<%# Eval("id") %>' /><br />
name:<asp:Label ID="nameLabel" runat="server" Text='<%# Bind("name") %>'
/><br />
<asp:LinkButton ID="EditButton" runat="server" CausesValidation="False"
CommandName="Edit" Text="Edit" />
<asp:LinkButton ID="DeleteButton" runat="server"
CausesValidation="False" CommandName="Delete" Text="Delete" />
<asp:LinkButton ID="NewButton" runat="server"
CausesValidation="False" CommandName="New" Text="New" />
</ItemTemplate>
</asp:FormView>
</div>
</form>
</body>
</html>
Design.aspx
Default.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 _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{ }}
Output:
c)Create a web application to display Using Disconnected Data
Access and Databinding using GridView.
Default.aspx
i)Default.aspx ii)DataSet.xsd
Default.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 _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{ }
}Output:
Practical No:09
Working with GridView control
a)Create a web application to demonstrate use of GridView control
template and GridView hyperlink.
Default.aspx
<!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:GridView ID="GridView1" runat="server" AllowPaging="True"
AllowSorting="True" AutoGenerateColumns="False" CellPadding="4"
DataKeyNames="First_Name" DataSourceID="SqlDataSource1"
ForeColor="#333333" GridLines="None">
<AlternatingRowStyle BackColor="White" />
<Columns>
<asp:CommandField ShowDeleteButton="True" ShowEditButton="True"
ShowSelectButton="True" />
<asp:BoundField DataField="First_Name" HeaderText="First_Name"
ReadOnly="True" SortExpression="First_Name" />
<asp:BoundField DataField="Last_Name" HeaderText="Last_Name"
SortExpression="Last_Name" />
<asp:BoundField DataField="City" HeaderText="City" SortExpression="City" />
<asp:BoundField DataField="Country" HeaderText="Country"
SortExpression="Country" />
</Columns>
<EditRowStyle BackColor="#2461BF" />
<FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#2461BF" ForeColor="White"
HorizontalAlign="Center" />
<RowStyle BackColor="#EFF3FB" />
<SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True"
ForeColor="#333333" />
<SortedAscendingCellStyle BackColor="#F5F7FB" />
<SortedAscendingHeaderStyle BackColor="#6D95E1" />
<SortedDescendingCellStyle BackColor="#E9EBEF" />
<SortedDescendingHeaderStyle BackColor="#4870BE" />
</asp:GridView>
<br /><br />
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
DeleteCommand="DELETE FROM [student1] WHERE [First_Name] =
@First_Name" InsertCommand="INSERT INTO [student1] ([First_Name],
[Last_Name], [City], [Country]) VALUES (@First_Name, @Last_Name, @City,
@Country)" SelectCommand="SELECT * FROM [student1]"
UpdateCommand="UPDATE [student1] SET [Last_Name] = @Last_Name, [City]
= @City, [Country] = @Country WHERE [First_Name] = @First_Name">
<DeleteParameters>
<asp:Parameter Name="First_Name" Type="String" />
</DeleteParameters>
<InsertParameters>
<asp:Parameter Name="First_Name" Type="String" />
<asp:Parameter Name="Last_Name" Type="String" />
<asp:Parameter Name="City" Type="String" />
<asp:Parameter Name="Country" Type="String" />
</InsertParameters>
<UpdateParameters>
<asp:Parameter Name="Last_Name" Type="String" />
<asp:Parameter Name="City" Type="String" />
<asp:Parameter Name="Country" Type="String" />
<asp:Parameter Name="First_Name" Type="String" />
</UpdateParameters>
</asp:SqlDataSource>
<br />
<br />
</div>
</form>
</body>
</html>
Design.aspx
Database
Code:
CREATE TABLE student1
(First_Name NCHAR(13) PRIMARY KEY,
Last_Name NCHAR(10),
City NCHAR(10),
Country NCHAR(10));
Output:
Update:
Delete:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void GridView1_RowCommand(object sender,
GridViewCommandEventArgs e)
{
if (e.CommandName == "click")
{
Response.Write(e.CommandName);
GridView1.Rows[Convert.ToInt16(e.CommandArgument)].BackColor =
System.Drawing.Color.Blue;
}
}
protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
{
}
}
Output:
c)Create a web application to demonstrate GridView paging and
Creating own table format using GridView.
Default.aspx
<%@ 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 align="center">
<asp:GridView ID="GridView1" runat="server" AllowPaging="True"
AutoGenerateColumns="False" Caption="Student Details" CellPadding="10"
CellSpacing="2" DataSourceID="SqlDataSource2" ForeColor="#333333"
GridLines="None" PageSize="5" Width="172px" DataKeyNames="eid">
<AlternatingRowStyle BackColor="White" ForeColor="#284775" />
<Columns>
<asp:BoundField DataField="eid" HeaderText="eid" SortExpression="eid"
ReadOnly="True" />
<asp:BoundField DataField="ename" HeaderText="ename"
SortExpression="ename" />
<asp:BoundField DataField="eage" HeaderText="eage" SortExpression="eage" />
<asp:BoundField DataField="edesg" HeaderText="edesg" SortExpression="edesg"
/></Columns>
<EditRowStyle BackColor="#999999" />
<FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<PagerSettings FirstPageText="First" LastPageText="Last" NextPageText="Next"
Position="TopAndBottom" PreviousPageText="Previous" />
<PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center"
/>
<RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
<SelectedRowStyle BackColor="#E2DED6" Font-Bold="True"
ForeColor="#333333" />
<SortedAscendingCellStyle BackColor="#E9E7E2" />
<SortedAscendingHeaderStyle BackColor="#506C8C" />
<SortedDescendingCellStyle BackColor="#FFFDF8" />
<SortedDescendingHeaderStyle BackColor="#6F8DAE" />
</asp:GridView>
<br /><br />
<asp:SqlDataSource ID="SqlDataSource2" runat="server"
ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
DeleteCommand="DELETE FROM [employee1] WHERE [eid] = @eid"
InsertCommand="INSERT INTO [employee1] ([eid], [ename], [eage], [edesg])
VALUES (@eid, @ename, @eage, @edesg)" SelectCommand="SELECT *
FROM [employee1]" UpdateCommand="UPDATE [employee1] SET [ename] =
@ename, [eage] = @eage, [edesg] = @edesg WHERE [eid] = @eid">
<DeleteParameters>
<asp:Parameter Name="eid" Type="Int32" />
</DeleteParameters>
<InsertParameters>
<asp:Parameter Name="eid" Type="Int32" />
<asp:Parameter Name="ename" Type="String" />
<asp:Parameter Name="eage" Type="Int32" />
<asp:Parameter Name="edesg" Type="String" />
</InsertParameters>
<UpdateParameters>
<asp:Parameter Name="ename" Type="String" />
<asp:Parameter Name="eage" Type="Int32" />
<asp:Parameter Name="edesg" Type="String" />
<asp:Parameter Name="eid" Type="Int32" />
</UpdateParameters>
</asp:SqlDataSource>
<br /></div>
</form></body>
</html>
Design:
Code:
create table employee1(eid int primary key,ename varchar(20),eage
int,edesg varchar(20));
Database:
Default.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 _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{ }
protected void GridView1_PageIndexChanging(Object
sender,GridViewPageEventArgs e)
{
GridView1.PageIndex = e.NewPageIndex;
}}
Output:
Page 1
Practical No:10
Working with AJAX and XML
a) Create a web application to demonstrate reading and writing
operation with XML.
Default.aspx
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(@"http://localhost:61795/XMLFile.xml");
while (red.Read()) {
if (red.NodeType.Equals(XmlNodeType.Element))
{
string s = Label1.Text + " ";
Label1.Text = s + red.Name;
}}
red.Close();
}
protected void Button2_Click(object sender, EventArgs e)
{
XmlTextWriter textWriter = new
XmlTextWriter("C:\\Users\\Deepak\\Documents\\Visual Studio
2012\\WebSites\\10b\\myXMLFile.xml", null);
textWriter.WriteStartDocument();
textWriter.WriteStartElement("student");
textWriter.WriteStartElement("name", "");
textWriter.WriteString("Suraj");
textWriter.WriteEndElement();
textWriter.WriteStartElement("roll", "");
textWriter.WriteString("29");
textWriter.WriteEndElement();
textWriter.WriteEndDocument();
textWriter.Close(); } }
XML.File
<?xml version="1.0"?><student><name>Suraj</name><roll>29</roll></student>
Output:
b)Create a web application to demonstrate Form Security and
Windows Security with proper Authentication and Authorization
properties.
Default.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs"
Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title></title>
</head><body>
<form id="form1" runat="server">
<div align="center">
<asp:ScriptManager ID="ScriptManager1" runat="server" />
<asp:Timer runat="server" id="UpdateTimer" interval="500"
ontick="UpdateTimer_Tick" />
<asp:UpdatePanel runat="server" id="TimedPanel" updatemode="Conditional">
<Triggers>
<asp:AsyncPostBackTrigger controlid="UpdateTimer" eventname="Tick" />
</Triggers>
<ContentTemplate>
<asp:Label runat="server" id="DateStampLabel" />
</ContentTemplate>
</asp:UpdatePanel><br /><br />
<asp:UpdateProgress runat="server" id="PageUpdateProgress">
<ProgressTemplate>
Loading...
</ProgressTemplate>
</asp:UpdateProgress>
<asp:UpdatePanel runat="server" id="Panel">
<ContentTemplate>
<asp:Button runat="server" id="UpdateButton" onclick="UpdateButton_Click"
text="Update" />
</ContentTemplate>
</asp:UpdatePanel>
</div></form>
</body>
</html>
Design
Default.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 _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{ }
protected void UpdateTimer_Tick(object sender, EventArgs e)
{
DateStampLabel.Text = DateTime.Now.ToString();
}
protected void UpdateButton_Click(object sender, EventArgs e)
{
System.Threading.Thread.Sleep(5000);
} }
Output:
Practical No:11
Programs to create and use DLL
Default.aspx
<%@ 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">
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click"
Text="UpperCase" />
<asp:Button ID="Button2" runat="server" OnClick="Button2_Click"
Text="LowerCase" />
<br />
<div>
&
nbsp;
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
</div>
</form>
</body>
</html>
Design:
Default.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
namespace ASClassLIB
{
public class AS
{
public string UpperConvert(string text)
{
return text.ToUpper();
}
public string LowerConvert(string text)
{
return text.ToLower();
}
}}
Default.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;