Professional Documents
Culture Documents
Awppracticalmanisha
Awppracticalmanisha
Awppracticalmanisha
Roll No:28
Practical 1
1. Working with basic C# and ASP .NET.
a. Create an application that obtains four int values from the user and displays the product.
Code:-
using System;
using System.Collections.Generic; using
System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
Int a=Convert.ToInt32(Console.ReadLine());
Int b=Convert.ToInt32(Console.ReadLine());
Int c=Convert.ToInt32(Console.ReadLine());
Int d=Convert.ToInt32(Console.ReadLine());
Int product=a*b*c*d;
Console.WriteLine(“The product is “+product());
Console.ReadLine();
}
}
}
namespace pract2
{
class Program
{
static void Main(string[] args)
{
string f; string l;
f = "steven clark";
l = "clark";
Console.WriteLine(f.Clone());
Console.WriteLine(f.CompareTo(l));
Console.WriteLine(f.Contains("ven"));
Console.WriteLine(f.EndsWith("n"));
Console.WriteLine(f.Equals(l));
Console.WriteLine(f.GetHashCode());
Console.WriteLine(f.GetType());
Console.WriteLine(f.GetTypeCode());
Console.WriteLine(f.IndexOf("e"));
Console.WriteLine(f.ToLower());
Console.WriteLine(f.ToUpper());
Console.WriteLine(f.Insert(0, "HELLO"));
Console.WriteLine(f.IsNormalized());
Console.WriteLine(f.LastIndexOf("e"));
Console.WriteLine(f.Length);
Console.WriteLine(f.Remove(5));
Console.WriteLine(f.Replace('e', 'i')); string[] split = f.Split(new char[]
{ 'e' });
Console.WriteLine(split[0]);
Console.WriteLine(split[1]);
Console.WriteLine(split[2]);
Console.WriteLine(f.StartsWith("s")); Console.WriteLine(f.Substring(2, 5));
Console.WriteLine(f.ToCharArray());
Console.WriteLine(f.Trim());
Console.ReadKey();
}
}
}
Output:
c. Create an application that receives the (Student Id, Student Name, Course Name, Date of Birth)
information from a set of students. The application should also display the information of all the
students once the data entered.
I. Code:-
using System;
namespace Practical4
{
class Program
{
static void Main(string[] args)
{
int f1 = 0 ,f2=1, f3,n,i=2;
n = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Fibonaaci Series"); Console.WriteLine(f1 + "\t" + f2);
while(i<=n)
{
f3 = f1 + f2;
Console.WriteLine("\n" + f3);
f1 = f2; f2 =
f3; i++;
}
}
}
Output:
2. Code:-
using System;
namespace prome
{
class Program
{
static void Main(string[] args)
{
int num, counter;
Console.Write("Enter number:"); num =
int.Parse(Console.ReadLine());
for (counter = 2; counter <= num / 2; counter++)
{
if ((num % counter) == 0)
break;
}
if (num == 1)
Console.WriteLine(num + "is neither prime nor composite"); else if (counter < (num / 2))
Console.WriteLine(num + "is not prime number"); else
Console.WriteLine(num + "is prime number");
}
}
}
Output:
namespace pracct4vowel
{
class Program
{
static void Main(string[] args)
{
string str; int i, len,
vowel;
Console.Write("Input the string : "); str =
Console.ReadLine();
vowel = 0;
len = str.Length;
if (str[i] == 'a' || str[i] == 'e' || str[i] == 'i' || str[i] == 'o' || str[i] == 'u' || str[i] == 'A' || str[i] ==
'E' || str[i] == 'I' || str[i] == 'O' || str[i] == 'U')
{
vowel++;
}
}
Console.Write("\nThe total number of vowel in the string is :
{0}\n", vowel);
}
}
}
Output:
4. Code:-
using System;
namespace forech
{
class Program
{
static void Main(string[] args)
{
int[] a = { 1, 2, 3, 4, 5 };
foreach(int x in a)
{
Console.WriteLine(x);
}
}
}
}
Output:
5. Code:-
using System;
namespace reerse_sum
{
class Program
{
static void Main(string[] args)
{
int rem ,rev=0, sum = 0, m,n; n=
Convert.ToInt32(Console.ReadLine()); m = n;
while (n>0)
{
rem= n % 10; rev = rev * 10 + rem; sum = sum + rem; n = n / 10;
}
Console.WriteLine("The reverse of"+m+"is"+rev);
Console.WriteLine("The sum of" + m + "is" + sum);
}
}
}
Output:-
namespace factrial
{
class Program
{
static void Main(string[] args)
{
int i, number, fact;
Console.WriteLine("Enter the Number");
number = int.Parse(Console.ReadLine());
fact = number;
for (i = number - 1; i >= 1; i--)
{
fact = fact * i;
}
Console.WriteLine("\nFactorial of Given Number is: " + fact);
Console.ReadLine();
}
}
Output
2. Code:-
using System;
namespace money_conersion
{
class Program
{
static void Main(string[] args)
{
int choice;
Console.WriteLine("Enter your Choice :\n 1- Dollar to Rupee \n 2 - Euro to Rupee \n 3 - Malaysian
Ringgit to Rupee ");
choice = int.Parse(Console.ReadLine());
switch (choice)
{
case 1:
Double dollar, rupee, val;
Console.WriteLine("Enter the Dollar Amount :");
dollar = Double.Parse(Console.ReadLine());
Console.WriteLine("Enter the Dollar Value :");
val = double.Parse(Console.ReadLine());
rupee = dollar * val;
Console.WriteLine("{0} Dollar Equals {1} Rupees", dollar, rupee);
break;
case 2:
Double Euro, rupe, valu;
Console.WriteLine("Enter the Euro Amount :");
Euro = Double.Parse(Console.ReadLine());
Console.WriteLine("Enter the Euro Value :");
valu = double.Parse(Console.ReadLine());
rupe = Euro * valu;
Console.WriteLine("{0} Euro Equals {1} Rupees", Euro, rupe);
break;
case 3:
Double ringit, rup, value;
Console.WriteLine("Enter the Ringgit Amount :");
ringit = Double.Parse(Console.ReadLine());
Console.WriteLine("Enter the Ringgit Value :");
value = double.Parse(Console.ReadLine());
rup = ringit * value;
Console.WriteLine("{0} Malaysian Ringgit Equals {1} Rupees",
ringit, rup);
break;
}
}
}
}
Output:
3. Code :-
using System;
namespace example
{
class Quadraticroots
{
double a, b, c;
class Roots
{
public static void Main()
{
Quadraticroots qr = new Quadraticroots();
qr.read();
qr.compute();
}
}
}
Output:
4 Code:-
using System;
namespace Temprature_Conversion
{
class Program
{
static void Main(string[] args)
{
double f, c;
Console.WriteLine("Enter the value of Celsius:");
c = Convert.ToDouble(Console.ReadLine());
f = c* 9 / 5 + 32;
Console.WriteLine(c + "°C in Fahrenheit is: " + f + "°F");
Console.WriteLine("Enter the value of Fahrenheit:");
f = Convert.ToDouble(Console.ReadLine());
c = (f - 32) * 5 / 9;
Console.WriteLine(f + "°F in Celsius is: " + c + "°C");
Console.ReadLine();
}
}
}
Output:
b. Create a simple application to demonstrate use of following concepts i. Function Overloading ii.
Inheritance (all types) iii. Constructor overloading iv. Interfaces
1.Code:-
using System;
namespace funtion_overloadinh
{
class Program
{
class Add
{
static void add(int x)
{
Console.WriteLine("X= " + (x + x));
}
static void add(int x, int y)
{
Console.WriteLine("X+Y=" + (x + y));
}
static void add(int x, int y, int z)
{
Console.WriteLine("X+Y+Z=" + (x + y + z));
}
}
}
Output:
namespace Single_inhertience
{
class Program
{
static void Main(string[] args)
{
Father f = new Father();
f.Display();
// Son class
Son s = new Son();
s.Display();
s.DisplayOne();
Console.ReadKey();
}
class Father
{
public void Display()
{
Console.WriteLine("This is base class");
}
}
class Son : Father
{
public void DisplayOne()
{
Console.WriteLine("This is derived class");
}
}
}
}
Output :
namespace Mutlevel_inheri
{
class Program
{
static void Main(string[] args)
{
A s = new A();
s.Display();
s.DisplayOne();
s.DisplayTwo();
Console.Read();
}
}
class A : B
{
public void DisplayTwo()
{
Console.WriteLine("A.. ");
}
}
class C
{
public void Display()
{
Console.WriteLine("C...");
}
}
class B : C
{
public void DisplayOne()
{
Console.WriteLine("B...");
}
}
}
Output:
namespace Hirarichal_inheri
{
class Program
{
static void Main(string[] args)
{
A f = new A();
f.display();
B s = new B();
s.display();
s.displayOne();
C d = new C();
d.displayTwo();
Console.ReadKey();
}
}
class A
{
public void display()
{
Console.WriteLine("A");
}
}
class B : A
{
public void displayOne()
{
Console.WriteLine("B");
}
}
class C : A
{
public void displayTwo()
{
Console.WriteLine("C");
}
}
}
Output:
3.Code:
using System;
class ADD
{
int x, y;
int f, p, s;
class GFG
{
g.show();
q.show1();
}
}
Output :-
3. Create a simple application to demonstrate use of following concepts i. Using Delegates and events ii.
Exception handling.
• Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Delegates_demo
{
public delegate int Mydelegate(int x, int y);
class sample
{
public static int rectangle(int a, int b)
{
return a * b;
}
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Delegate Program");
Mydelegate mdl = new Mydelegate(sample.rectangle);
Console.WriteLine("The Area of rectangle is {0}", mdl(4, 5));
Console.ReadKey();
}
}
}
Output :
2.Code:-
using System;
namespace ErrorHandlingApplication {
class DivNumbers {
int result;
DivNumbers() {
result = 0;
}
public void division(int num1, int num2) {
try {
result = num1 / num2;
} catch (DivideByZeroException e) {
Console.WriteLine("Exception caught: {0}", e);
} finally {
Console.WriteLine("Result: {0}", result);
}
}
static void Main(string[] args) {
DivNumbers d = new DivNumbers();
d.division(25, 0);
Console.ReadKey();
}
}
}
Output:-
a. Create a simple web page with various server controls to demonstrate setting and use of their
properties. (Example : AutoPostBack) .
Code :-
"WebForm1.aspx:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs"
Inherits="autopostback.WebForm1" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<center> AutoPost Back </center>
<asp:ListBox ID="ListBox1" runat="server" AutoPostBack="True"
OnSelectedIndexChanged="ListBox1_SelectedIndexChanged">
<asp:ListItem>Red</asp:ListItem>
<asp:ListItem>Blue</asp:ListItem>
<asp:ListItem>Green</asp:ListItem>
</asp:ListBox>
<br />
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
</div>
</form>
</body>
</html>
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 autopostback
{
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Output:
b. Demonstrate the use of Calendar control to perform following operations. a) Display messages in a
calendar control b) Display vacation in a calendar control c) Selected day in a calendar control using style
d) Difference between two calendar dates.
Code:-
Webform.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs"
Inherits="_3B_calendra.WebForm1" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<asp:Calendar ID="Calendar1" runat="server" BackColor="#FFFFCC" BorderColor="#FFCC66"
BorderWidth="1px" DayNameFormat="Shortest" Font-Names="Verdana" Font-Size="8pt"
ForeColor="#663399" Height="200px" OnDayRender="Calendar1_DayRender"
OnSelectionChanged="Calendar1_SelectionChanged1" ShowGridLines="True" Width="220px">
<DayHeaderStyle BackColor="#FFCC66" Font-Bold="True" Height="1px" />
<NextPrevStyle Font-Size="9pt" ForeColor="#FFFFCC" />
<OtherMonthDayStyle ForeColor="#CC9966" />
<SelectedDayStyle BackColor="#CCCCFF" Font-Bold="True" />
<SelectorStyle BackColor="#FFCC66" />
<TitleStyle BackColor="#990000" Font-Bold="True" Font-Size="9pt" ForeColor="#FFFFCC" />
<TodayDayStyle BackColor="#FFCC66" ForeColor="White" />
</asp:Calendar>
<asp:Label ID="Label2" runat="server" Text="Label"></asp:Label>
<br />
<asp:Label ID="Label3" runat="server" Text="Label"></asp:Label>
<br />
<asp:Label ID="Label4" runat="server" Text="Label"></asp:Label>
<br />
<asp:Calendar ID="Calendar2" runat="server"></asp:Calendar>
<br />
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Submit" />
<br />
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
</form>
</body>
</html>
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 _3B_calendra
{
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Output:
c. Demonstrate the use of Treeview control perform following operations. 25 a) Treeview control and
datalist b) Treeview operations.
Code:
Default2.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default2.aspx.cs"
Inherits="_3b._default" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<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="~/Home.aspx">
</asp:TreeNode>
<asp:TreeNode Text = "Constructor Overloading" Value = "GREEN"
NavigateUrl="~/Home.aspx"></asp:TreeNode>
<asp:TreeNode NavigateUrl="~/Home.aspx" Text="Inheritance"
Value="BLUE"></asp:TreeNode>
<asp:TreeNode NavigateUrl="~/~/Home.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>
</form>
</body>
</html>
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.cs
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace _3b
{
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();
}
}
}
}
Home.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Home.aspx.cs" Inherits="_3b.Home"
%>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<h1>This is home Page</h1>
</form>
</body>
</html>
Output:
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<style
type="text/css"> .auto-
style1 { width: 72%;
background-color: #C0C0C0;
}
.auto-style2
{ width: 357px;
text-align: right;
}
.auto-style3
{ width: 357px;
text-align: right;
height: 30px;
}
.auto-style4
{ height: 30px;
width: 445px;
}
.auto-style5 {
width: 445px;
}
.auto-style6
{ width: 357px;
text-align: right;
height: 21px;
}
.auto-style7
{ width: 445px;
height: 21px;
}
</style>
</head>
<body>
<center> Registration form with validation</center>
<form id="form1" runat="server">
</form>
</body>
</html>
Webform.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 CustomValidator1_ServerValidate1(object source,
ServerValidateEventArgs args)
{
}
}
}
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:AdRotator ID="AdRotator1" runat="server" Target="_blank"
AdvertisementFile="~/ADdata.xml" OnAdCreated="AdRotator1_AdCreated" />
</div>
</form>
</body>
</html>
<%-- --%>
ADdata.xml
<?xml version="1.0" encoding="utf-8" ?>
<Advertisements>
<Ad>
<ImageUrl>~/Images/insta.png</ImageUrl>
<NavigateUrl>https://www.arcgis.com/apps/opsdashboard/index.html#/bda7594740f
d40299423467b48e9ecf6</NavigateUrl>
<AlternateText>Please visit https://www.instagram.com</AlternateText>
<Impressions>30</Impressions>
<Keyword>Instagram</Keyword>
</Ad>
<Ad>
<ImageUrl>~/Images/you.png</ImageUrl>
<NavigateUrl>https://www.youtube.com/</NavigateUrl>
<AlternateText>Please visit https://www.youtube.com</AlternateText>
<Impressions>20</Impressions>
<Keyword>Youtube</Keyword>
</Ad>
</Advertisements>
Output:
<table class="auto-style2">
<tr>
<td class="auto-style5">Username</td>
<td class="auto-style3">
<asp:TextBox ID="usertxt" runat="server" Width="143px"
OnTextChanged="usertxt_TextChanged" ValidationGroup="lv" CssClass="autostyle4"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server"
ControlToValidate="usertxt" ForeColor="Red"
ValidationGroup="lv">*</asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td class="auto-style5">Password</td>
<td class="auto-style3">
<asp:TextBox ID="passtxt" runat="server" Width="143px"
ValidationGroup="lv"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server"
ControlToValidate="passtxt" ForeColor="Red"
ValidationGroup="lv">*</asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td class="auto-style5"></td>
<td class="auto-style3">
<asp:Button ID="Button1" runat="server" Text="Login" Width="65px" ValidationGroup="lv" />
</td>
</tr>
</table>
register.ascx
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="register.ascx.cs"
Inherits="_4C.MyCntrl.WebUserControl1" %>
<style type="text/css">
.auto-style6 {
width: 107px;
}
.auto-style5 { width:
109px;
}
</style>
<table style="width:100%;">
<tr>
<td class="auto-style6">Username</td>
<td>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td class="auto-style6">Password</td>
<td>
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td class="auto-style6">Renter-Password</td>
<td>
<asp:TextBox ID="TextBox3" runat="server"></asp:TextBox>
</td>
</tr>
</table>
<table style="width:100%;">
<tr>
<td class="auto-style6">Email</td>
<td>
<asp:TextBox ID="TextBox4" runat="server"></asp:TextBox>
</td>
</tr>
</table>
<table style="width:100%;">
<tr>
<td class="auto-style5"> </td>
<td>
<asp:Button ID="Button1" runat="server" Text="Register" Width="77px" />
</td>
</tr>
</table>
WebForm1.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs"
Inherits="_4C.WebForm1" %>
<!DOCTYPE html>
<script runat="server">
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<uc1:login ID="login1" runat="server" />
</div>
<uc2:register ID="register1" runat="server" />
</form>
</body>
</html>
Output:
a. Create Web Form to demonstrate use of Website Navigation controls and Site Map.
Code:
Webform1.aspx:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs"
Inherits="_5a.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:SiteMapPath ID="SiteMapPath1" runat="server">
</asp:SiteMapPath>
<br />
<br />
<asp:Menu ID="Menu1" runat="server" DataSourceID="SiteMapDataSource1">
</asp:Menu>
<br />
<asp:SiteMapDataSource ID="SiteMapDataSource1" runat="server" />
</div>
</form>
</body>
</html>
Webform2.aspx:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm2.aspx.cs"
Inherits="_5a.WebForm2" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:SiteMapPath ID="SiteMapPath1" runat="server">
</asp:SiteMapPath><br/>
Welcome to Online Store
</div>
</form>
</body>
</html>
Webform.aspx:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm2.aspx.cs"
Inherits="_5a.WebForm2" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:SiteMapPath ID="SiteMapPath1" runat="server">
</asp:SiteMapPath><br/>
Welcome to Online Store
</div>
</form>
</body>
</html>
Webform3.aspx:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm3.aspx.cs"
Inherits="_5a.WebForm3" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:SiteMapPath ID="SiteMapPath1" runat="server">
</asp:SiteMapPath><br/>
Hii Welcome to online shopping : Mobiles
</div>
</form>
</body>
</html>
Output
:
b. Create a web application to demonstrate use of Master Page with applying Styles and Themes for
page beautification.
Code:
MasterPage.Master:
<%@ Master Language="C#" AutoEventWireup="true" CodeBehind="MasterPage.master.cs"
Inherits="Masterpage5a.MasterPage" %>
<!DOCTYPE html>
<html>
<head runat="server">
<title>Master Page Demo</title>
<link href="StyleSheet1.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="Hello.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>
</aside>
<div id="con">
<asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server">
</asp:ContentPlaceHolder>
</div>
<footer id="footer">
copyright @MyWorld
</footer>
</body>
</html>
</form>
</body>
</html>
StyleSheet1.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;
}
Hello.aspx:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Hello.aspx.cs"
Inherits="Masterpage5a.WebForm1" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<h1>Hello World</h1>
</form>
</body>
</html>
Home.aspx:
<%@ Page Title="" Language="C#" MasterPageFile="~/MasterPage.Master" AutoEventWireup="true"
CodeBehind="Home.aspx.cs" Inherits="Masterpage5a.Home" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server"><h1>Home
page</h1>
</asp:Content>
Output:
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:HiddenField ID="HiddenField1" runat="server" Value="2" />
<br />
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
<br />
<br />
<asp:Label ID="Label2" runat="server" Text="Label"></asp:Label>
<br />
<br />
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="View State" />
<br />
<br />
<asp:Button ID="Button2" runat="server" OnClick="Button2_Click" Text="Hidden Feild" />
<br />
<br />
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<br />
<br />
<asp:Button ID="Button3" runat="server" OnClick="Button3_Click" Text="Cookies" />
</div>
</form>
</body>
</html>
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 _5c
{
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if(IsPostBack)
{
if(ViewState["count"] != null)
{
int ViewStateVal = Convert.ToInt32(ViewState["count"]) + 1;
Label2.Text = "View State:" + ViewStateVal.ToString();
ViewState["count"] = ViewStateVal.ToString();
}
else
{
ViewState["count"] = "1";
}
}
}
<!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>
WebForm2.aspx.cs:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm2.aspx.cs"
Inherits="_5c.WebForm2" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
</div>
</form>
</body>
</html>
Output:
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:TextBox ID="TextBox1" Text="<%#textdata %>" runat="server"
Height="121px" TextMode="MultiLine" Width="266px" CausesValidation="False"
OnTextChanged="TextBox1_TextChanged" ></asp:TextBox>
<asp:TextBox ID="TextBox2" runat="server" AutoPostBack="True"
OnTextChanged="TextBox2_TextChanged"></asp:TextBox>
</div>
</form>
</body>
</html>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace WebApplication8
{
public partial class bindtext : System.Web.UI.Page
{
public string textdata;
protected void Page_Load(object sender, EventArgs e)
{
}
}
}
Output:
+
b. Create a web application to display records by using database.
Code:
WebForm1.aspx:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs"
Inherits="_6b.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:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<br />
<br />
<asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" />
<br />
<br />
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
</div>
</form>
</body>
</html>
WebForm1.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;
namespace _6b
{
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
Output:
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<style type="text/css">
.auto-style1 {
color: #800000;
font-size: x-large;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$
ConnectionStrings:EmployeeConnectionString %>" SelectCommand="SELECT * FROM
[empRegister]"></asp:SqlDataSource>
<h1><strong><span class="auto-style1"> DataList </span>
<br class="auto-style1" />
</strong></h1>
<asp:DataList ID="DataList1" runat="server" DataKeyField="UserID"
DataSourceID="SqlDataSource1">
<ItemTemplate>
First Name:
<asp:Label ID="First_NameLabel" runat="server" Text='<%# Eval("[First Name]") %>' />
<br />
Last Name:
<asp:Label ID="Last_NameLabel" runat="server" Text='<%# Eval("[Last Name]") %>' />
<br />
UserID:
<asp:Label ID="UserIDLabel" runat="server" Text='<%# Eval("UserID") %>' />
<br />
EmailId:
<asp:Label ID="EmailIdLabel" runat="server" Text='<%# Eval("EmailId") %>' />
<br />
Paasword:
<asp:Label ID="PaaswordLabel" runat="server" Text='<%# Eval("Paasword") %>' />
<br />
Mobile No:
<asp:Label ID="Mobile_NoLabel" runat="server" Text='<%# Eval("[Mobile No]") %>' />
<br />
Address:
<asp:Label ID="AddressLabel" runat="server" Text='<%# Eval("Address") %>' />
<br />
<br />
</ItemTemplate>
</asp:DataList>
</div>
</form>
</body>
</html>
Output:
namespace prac7a
{
public partial class example : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
DataSet studs = new DataSet();
studs.Tables.Add(new DataTable("student"));
studs.Tables["student"].Columns.Add(new DataColumn("rollno"));
studs.Tables["student"].Columns.Add(new DataColumn("name"));
studs.Tables["student"].Columns.Add(new DataColumn("class"));
studs.Tables["student"].Columns.Add(new DataColumn("phone"));
studs.Tables["student"].Columns.Add(new DataColumn("email"));
DataRow dr = studs.Tables["student"].NewRow();
dr["rollno"] = "1";
dr[1] = "Sam";
dr[2] = "it";
dr[3] = "6523236521";
dr[4] = "vhv@gmail.com";
studs.Tables["student"].Rows.Add(dr);
dr = studs.Tables["student"].NewRow();
dr["rollno"] = "2";
dr[1] = "Tam";
dr[2] = "it";
dr[3] = "65235323212";
dr[4] = "mnm@gmail.com";
studs.Tables["student"].Rows.Add(dr);
GridView1.DataSource = studs.Tables["student"];
GridView1.DataBind();
DropDownList1.DataSource = studs.Tables["student"];
DropDownList1.DataTextField = "name";
DropDownList1.DataValueField = "rollno";
DropDownList1.DataBind();
}
}
}
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:GridView ID="GridView1" runat="server">
</asp:GridView>
<asp:DropDownList ID="DropDownList1" runat="server">
</asp:DropDownList>
<br />
</div>
</form>
</body>
</html>
Output:
b. Create a web application for to display the phone no of an author using database.
Code:
WebForm1.aspx:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs"
Inherits="__7a.WebForm1" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
</div>
</form>
</body>
</html>
WebForm1.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;
namespace __7a
{
public partial class WebForm1 : System.Web.UI.Page
{
string conn =
ConfigurationManager.ConnectionStrings["EmployeeConnectionString2"].ConnectionString;
protected void Page_Load(object sender, EventArgs e)
{
Output:
c. Create a web application for inserting and deleting record from a database. (Using Execute-Non Query)
Code :
WebForm1.aspx:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs"
Inherits="DataBase.WebForm1" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<table>
<tr>
<td>
<asp:Label ID="Label2" runat="server" Text="Id"></asp:Label>
</td>
<td colspan="2">
<asp:TextBox ID="txtId" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td>
<asp:Label ID="Label1" runat="server" Text="Name"></asp:Label>
</td>
<td colspan="2">
<asp:TextBox ID="txtname" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td>
<asp:Label ID="Label3" runat="server" Text="EmailD"></asp:Label>
</td>
<td colspan="2">
<asp:TextBox ID="txtmail" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td>
<asp:Label ID="Label4" runat="server" Text="Password"></asp:Label>
</td>
<td colspan="2">
<asp:TextBox ID="txtpass" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td>
</td>
<td colspan="2">
<asp:Button ID="btnsave" runat="server" Text="Insert" OnClick="btnsave_Click" />
<asp:Button ID="delete" runat="server" Text="Delete" OnClick="Delete_Click" />
<asp:Button ID="btnclear" runat="server" Text="Update" OnClick="btnclear_Click" />
</td>
</tr>
<tr>
<td>
</td>
<td colspan="2">
<asp:Label ID="lblSuccessmessage" runat="server" Text="Label"
ForeColor="#009900"></asp:Label>
</td>
</tr>
<tr>
<td>
</td>
<td colspan="2">
</td>
</tr>
</table>
<br />
<br />
<asp:GridView ID="GridView2" runat="server" AutoGenerateColumns="False"
DataKeyNames="Id" DataSourceID="SqlDataSource2">
<Columns>
<asp:BoundField DataField="Id" HeaderText="Id" ReadOnly="True" SortExpression="Id" />
<asp:BoundField DataField="Name" HeaderText="Name" SortExpression="Name" />
<asp:BoundField DataField="Email" HeaderText="Email" SortExpression="Email" />
<asp:BoundField DataField="Password" HeaderText="Password"
SortExpression="Password" />
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$
ConnectionStrings:StudentConnectionString2 %>" SelectCommand="SELECT * FROM
[st_info]"></asp:SqlDataSource>
<br />
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$
ConnectionStrings:StudentConnectionString %>" SelectCommand="SELECT * FROM
[st_info]"></asp:SqlDataSource>
</div>
</form>
</body>
</html>
WebForm1.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;
namespace DataBase
{
public partial class WebForm1 : System.Web.UI.Page
{
string conn =
ConfigurationManager.ConnectionStrings["StudentConnectionString"].ConnectionString;
protected void Page_Load(object sender, EventArgs e)
{
}
public void Binds()
{
SqlConnection con = new SqlConnection(conn);
con.Open();
SqlCommand cmd = new SqlCommand("select * from st_info ", con);
SqlDataReader rd = cmd.ExecuteReader();
GridView2.DataSource = rd;
GridView2.DataBind();
lblSuccessmessage.Text = "Record Found";
con.Close();
try
{
added = cmd.ExecuteNonQuery();
lblSuccessmessage.Text = added+"Record Inserted Successfully";
}
catch(Exception e1)
{
lblSuccessmessage.Text = e1.Message;
}
if(added<0)
{
Binds();
con.Close();
}
txtId.Text = " ";
txtname.Text = " ";
txtmail.Text = " ";
txtpass.Text = " ";
}
catch (Exception e1)
{
lblSuccessmessage.Text = e1.Message;
}
if (added < 0)
{
Binds();
con.Close();
}
txtId.Text = " ";
txtname.Text = " ";
txtmail.Text = " ";
txtpass.Text = " ";
}
}
Output:
8. Working with data control
a. Create a web application to demonstrate various uses and properties of SqlDataSource.
Code:
webform2.aspx:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm2.aspx.cs"
Inherits="_8a.WebForm2" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$
ConnectionStrings:EmployeeConnectionString %> "
SelectCommand="SELECt * FROM empRegister"
UpdateCommand="Update empRegister SET
First_Name=@First_Name,Last_Name=@Last_Name,EmailId=@EmailId,Mobile=@Mobile ,Address=@A
ddress WHERE UserID=@UserID">
</asp:SqlDataSource>
<br />
</div>
<asp:GridView ID="GridView1" runat="server" AllowSorting="True" AutoGenerateColumns="False"
AutoGenerateEditButton="True" AutoGenerateSelectButton="True" CellPadding="4"
DataKeyNames="UserID" DataSourceID="SqlDataSource1" ForeColor="#333333" GridLines="None"
AllowPaging="True">
<AlternatingRowStyle BackColor="White" ForeColor="#284775" />
<Columns>
<asp:BoundField DataField="First_Name" HeaderText="First_Name"
SortExpression="First_Name" />
<asp:BoundField DataField="Last_Name" HeaderText="Last_Name"
SortExpression="Last_Name" />
<asp:BoundField DataField="UserID" HeaderText="UserID" ReadOnly="True"
SortExpression="UserID" />
<asp:BoundField DataField="EmailId" HeaderText="EmailId" SortExpression="EmailId" />
<asp:BoundField DataField="Paasword" HeaderText="Paasword" SortExpression="Paasword" />
<asp:BoundField DataField="Mobile" HeaderText="Mobile" SortExpression="Mobile" />
<asp:BoundField DataField="Address" HeaderText="Address" SortExpression="Address" />
</Columns>
<EditRowStyle BackColor="#999999" />
<FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<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>
</form>
</body>
</html>
Output:
After Updating:
b. Create a web application to demonstrate data binding using DetailsView and FormView Control.
Code:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs"
Inherits="_8a.WebForm1" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<asp:DetailsView ID="DetailsView1" runat="server" AllowPaging="True" AutoGenerateRows="False"
BackColor="#DEBA84" BorderColor="#DEBA84" BorderStyle="None" BorderWidth="1px"
CellPadding="3" CellSpacing="2" DataKeyNames="Id" DataSourceID="SqlDataSource1" Height="50px"
Width="125px">
<EditRowStyle BackColor="#738A9C" Font-Bold="True" ForeColor="White" />
<Fields>
<asp:BoundField DataField="Id" HeaderText="Id" ReadOnly="True" SortExpression="Id" />
<asp:BoundField DataField="Name" HeaderText="Name" SortExpression="Name" />
<asp:BoundField DataField="Email" HeaderText="Email" SortExpression="Email" />
<asp:BoundField DataField="Password" HeaderText="Password" SortExpression="Password" />
</Fields>
<FooterStyle BackColor="#F7DFB5" ForeColor="#8C4510" />
<HeaderStyle BackColor="#A55129" Font-Bold="True" ForeColor="White" />
<PagerStyle ForeColor="#8C4510" HorizontalAlign="Center" />
<RowStyle BackColor="#FFF7E7" ForeColor="#8C4510" />
</asp:DetailsView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$
ConnectionStrings:StudentConnectionString2 %>" SelectCommand="SELECT * FROM
[st_info]"></asp:SqlDataSource>
</form>
</body>
</html>
Output:
c. Create a web application to display Using Disconnected Data Access and Databinding using GridView.
Code:
Webform2.aspx:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm2.aspx.cs"
Inherits="__7a.WebForm2" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:DropDownList ID="DropDownList1" runat="server" DataSourceID="SqlDataSource1"
DataTextField="First_Name" DataValueField="UserID">
</asp:DropDownList>
<br />
<br />
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Click" />
<br />
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$
ConnectionStrings:EmployeeConnectionString %>" SelectCommand="SELECT * FROM
[empRegister]"></asp:SqlDataSource>
<br />
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
<br />
<asp:GridView ID="GridView1" runat="server" CellPadding="4" ForeColor="#333333"
GridLines="None">
<AlternatingRowStyle BackColor="White" />
<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>
</div>
</form>
</body>
</html>
Webform2.aspx.cs:
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace __7a
{
public partial class WebForm2 : System.Web.UI.Page
{
string conn =
ConfigurationManager.ConnectionStrings["EmployeeConnectionString"].ConnectionString;
Practical No10
9.Working With Practical
Code:
webform1.aspx:
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<div>
<br />
Study Material :<br />
<Columns>
<EditItemTemplate>
</EditItemTemplate>
<ItemTemplate>
</ItemTemplate>
</asp:TemplateField>
</asp:HyperLinkField>
</Columns>
</asp:GridView>
<br />
<br />
</div>
</form>
</body>
</html>
Output:
b.Create a web application to demonstrate use of GridView button column and GridView
events.
Code:
Webform2.aspx:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs"
Inherits="_9a.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:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
BackColor="White" BorderColor="#999999" BorderStyle="None" BorderWidth="1px"
CellPadding="3" DataKeyNames="UserID" DataSourceID="SqlDataSource1"
GridLines="Vertical">
<AlternatingRowStyle BackColor="#DCDCDC" />
<Columns>
<asp:BoundField DataField="First_Name" HeaderText="First_Name"
SortExpression="First_Name" />
<asp:BoundField DataField="Last_Name" HeaderText="Last_Name"
SortExpression="Last_Name" />
<asp:BoundField DataField="UserID" HeaderText="UserID" ReadOnly="True"
SortExpression="UserID" />
<asp:BoundField DataField="EmailId" HeaderText="EmailId"
SortExpression="EmailId" />
<asp:BoundField DataField="Paasword" HeaderText="Paasword"
SortExpression="Paasword" />
<asp:BoundField DataField="Mobile" HeaderText="Mobile"
SortExpression="Mobile" />
<asp:BoundField DataField="Address" HeaderText="Address"
SortExpression="Address" />
</Columns>
<FooterStyle BackColor="#CCCCCC" ForeColor="Black" />
<HeaderStyle BackColor="#000084" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#999999" ForeColor="Black" HorizontalAlign="Center" />
<RowStyle BackColor="#EEEEEE" ForeColor="Black" />
<SelectedRowStyle BackColor="#008A8C" Font-Bold="True" ForeColor="White" />
<SortedAscendingCellStyle BackColor="#F1F1F1" />
<SortedAscendingHeaderStyle BackColor="#0000A9" />
<SortedDescendingCellStyle BackColor="#CAC9C9" />
<SortedDescendingHeaderStyle BackColor="#000065" />
</asp:GridView>
<br />
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$
ConnectionStrings:EmployeeConnectionString2 %>" SelectCommand="SELECT * FROM
[empRegister]"></asp:SqlDataSource>
</div>
</form>
</body>
</html>
webform.aspx.cs:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace _9a
{
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "b1")
{
Response.Write(e.CommandName);
GridView1.SelectedRowStyle.BackColor = System.Drawing.Color.Brown;
GridView1.Rows[Convert.ToInt16(e.CommandArgument)].BackColor =
System.Drawing.Color.Blue;
}
}
} }
Output:
c. Create a web application to demonstrate GridView paging and Creating own table
format using GridView.
Code:
paging.aspx:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="paging.aspx.cs"
Inherits="_9a.paging" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<style type="text/css">
.auto-style1 {
width: 100%;
border-collapse: collapse;
border-left-style: solid;
border-left-width: 2px;
border-right: 2px solid #C0C0C0;
border-top-style: solid;
border-top-width: 2px;
border-bottom: 2px solid #C0C0C0;
background-color: #FFFF00;
}
.auto-style2 {
width: 465px;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div>
<center>
<table class="auto-style1">
<tr>
<td style="font-size:x-large;font-weight:bold; background-color:#C0C0C0"
class="auto-style2"> Paging In GridView </td>
</tr>
<tr>
<td class="auto-style2" style="background-color: #FFFFFF">
<asp:GridView ID="GridView1" runat="server" AllowPaging="True"
AllowSorting="True" AutoGenerateColumns="False" CellPadding="4" DataKeyNames="UserID"
DataSourceID="SqlDataSource1" ForeColor="#333333" GridLines="None">
<AlternatingRowStyle BackColor="White" />
<Columns>
<asp:CommandField ShowSelectButton="True" />
<asp:BoundField DataField="First_Name" HeaderText="First_Name"
SortExpression="First_Name" />
<asp:BoundField DataField="Last_Name" HeaderText="Last_Name"
SortExpression="Last_Name" />
<asp:BoundField DataField="UserID" HeaderText="UserID"
ReadOnly="True" SortExpression="UserID" />
<asp:BoundField DataField="EmailId" HeaderText="EmailId"
SortExpression="EmailId" />
<asp:BoundField DataField="Paasword" HeaderText="Paasword"
SortExpression="Paasword" />
<asp:BoundField DataField="Mobile" HeaderText="Mobile"
SortExpression="Mobile" />
<asp:BoundField DataField="Address" HeaderText="Address"
SortExpression="Address" />
</Columns>
<FooterStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#FFCC66" ForeColor="#333333"
HorizontalAlign="Center" />
<RowStyle BackColor="#FFFBD6" ForeColor="#333333" />
<SelectedRowStyle BackColor="#FFCC66" Font-Bold="True"
ForeColor="Navy" />
<SortedAscendingCellStyle BackColor="#FDF5AC" />
<SortedAscendingHeaderStyle BackColor="#4D0000" />
<SortedDescendingCellStyle BackColor="#FCF6C0" />
<SortedDescendingHeaderStyle BackColor="#820000" />
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<
%$ ConnectionStrings:EmployeeConnectionString5 %>"
ProviderName="System.Data.SqlClient" SelectCommand="SELECT * FROM
[empRegister]"></asp:SqlDataSource>
</td>
</tr>
</table>
</div>
</form>
</body>
</html>
Output: