Final Awp
Final Awp
N COLLEGE
PRACTICAL 1
Aim: Working with basic C# and ASP .NET
A: Create an application that obtains four int values from the user and displays the product.
INPUT:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace pract1_a {
class Product{
static void Main(string[] args) {
int a, b, c, d, product;
Console.WriteLine("Enter four integers");
a = Convert.ToInt32(Console.ReadLine());
b = Convert.ToInt32(Console.ReadLine());
c = Convert.ToInt32(Console.ReadLine());
d = Convert.ToInt32(Console.ReadLine());
product = a * b * c * d;
Console.WriteLine("Product="+product);
Console.ReadKey();
}
}
}
OUTPUT:
1
AWP JOURNAL B.N.N COLLEGE
Design:
WebForm1.aspx:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs"
Inherits="PPrac2.WebForm1" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<body><form id="form1" runat="server"><div>
<asp:Label ID="Label1" runat="server" Text="Enter String: "></asp:Label>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox><br /><br />
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Result:" />
<asp:Button ID="Button2" runat="server" OnClick="Button2_Click" Text="Reset:" /><br /><br />
<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:Label ID="Label5" runat="server" Text="Label"></asp:Label><br />
<asp:Label ID="Label6" runat="server" Text="Label"></asp:Label><br />
<asp:Label ID="Label7" runat="server" Text="Label"></asp:Label><br />
<asp:Label ID="Label8" runat="server" Text="Label"></asp:Label><br />
<asp:Label ID="Label9" runat="server" Text="Label"></asp:Label><br />
<asp:Label ID="Label10" runat="server" Text="Label"></asp:Label><br />
<asp:Label ID="Label11" 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 PPrac2{
public partial class WebForm1 : System.Web.UI.Page{
protected void Page_Load(object sender, EventArgs e){
}
2
AWP JOURNAL B.N.N COLLEGE
OUTPUT:
3
AWP JOURNAL B.N.N COLLEGE
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.
INPUT:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace student{
class Program
{
struct stud
{
public String stud_name, stud_id, c_name; public int date, month, year;}
static void Main(string[] args)
{
stud[] s = new stud[5];
for (int i = 0; i < 5; i++)
{
Console.WriteLine("Enter student id");
s[i].stud_id = Console.ReadLine();
Console.WriteLine("Enter student name");
s[i].stud_name = Console.ReadLine();
Console.WriteLine("Enter course name");
s[i].c_name = Console.ReadLine();
Console.WriteLine("Enter date of birth \n Enter the date(1- 31)");
s[i].date = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Enter the month(1-12)");
s[i].month = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Enter the year");
s[i].year = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Enter student list:");
}
for (int i = 0; i < 5; i++){
Console.WriteLine("Student ID=" + s[i].stud_id);
Console.WriteLine("Student name=" + s[i].stud_name);
Console.WriteLine("Course name=" + s[i].c_name);
Console.WriteLine("Birth date=" + s[i].date + "-" + s[i].month + "-" + s[i].year);
}
Console.ReadKey();
}
}
}
4
AWP JOURNAL B.N.N COLLEGE
OUTPUT:
5
AWP JOURNAL B.N.N COLLEGE
OUTPUT:
break;
case 'U': Console.WriteLine(ch + " is a vowel");
break;
default:Console.WriteLine(ch + " is not a vowel");
break;
}
Console.ReadKey();
}}}
OUTPUT:
9
AWP JOURNAL B.N.N COLLEGE
PRACTICAL 2
m = 3;
else
m = 4;
switch (m){
case 1: Console.WriteLine("\n Not a Quadratic equation, Linear equation");
Console.ReadLine();
break;
case 2: Console.WriteLine("\n Roots are Real and Distinct");
r1 = (-b + Math.Sqrt(d1)) / (2 * a);
r2 = (-b - Math.Sqrt(d1)) / (2 * a);
Console.WriteLine("\n First root is {0:#.##}", r1);
Console.WriteLine("\n Second root is {0:#.##}", r2);
Console.ReadLine();
break;
case 3: Console.WriteLine("\n Roots are Real and Equal");
r1 = r2 = (-b) / (2 * a);
Console.WriteLine("\n First root is {0:#.##}", r1);
Console.WriteLine("\n Second root is {0:#.##}", r2);
Console.ReadLine();
break;
case 4: Console.WriteLine("\n Roots are Imaginary");
r1 = (-b) / (2 * a);
r2 = Math.Sqrt(-d1) / (2 * a);
Console.WriteLine("\n First root is {0:#.##} + i {1:#.##}", r1, r2);
Console.WriteLine("\n Second root is {0:#.##} - i {1:#.##}", r1, r2);
Console.ReadLine();
break;
}}}
class Roots{
static void Main(string[] args){
Quadraticroots qr = new Quadraticroots(); qr.read(); qr.compute();
}}}}
OUTPUT:
namespace Prac2_a_4{
class Program{
static void Main(string[] args){
int celsius,
faren;
Console.WriteLine("Enter the Temperature in Celsius(°C) : ");
celsius = int.Parse(Console.ReadLine());
faren = (celsius * 9) / 5 + 32;
Console.WriteLine("0Temperature in Fahrenheit is(°F) : " + faren);
Console.ReadLine();
}}}
OUTPUT:
13
AWP JOURNAL B.N.N COLLEGE
height = Int32.Parse(Console.ReadLine());
Console.WriteLine("Enter surface area");
surface_area = Int32.Parse(Console.ReadLine());
}
public void display(){
base.displaydata();
Console.WriteLine("\nHeight=" + height);
Console.WriteLine("Surface area=" + surface_area);
}}
class sample{
static void Main(string[] args){
table obj = new table();
obj.accept();
obj.display();
Console.ReadKey();
}}}
OUTPUT:
Hierarchical Inheritance
INPUT:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Prac2b_2_b{
class employee{
public void display(){
Console.WriteLine("This is Employee class");
}}
class programmer : employee{
public void display(){
Console.WriteLine("This is Programmer class");
}}
class manager : employee{
public void display(){
Console.WriteLine("This is Manager class");
}}
class sample{
static void Main(string[] args){
Console.WriteLine("Whose information you want to see: \n 1.Programmer \n 2.Manager");
int ch = Int32.Parse(Console.ReadLine());
if (ch == 1){
15
AWP JOURNAL B.N.N COLLEGE
Multilevel Inheritance
INPUT:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication4{
class person{
int age;
String name;
public person(String s,int a){
name = s;
age = a;
}
public void show(){
Console.WriteLine("Name=" + name);
Console.WriteLine("Age=" + age);
}}
class employee : person{
String designation;
public employee(String s, int a, String d)
: base(s, a){
designation = d;
}
public void show(){
base.show();
Console.WriteLine("Designation=" + designation);
}}
class payroll : employee{
int salary;
public payroll(String s, int a, String d, int sal)
: base(s, a, d){
salary = sal;
}
16
AWP JOURNAL B.N.N COLLEGE
IV: Interfaces:
INPUT:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace _2bInterfaces{
interface rect{
void calculate1(float x, float y);
}
class circle{
public void calculate2(float a){
Console.WriteLine("Area of circle= " + 3.14 * a * a);
}}
class shape : circle, rect{
public void calculate1(float x, float y){
Console.WriteLine("Area of rectangle= " + x * y);
}}
class sample{
static void Main(string[] args){
shape obj = new shape();
obj.calculate1(10.1f, 20.1f);
obj.calculate2(5.3f);
Console.ReadKey();
}}}
OUTPUT:
18
AWP JOURNAL B.N.N COLLEGE
}
static void Main(string[] args){
dele d1 = new dele(display);
d1();
Console.ReadKey();
}}}
OUTPUT:
19
AWP JOURNAL B.N.N COLLEGE
PRACTICAL 3
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><asp:Label ID="Label1" runat="server" Text="Name: "></asp:Label>
<asp:TextBox ID="txtname" runat="server"></asp:TextBox><br /><br />
<asp:Label ID="lbladdress" runat="server" Text="Address:"></asp:Label>
<asp:TextBox ID="txtaddress" runat="server"></asp:TextBox><br /><br />
Gender:<br />
<asp:RadioButton ID="rbmale" runat="server" AutoPostBack="True" GroupName="a" Text="Male"
/>
<asp:RadioButton ID="rbfemale" runat="server" AutoPostBack="True" GroupName="a" Text="Female"
/><br /><br />
Subjects:<asp:RadioButtonList ID="RadioButtonList1" runat="server" AutoPostBack="True">
<asp:ListItem>AI</asp:ListItem>
<asp:ListItem>IOT</asp:ListItem>
<asp:ListItem>SPM</asp:ListItem>
<asp:ListItem>JAVA</asp:ListItem>
<asp:ListItem>AWP</asp:ListItem>
</asp:RadioButtonList><br />
Vehicles:<br />
<asp:CheckBoxList ID="CheckBoxList1" runat="server" AutoPostBack="True">
<asp:ListItem>BUS</asp:ListItem><asp:ListItem>CAR</asp:ListItem>
<asp:ListItem>AUTO</asp:ListItem></asp:CheckBoxList><br />
Fruits:<br />
<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True">
<asp:ListItem>Apple</asp:ListItem><asp:ListItem>Mango</asp:ListItem>
<asp:ListItem>Orange</asp:ListItem></asp:DropDownList><br /><br />
20
AWP JOURNAL B.N.N COLLEGE
OUTPUT:
21
AWP JOURNAL B.N.N COLLEGE
WebForm1.aspx:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs"
Inherits="calender.WebForm1" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<body><form id="form1" runat="server"><div>
<asp:Calendar ID="Calendar1" runat="server"></asp:Calendar><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:Label ID="Label3" runat="server" Text="Label"></asp:Label><br /><br />
<asp:Label ID="Label4" runat="server" Text="Label"></asp:Label><br /><br />
<asp:Label ID="Label5" runat="server" Text="Label"></asp:Label><br /><br />
<asp:Button ID="btnresult" runat="server" OnClick="btn_result_Click" Text="Result:" /><br /><br />
<br />
<asp:Button ID="btnreset" runat="server" OnClick="btnreset_Click" Text="Reset:" /><br /></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 calender{
public partial class WebForm1 : System.Web.UI.Page{
protected void Page_Load(object sender, EventArgs e){
}
protected void btn_result_Click(object sender, EventArgs e){
Calendar1.Caption = "Hassan";
Calendar1.FirstDayOfWeek = FirstDayOfWeek.Sunday;
22
AWP JOURNAL B.N.N COLLEGE
Calendar1.NextPrevFormat = NextPrevFormat.ShortMonth;
Calendar1.TitleFormat = TitleFormat.Month;
Label1.Text = "<h1>Welcome to Calandar</h1>";
Label2.Text = "Today's date" + Calendar1.TodaysDate.ToShortDateString();
Label3.Text = "Ganpati Vacation Start: 9-13-2018";
TimeSpan d = new DateTime(2018, 9, 13) - DateTime.Now;
Label4.Text = "Days remaining for ganpati vacation:" + d.Days.ToString();
TimeSpan d1 = new DateTime(2018, 12, 31) - DateTime.Now;
Label5.Text = "Days remaining for new year:" + d1.Days.ToString();
if (Calendar1.SelectedDate.ToShortDateString() == "9-13-2018")
Label3.Text = "<b>Ganpati Festival Start</b>";
if (Calendar1.SelectedDate.ToShortDateString() == "9-23-2018")
Label3.Text = "<b>Ganpati Festival End</b>";
}
protected void btnreset_Click(object sender, EventArgs e){
Label1.Text = "";
Label2.Text = "";
Label3.Text = "";
Label4.Text = "";
Label5.Text = "";
Calendar1.SelectedDates.Clear();
}}}
OUTPUT:
23
AWP JOURNAL B.N.N COLLEGE
25
AWP JOURNAL B.N.N COLLEGE
PRACTICAL 4
Aim: Working with Form Controls
A: Create a Registration form to demonstrate use of various Validation controls.
I: RangeValidator:
Design:
WebForm1.aspx:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs"
Inherits="calender.WebForm1" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<body><form id="form1" runat="server"><div>
<asp:Label ID="Label1" runat="server" Text="Age: "></asp:Label>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:RangeValidator ID="RangeValidator1" runat="server" ControlToValidate="TextBox1"
ErrorMessage="Enter value between 20-80" ForeColor="Red" MaximumValue="80"
MinimumValue="20"></asp:RangeValidator><br /><br />
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="OK" /><br /><br />
<asp:Label ID="Label2" runat="server" Text="Result: "></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 vaaalidation{
public partial class WebForm1 : System.Web.UI.Page{
protected void Page_Load(object sender, EventArgs e){
}
protected void Button1_Click(object sender, EventArgs e){
Label2.Text = TextBox1.Text;
}}}
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>
<appSettings>
<add key="ValidationSettings:UnobtrusiveValidationMode" value="None"/>
</appSettings>
<system.web>
<compilation debug="true" targetFramework="4.0" />
26
AWP JOURNAL B.N.N COLLEGE
</system.web>
</configuration>
OUTPUT:
WebForm1.aspx:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs"
Inherits="validation2.WebForm1" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
</head><body><form id="form1" runat="server"><div>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox><br /><br />
<asp:CompareValidator ID="CompareValidator1" runat="server" BackColor="White"
ControlToCompare="TextBox1" ControlToValidate="TextBox2" ErrorMessage="Enter correct values"
ForeColor="Red"></asp:CompareValidator>
<br /><br />
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox><br /><br />
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="OK" /><br /><br />
<asp:Label ID="Label1" runat="server" Text="Result:"></asp:Label>
</div></form></body></html>
WebForm1.aspc.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace validation2{
public partial class WebForm1 : System.Web.UI.Page{
protected void Page_Load(object sender, EventArgs e){
}
protected void Button1_Click(object sender, EventArgs e){
Label1.Text = TextBox2.Text;
27
AWP JOURNAL B.N.N COLLEGE
}}}
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>
<appSettings>
<add key="ValidationSettings:UnobtrusiveValidationMode" value="None"/>
</appSettings>
<system.web>
<compilation debug="true" targetFramework="4.0" />
</system.web>
</configuration>
OUTPUT:
WebForm1.aspx:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs"
Inherits="validaton3.WebForm1" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
</head><body><form id="form1" runat="server"><div>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="TextBox1"
ErrorMessage="Enter value" ForeColor="Red"></asp:RequiredFieldValidator><br /><br />
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ControlToValidate="TextBox2"
ErrorMessage="Enter value" ForeColor="Red"></asp:RequiredFieldValidator>
<br /><br />
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="OK" />
<br /></div>
<asp:Label ID="Label1" runat="server" Text="Result:"></asp:Label>
</form></body></html>
28
AWP JOURNAL B.N.N COLLEGE
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 validaton3{
public partial class WebForm1 : System.Web.UI.Page{
protected void Page_Load(object sender, EventArgs e){
}
protected void Button1_Click(object sender, EventArgs e){
Label1.Text = TextBox2.Text;
}}}
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><appSettings>
<add key="ValidationSettings:UnobtrusiveValidationMode" value="None"/>
</appSettings>
<system.web>
<compilation debug="true" targetFramework="4.0" />
</system.web></configuration>
OUTPUT:
WebForm1.aspx:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs"
Inherits="validaton3.WebForm1" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
</head><body><form id="form1" runat="server">
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
29
AWP JOURNAL B.N.N COLLEGE
OUTPUT:
V: Custom Validator:
Design:
30
AWP JOURNAL B.N.N COLLEGE
WebForm1.aspx:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs"
Inherits="validaton3.WebForm1" %>
<!DOCTYPE html>
<html xmlns="http:/
<body><form id="form1" runat="server">
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:CustomValidator ID="CustomValidator1" runat="server" ControlToValidate="TextBox1"
ErrorMessage="Enter number which is divisible by 2" ForeColor="Red"
OnServerValidate="CustomValidator1_ServletValidator"></asp:CustomValidator><br /><br />
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="OK" /><br /><br />
<asp:Label ID="Label1" runat="server" Text="Result:"></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 validaton3{
public partial class WebForm1 : System.Web.UI.Page{
protected void Page_Load(object sender, EventArgs e){
}
protected void Button1_Click(object sender, EventArgs e){
Label1.Text = TextBox1.Text;
}
protected void CustomValidator1_ServletValidator(object source, ServerValidateEventArgs args){
int num = int.Parse(TextBox1.Text);
if (num % 2 == 0){
args.IsValid = true;
}
else{
args.IsValid = false;
}}}}
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>
<appSettings>
<add key="ValidationSettings:UnobtrusiveValidationMode" value="None"/>
</appSettings><system.web>
<compilation debug="true" targetFramework="4.0" />
</system.web></configuration>
OUTPUT:
31
AWP JOURNAL B.N.N COLLEGE
WebForm1.aspx:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"><body>
<form id="form1" runat="server">
<asp:AdRotator ID="AdRotator1" runat="server" DataSourceID="XmlDataSource1" />
<asp:XmlDataSource ID="XmlDataSource1" runat="server"
DataFile="~/XMLFile.xml"></asp:XmlDataSource>
</form></body></html>
XML File.xml:
<?xml version="1.0" encoding="utf-8" ?>
<Advertisements><Ad>
<ImageUrl>tim-trad-CLm3pWXrS9Q-unsplash.jpg</ImageUrl>
<NavigateUrl>http://www.google.com</NavigateUrl>
<AlternateText>Google Site</AlternateText></Ad><Ad>
<ImageUrl>larm-rmah-5em1lVBmvw8-unsplash.jpg</ImageUrl>
<NavigateUrl>http://www.facebook.com</NavigateUrl>
<AlternateText>Facebook Site</AlternateText></Ad><Ad>
<ImageUrl>harley-davidson-AyH9hAmiX9Y-unsplash.jpg</ImageUrl>
<NavigateUrl>http://www.gmail.com</NavigateUrl>
<AlternateText>Gmail Site</AlternateText>
</Ad></Advertisements>
OUTPUT:
32
AWP JOURNAL B.N.N COLLEGE
MyUserControl.ascx:
<%@ Control Language="C#" AutoEventWireup="true"
CodeFile="MyUserControl.ascx.cs" Inherits="MyUserControl" %>
<h3>This is User Contro1 </h3>
<table>
<tr>
<td>Name</td>
<td>
<asp:TextBox ID="txtName" runat="server"></asp:TextBox>
</td>
</tr>
<tr><td>City</td>
<td><asp:TextBox ID="txtcity" runat="server"></asp:TextBox></td>
</tr>
<tr><td></td>
<td>
</td>
</tr>
<tr>
<td></td>
<td>
<asp:Button ID="txtSave" runat="server" Text="Save" onclick="txtSave_Click" />
</td>
</tr>
</table><br />
<asp:Label ID="Label1" runat="server" ForeColor="White" Text=" "></asp:Label>
MyUserControl.ascx.cs
protected void txtSave_Click(object sender, EventArgs e)
{
Label1.Text = "Your Name is " + txtName.Text + " and you are from " +
txtcity.Text;
}
UserControlDisplay.aspx:
<%@ Page Language="C#" AutoEventWireup="true"
33
AWP JOURNAL B.N.N COLLEGE
OUTPUT :
34
AWP JOURNAL B.N.N COLLEGE
PRACTICAL 5
Aim: Working with Navigation, Beautification and Master page.
A: Create Web Form to demonstrate use of Website Navigation controls and Site Map
Step1:- Design view:
Home.aspx:
35
AWP JOURNAL B.N.N COLLEGE
Web.sitemap :
<?xml version="1.0" encoding="utf-8" ?>
<siteMap xmlns="http://schemas.microsoft.com/AspNet/SiteMap-File-1.0" >
<siteMapNode url="Home.aspx" title="Home" description="">
<siteMapNode url="Product.aspx" title="Product" description="" >
<siteMapNode url="Electronics.aspx" title="Electronics" description="" >
<siteMapNode url="Tv.aspx" title="Tv" description=""/>
<siteMapNode url="Fan.aspx" title="Fan" description="" />
</siteMapNode>
<siteMapNode url="Fashion.aspx" title="Fashion" description="" >
<siteMapNode url="Cloths.aspx" title="Cloths" description="" />
</siteMapNode>
<siteMapNode url="Shopping.aspx" title="Shopping" description="" >
<siteMapNode url="Bags" title="Bags" description="" />
<siteMapNode url="Shoes.aspx" title="Shoes" description="" />
</siteMapNode>
</siteMapNode>
</siteMapNode>
</siteMap>
OUTPUT:
36
AWP JOURNAL B.N.N COLLEGE
B: Create a web application to demonstrate use of Master Page with applying Styles and Themes for page
beautification.
Skin1.skin:
<asp:Label runat="server" ForeColor="red" Font-size="14pt" Font-Name="Verdana" />
<asp:Button runat="server" Borderstyle="Solid" BorderWidth="2px" Bordercolor="Blue"
Backcolor="Magenta"/>
StyleSheet1.css:
body {
background-color:yellow;
font-family:Cambria;
font-size:18px;
}
Site1.Master:
<%@ Master Language="C#" AutoEventWireup="true" CodeBehind="Site1.master.cs"
Inherits="Pract5.Site1" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<asp:ContentPlaceHolder ID="head" runat="server">
</asp:ContentPlaceHolder>
<link href="StyleSheet1.css" rel="stylesheet" type="text/css" />
</head><body>
<form id="form1" runat="server"> <div>
<asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server">
</asp:ContentPlaceHolder>
<asp:ContentPlaceHolder ID="ContentPlaceHolder2" runat="server">
</asp:ContentPlaceHolder>
</div> </form></body></html>
WebForm2.aspx:
<%@ Page Theme="Skin1" Title="" Language="C#" MasterPageFile="~/Site1.Master"
AutoEventWireup="true" CodeBehind="WebForm2.aspx.cs" Inherits="Pract5.WebForm2" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
<asp:Label ID="Label1" runat="server" Text="Advanced Web Programming"></asp:Label>
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="ContentPlaceHolder2" runat="server">
<asp:Label ID="Label2" runat="server" Text="Enterprise Java"></asp:Label>
<br />
<asp:Label ID="Label3" runat="server" Text="Label"></asp:Label>
<br />
<asp:Button ID="Button1" runat="server" Text="Demo" OnClick="Button1_Click" />
</asp:Content>
WebForm2.aspx.cs:
using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace Pract5
37
AWP JOURNAL B.N.N COLLEGE
{
public partial class WebForm2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
Label3.Text = "Master Page and Content Page Example";
}
}
}
OUTPUT:
38
AWP JOURNAL B.N.N COLLEGE
39
AWP JOURNAL B.N.N COLLEGE
40
AWP JOURNAL B.N.N COLLEGE
III: Cookies:
WebForm1.aspx:
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title></head><body>
<form id="form1" runat="server">
<%-- Cookies--%> <div>
Cookies Example <br /> First Name:
<asp:TextBox ID="txtname1" runat="server"></asp:TextBox><br />
Email Id :
<asp:TextBox ID="txtemail1" runat="server"></asp:TextBox><br /><br />
<asp:Button runat="server" ID="Button2"
Text="Submit" OnClick="Button2_Click" /> <br /> <br />
</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 AWP_Practs{
public partial class WebForm1 : System.Web.UI.Page {
protected void Page_Load(object sender, EventArgs e) {
}
protected void Button2_Click(object sender, EventArgs e) {
HttpCookie cookie = new HttpCookie("UserInfo");
cookie["name"] = txtname1.Text;
cookie["email"] = txtemail1.Text;
//for persistence cookies
cookie.Expires = DateTime.Now.AddSeconds(5);
Response.Cookies.Add(cookie);
Response.Redirect("WebForm2.aspx");
}}}
WebForm2.aspx:
//same AS CrossPage Posting Url
WebForm2.aspx.cs:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace AWP_Practs{
public partial class WebForm2 : System.Web.UI.Page {
protected void Page_Load(object sender, EventArgs e) {
//Cookies
HttpCookie cookie = Request.Cookies["UserInfo"];
41
AWP JOURNAL B.N.N COLLEGE
if (cookie != null) {
lblname.Text=cookie["name"];
lblemail.Text=cookie["email"];
}}}
OUTPUT:
IV: Session:
WebForm1.aspx:
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server"> <title></title></head><body>
<form id="form1" runat="server">
<%-- Session--%> <div> <br />
Session Example <br />
First Name:<asp:TextBox ID="txtname2" runat="server"></asp:TextBox><br />
Email Id :
<asp:TextBox ID="txtemail2" runat="server"></asp:TextBox><br /><br />
<asp:Button runat="server" ID="Button3"
Text="Submit" OnClick="Button3_Click" /><br /> </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 AWP_Practs{
public partial class WebForm1 : System.Web.UI.Page {
protected void Page_Load(object sender, EventArgs e) {
}
protected void Button3_Click(object sender, EventArgs e) {
Session["name"] = txtname2.Text;
Session["email"] = txtemail2.Text;
Session.Timeout = 1;
Response.Redirect("WebForm2.aspx"); } }}
WebForm2.aspx:
//Designing same as above
WebForm2.aspx.cs:
using System;
using System.Collections.Generic;
42
AWP JOURNAL B.N.N COLLEGE
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace AWP_Practs{
public partial class WebForm2 : System.Web.UI.Page {
protected void Page_Load(object sender, EventArgs e) {
if(Session["name"]!=null)
lblname.Text = Session["name"].ToString();
if (Session["email"] != null)
lblemail.Text = Session["email"].ToString();
} }}
OUTPUT:
43
AWP JOURNAL B.N.N COLLEGE
PRACTICAL 6
Aim: Working with database
A: Create a web application bind data in a multiline textbox by querying in another textbox.
INPUT:
Pract6_a.aspx:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Pract6_a.aspx.cs"
Inherits="AWP_Practs.Pract6_a" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"><body>
<form id="form1" runat="server"><div>
<asp:TextBox ID="TextBox1" runat="server" TextMode="MultiLine"></asp:TextBox><br /><br />
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Execute Query" /><br /><br />
<asp:TextBox ID="TextBox2" runat="server" TextMode="MultiLine"></asp:TextBox>
</div></form></body></html>
Pract6_a.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 AWP_Practs{
public partial class Pract6_a : System.Web.UI.Page{
protected void Page_Load(object sender, EventArgs e){
}
protected void Button1_Click(object sender, EventArgs e){
string constr = ConfigurationManager.ConnectionStrings["conn"].ConnectionString;
SqlConnection con = new SqlConnection(constr);
con.Open();
SqlCommand cmd = new SqlCommand(TextBox1.Text,con);
SqlDataReader dr = cmd.ExecuteReader();
TextBox2.Text = "";
while (dr.Read()){
for (int i = 0; i < dr.FieldCount - 1; i++){
TextBox2.Text += dr[i].ToString().PadLeft(15);
}}
dr.Close();
con.Close();
}}}
44
AWP JOURNAL B.N.N COLLEGE
OUTPUT:
45
AWP JOURNAL B.N.N COLLEGE
46
AWP JOURNAL B.N.N COLLEGE
<?xml version="1.0"?>
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.5" />
<httpRuntime targetFramework="4.5" /></system.web>
<connectionStrings>
<add name="conn" connectionString="Data Source=PC\MSSQLSERVERDB;Initial
Catalog=Business;Integrated Security=True"/>
</connectionStrings>
</configuration>
OUTPUT:
47
AWP JOURNAL B.N.N COLLEGE
48
AWP JOURNAL B.N.N COLLEGE
PRACTICAL 7
Aim: Working with Database
A: Create a web application to display Databinding using dropdownlist control.
INPUT:
Pract7_a.aspx:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Pract7_a.aspx.cs"
Inherits="AWP_Practs.Pract7_a" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<body><form id="form1" runat="server"><div>
<asp:DropDownList ID="DropDownList1" runat="server" DataSourceID="SqlDataSource1"
DataTextField="Country" DataValueField="Country"></asp:DropDownList>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="Data
Source=PC\MSSQLSERVERDB;Initial Catalog=Business;Integrated Security=True"
ProviderName="System.Data.SqlClient" SelectCommand="SELECT [Country] FROM
[Customer]"></asp:SqlDataSource><br />
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Click me!" /><br />
<asp:Label ID="Label1" runat="server" Text="the Country You Have Selected Is : "></asp:Label>
</div></form></body></html>
Pract7_a.aspx.cs:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace AWP_Practs{
public partial class Pract7_a : System.Web.UI.Page{
protected void Page_Load(object sender, EventArgs e){
}
protected void Button1_Click(object sender, EventArgs e){
Label1.Text ="The Coutry You Have Selected Is : "+ DropDownList1.SelectedValue;
}}}
49
AWP JOURNAL B.N.N COLLEGE
OUTPUT:
50
AWP JOURNAL B.N.N COLLEGE
B: Create a web application for to display the phone no of an author using database.
INPUT:
Pract7_b.aspx:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Pract7_b.aspx.cs"
Inherits="AWP_Practs.Pract7_b" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<body><form id="form1" runat="server"><div>
<asp:DropDownList ID="DropDownList1" runat="server" DataSourceID="SqlDataSource1"
DataTextField="FirstName" DataValueField="Phone">
</asp:DropDownList>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="Data
Source=PC\MSSQLSERVERDB;Initial Catalog=Business;Integrated Security=True"
ProviderName="System.Data.SqlClient" SelectCommand="SELECT [FirstName], [Phone] FROM
[Customer]"></asp:SqlDataSource><br />
<asp:Button ID="Button1" runat="server" Text="Get Phone No." OnClick="Button1_Click" /><br />
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
</div></form></body></html>
Pract7_b.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 AWP_Practs{
public partial class Pract7_b : System.Web.UI.Page{
protected void Page_Load(object sender, EventArgs e){
}
protected void Button1_Click(object sender, EventArgs e){
Label1.Text = "Your Phone Number Is " + DropDownList1.SelectedValue;
}
}
}
51
AWP JOURNAL B.N.N COLLEGE
OUTPUT:
52
AWP JOURNAL B.N.N COLLEGE
C: Create a web application for inserting and deleting record from a database. (Using Execute-Non Query).
Design:
Pract7_c.aspx:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Pract7_c.aspx.cs"
Inherits="AWP_Practs.Pract7_c" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<body>
<form id="form1" runat="server"><div>
Enter Customer
ID:
<asp:TextBox ID="TextBox6" runat="server"></asp:TextBox><br />
Enter Customer First Name :<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox><br />
Enter Customer Last Name:<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox><br />
Enter Customer City:
<asp:TextBox ID="TextBox3" runat="server"></asp:TextBox><br />
Enter Customer Country :
<asp:TextBox ID="TextBox4" runat="server"></asp:TextBox><br />
Enter Customer Phone:
<asp:TextBox ID="TextBox5" runat="server"></asp:TextBox><br /><br />
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Insert Record" />
<asp:Button ID="Button2" runat="server" OnClick="Button2_Click" Text="Delete Record" /><br /><br />
<asp:Label ID="Label1" runat="server"></asp:Label>
</div></form></body></html>
Pract7_c.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;
53
AWP JOURNAL B.N.N COLLEGE
using System.Web.UI.WebControls;
namespace AWP_Practs{
public partial class Pract7_c : System.Web.UI.Page{
protected void Page_Load(object sender, EventArgs e){
}
protected void Button1_Click(object sender, EventArgs e){
string constr = ConfigurationManager.ConnectionStrings["conn"].ConnectionString;
SqlConnection con = new SqlConnection(constr);
string InsertQuery = "insert into customer values(@id,@fname,@lname,@city,@country,@phone)";
SqlCommand cmd = new SqlCommand(InsertQuery, con);
cmd.Parameters.AddWithValue("@id", TextBox6.Text);
cmd.Parameters.AddWithValue("@fname",TextBox1.Text);
cmd.Parameters.AddWithValue("@lname", TextBox2.Text);
cmd.Parameters.AddWithValue("@city", TextBox3.Text);
cmd.Parameters.AddWithValue("@country", TextBox4.Text);
cmd.Parameters.AddWithValue("@phone", TextBox5.Text);
con.Open();
cmd.ExecuteNonQuery();
Label1.Text = "Record Inserted Successfuly";
con.Close();
}
protected void Button2_Click(object sender, EventArgs e){
string constr = ConfigurationManager.ConnectionStrings["conn"].ConnectionString;
SqlConnection con = new SqlConnection(constr);
string InsertQuery = "Delete from customer where FirstName=@fname";
SqlCommand cmd = new SqlCommand(InsertQuery, con);
cmd.Parameters.AddWithValue("@fname",TextBox1.Text);
con.Open();
cmd.ExecuteNonQuery();
Label1.Text = "Record Deleted Successfuly";
con.Close();
}}}
54
AWP JOURNAL B.N.N COLLEGE
OUTPUT:
55
AWP JOURNAL B.N.N COLLEGE
PRACTICAL 8
Aim: Working with Data Controls
A: Create a web application to demonstrate various uses and properties of SqlDataSource.
INPUT:
Pract8_a.aspx:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Pract8_a.aspx.cs"
Inherits="AWP_Practs.Pract8_a" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<body><form id="form1" runat="server"><div>
<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="true"
DataSourceID="SqlDataSource1" DataTextField="ProductName" DataValueField="ProductName"
OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged" style="margin-bottom: 0px">
</asp:DropDownList>
<asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="Data
Source=PC\MSSQLSERVERDB;Initial Catalog=Business;Integrated Security=True"
ProviderName="System.Data.SqlClient" SelectCommand="SELECT * FROM
[Product]"></asp:SqlDataSource>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="Data
Source=PC\MSSQLSERVERDB;Initial Catalog=Business;Integrated Security=True"
ProviderName="System.Data.SqlClient" SelectCommand="SELECT [ProductName] FROM
[Product]"></asp:SqlDataSource><br /><br />
<asp:DetailsView ID="DetailsView1" runat="server" AutoGenerateRows="False"
DataKeyNames="product_id" DataSourceID="SqlDataSource2" Height="50px" Width="125px"><Fields>
<asp:BoundField DataField="product_id" HeaderText="product_id" ReadOnly="True"
SortExpression="product_id" />
<asp:BoundField DataField="ProductName" HeaderText="ProductName" SortExpression="ProductName"
/>
<asp:BoundField DataField="supplier_id" HeaderText="supplier_id" SortExpression="supplier_id" />
<asp:BoundField DataField="UnitPrice" HeaderText="UnitPrice" SortExpression="UnitPrice" />
<asp:BoundField DataField="Package" HeaderText="Package" SortExpression="Package" />
<asp:CheckBoxField DataField="IsDiscontinued" HeaderText="IsDiscontinued"
SortExpression="IsDiscontinued" />
</Fields>
</asp:DetailsView>
</div></form></body></html>
Pract8_a.aspx.cs:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
56
AWP JOURNAL B.N.N COLLEGE
namespace AWP_Practs{
public partial class Pract8_a : System.Web.UI.Page{
protected void Page_Load(object sender, EventArgs e){
}
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e){
SqlDataSource2.SelectCommand = "select * from product where
ProductName='"+DropDownList1.SelectedValue+"'";
}}}
OUTPUT:
57
AWP JOURNAL B.N.N COLLEGE
B: Create a web application to demonstrate data binding using DetailsView and FormView Control.
INPUT:
Pract8_b.aspx:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Pract8_b.aspx.cs"
Inherits="AWP_Practs.Pract8_b" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<body><form id="form1" runat="server">
<div style="width: 713px">
<asp:FormView ID="FormView1" runat="server" BackColor="White" BorderColor="#999999"
BorderStyle="None" BorderWidth="1px" CellPadding="3" DataKeyNames="id"
DataSourceID="SqlDataSource1" GridLines="Vertical">
<EditItemTemplate>id:
<asp:Label ID="idLabel1" runat="server" Text='<%# Eval("id") %>' /><br />
FirstName:<asp:TextBox ID="FirstNameTextBox" runat="server" Text='<%# Bind("FirstName") %>' />
<br />
LastName:<asp:TextBox ID="LastNameTextBox" runat="server" Text='<%# Bind("LastName") %>' />
<br />
City:<asp:TextBox ID="CityTextBox" runat="server" Text='<%# Bind("City") %>' /><br />
Country:<asp:TextBox ID="CountryTextBox" runat="server" Text='<%# Bind("Country") %>' /><br />
Phone:<asp:TextBox ID="PhoneTextBox" runat="server" Text='<%# Bind("Phone") %>' /><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>
<EditRowStyle BackColor="#008A8C" Font-Bold="True" ForeColor="White" />
<FooterStyle BackColor="#CCCCCC" ForeColor="Black" />
<HeaderStyle BackColor="#000084" Font-Bold="True" ForeColor="White" />
<InsertItemTemplate>
id:<asp:TextBox ID="idTextBox" runat="server" Text='<%# Bind("id") %>' /><br />
FirstName:<asp:TextBox ID="FirstNameTextBox" runat="server" Text='<%# Bind("FirstName") %>' />
<br />
LastName:<asp:TextBox ID="LastNameTextBox" runat="server" Text='<%# Bind("LastName") %>' />
<br />
City:<asp:TextBox ID="CityTextBox" runat="server" Text='<%# Bind("City") %>' /><br />
Country:<asp:TextBox ID="CountryTextBox" runat="server" Text='<%# Bind("Country") %>' /><br />
Phone:<asp:TextBox ID="PhoneTextBox" runat="server" Text='<%# Bind("Phone") %>' /><br />
<asp:LinkButton ID="InsertButton" runat="server" CausesValidation="True" CommandName="Insert"
Text="Insert" />
<asp:LinkButton ID="InsertCancelButton" runat="server" CausesValidation="False"
58
AWP JOURNAL B.N.N COLLEGE
Design:
60
AWP JOURNAL B.N.N COLLEGE
C: Create a web application to display Using Disconnected Data Access and Databinding using Grid View.
INPUT:
Pract8_c.aspx:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Pract8_c.aspx.cs"
Inherits="AWP_Practs.Pract8_c" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<body><form id="form1" runat="server"><div>
&nbs
p; &n
bsp;
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Show Disconnected Fetched
Data" /><br />
<asp:GridView ID="GridView1" runat="server" BackColor="White" BorderColor="#336666"
BorderStyle="Double" BorderWidth="3px" CellPadding="4" GridLines="Horizontal">
<FooterStyle BackColor="White" ForeColor="#333333" />
<HeaderStyle BackColor="#336666" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#336666" ForeColor="White" HorizontalAlign="Center" />
<RowStyle BackColor="White" ForeColor="#333333" />
<SelectedRowStyle BackColor="#339966" Font-Bold="True" ForeColor="White" />
<SortedAscendingCellStyle BackColor="#F7F7F7" />
<SortedAscendingHeaderStyle BackColor="#487575" />
<SortedDescendingCellStyle BackColor="#E5E5E5" />
<SortedDescendingHeaderStyle BackColor="#275353" />
</asp:GridView>
</div></form></body></html>
Design:
Pract8_c.aspx.cs:
61
AWP JOURNAL B.N.N COLLEGE
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 AWP_Practs{
public partial class Pract8_c : System.Web.UI.Page{
protected void Page_Load(object sender, EventArgs e){
}
protected void Button1_Click(object sender, EventArgs e){
string constr = ConfigurationManager.ConnectionStrings["conn"].ConnectionString;
SqlConnection con = new SqlConnection(constr);
SqlDataAdapter da = new SqlDataAdapter();
DataSet ds = new DataSet();
SqlCommand cmd=new SqlCommand("Select * from customer", con);
cmd.CommandType = CommandType.Text;
da.SelectCommand = cmd;
da.Fill(ds, "customer");
GridView1.DataSource = ds.Tables[0];
GridView1.DataBind();
}}}
OUTPUT:
62