Practical 1: A) Create An Application That Obtains Four Int Values From The User and Displays The Product. Code
Practical 1: A) Create An Application That Obtains Four Int Values From The User and Displays The Product. Code
A) Create an application that obtains four int values from the user and displays the product.
Code:-
using System;
class HelloWorld {
static void Main() {
int num1,num2,num3,num4,mul;
Console.WriteLine("Enter a Num1: ");
num1=Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Enter a Num2: ");
num2=Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Enter a Num3: ");
num3=Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Enter a Num4: ");
num4=Convert.ToInt32(Console.ReadLine());
mul=num1*num2*num3*num4;
Console.WriteLine("Product of all number: "+mul);
}
}
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.
Code:-
using System;
class Student{
public int student_Id;
public string student_Name;
public string student_Course;
public string student_DOB;
public void set(){
Console.WriteLine("Enter the Stduent Id: ");
student_Id=Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Enter the Stduent Name: ");
student_Name=Console.ReadLine();
Console.WriteLine("Enter the Stduent Course: ");
student_Course=Console.ReadLine();
Console.WriteLine("Enter the Stduent Date of Birth: ");
student_DOB=Console.ReadLine();
}
public void get(){
Console.WriteLine("Student ID: "+student_Id);
Console.WriteLine("Student Name: "+student_Name);
Console.WriteLine("Student Course: "+student_Course);
Console.WriteLine("Student Date of Birth: "+student_DOB);
}
}
Practical 2
WebForm1.aspx:-
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs"
Inherits="WebApplication2.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:Label ID="Label1" runat="server" Text="Enter number"></asp:Label>
<asp:TextBox ID="TextBox1" runat="server" Text=""></asp:TextBox>
<asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click1" />
<br />
<asp:Label ID="Label2" runat="server" Text=""></asp:Label>
</div>
</form>
</body>
</html>
WebForm1.aspx.cs
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
namespace WebApplication2
{
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{}
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Label ID="Label1" runat="server" Text="Enter money"></asp:Label>
<asp:TextBox ID="TextBox1" runat="server" Text=""></asp:TextBox>
<asp:Button ID="Button1" runat="server" Text="Dollar" OnClick="Button1_Click" />
<asp:Button ID="Button2" runat="server" Text="Dinar" OnClick="Button2_Click" />
<br />
<asp:Label ID="Label2" runat="server" Text=""></asp:Label>
</div>
</form>
</body>
</html>
WebForm2.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
namespace WebApplication2
{
public partial class WebForm2 : 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">
WebForm3.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace WebApplication2
{
public partial class WebForm3 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Output:-
WebForm4.aspx
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
Enter Number 1:<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
Enter Number 2:<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
<asp:Button ID="Button1" runat="server" Text="Area of Circle" OnClick="Button1_Click"
style="height-26px"/>
<asp:Button ID="Button2" runat="server" Text="Area of Square" OnClick="Button2_Click"/>
<asp:Button ID="Button3" runat="server" Text="Area of Rectangle" OnClick="Button3_Click" />
</div>
</form>
</body>
</html>
WebForm4.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace WebApplication2
{
public partial class WebForm4 : System.Web.UI.Page
{
void area(int x)
Output:-
ii) Inheritance
a) Simple Inheritance
Code:-
WebForm5.aspx.cs
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
namespace WebApplication2
{
class A
{
public string show()
{
return ("class A");
}
}
class B : A
{
public string disp()
{
return ("class B");
}
}
b) Hierarchical Inheritance
Code:-
WebForm6.apsx.cs
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace WebApplication2
{
Output:-
using Microsoft.Win32;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Web;
using System.Web.UI;
namespace WebApplication2
{
public partial class WebForm6 : System.Web.UI.Page
{
int z;
public WebForm6()
{
z = 25;
}
public WebForm6(int y)
{
z = y;
}
public WebForm6(WebForm6 obj)
{
z = obj.z;
}
public int show()
{
return z;
}
protected void Page_Load(object sender, EventArgs e)
{
WebForm6 ob = new WebForm6();
Response.Write(ob.show());
WebForm6 ob1 = new WebForm6(15);
Response.Write("<br>" + ob1.show());
WebForm6 ob2 = new WebForm6();
Response.Write("<br>" + ob2.show());
}
}
}
Output:-
iv) Interfaces
Code:-
WebForm28.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
}
}
}
Output:-
namespace WebApplication2
{
public delegate void dell(int x, int y);
}
}
Output:-
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
WebForm7.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace WebApplication2
{
public partial class WebForm7 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Practical 3
Working with Web Forms and Controls
a) Create a simple web page with various server controls to demonstrate setting and use of their properties.
(Example : AutoPostBack)
Code:-
WebForm9.aspx
<!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" AutoPostBack="true"
OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged">
<asp:ListItem Text="Nerul" Value="400706"></asp:ListItem>
<asp:ListItem Text="Seawood" Value="400707"></asp:ListItem>
<asp:ListItem Text="Vashi" Value="400708"></asp:ListItem>
</asp:DropDownList>
<asp:RadioButtonList ID="RadioButtonList1" runat="server" AutoPostBack="true"
OnSelectedIndexChanged="RadioButtonList1_SelectedIndexChanged">
<asp:ListItem Text="Small" Value="Small"></asp:ListItem>
<asp:ListItem Text="Medium" Value="Medium"></asp:ListItem>
<asp:ListItem Text="Large" Value="Large"></asp:ListItem>
</asp:RadioButtonList>
<asp:RadioButtonList ID="RadioButtonList2" runat="server" AutoPostBack="true"
OnSelectedIndexChanged="RadioButtonList2_SelectedIndexChanged">
<asp:ListItem Text="Red" Value="Red"></asp:ListItem>
<asp:ListItem Text="Blue" Value="Blue"></asp:ListItem>
<asp:ListItem Text="Green" Value="Green"></asp:ListItem>
</asp:RadioButtonList>
<asp:RadioButtonList ID="RadioButtonList3" runat="server" AutoPostBack="true"
OnSelectedIndexChanged="RadioButtonList3_SelectedIndexChanged">
<asp:ListItem Text="Arial" Value="Arial"></asp:ListItem>
<asp:ListItem Text="Times New Roman" Value="Times New Roman"></asp:ListItem>
<asp:ListItem Text="Jokerman" Value="Jokerman"></asp:ListItem>
</asp:RadioButtonList>
<asp:CheckBox ID="CheckBox1" runat="server" Text="Underline" AutoPostBack="true"
OnCheckedChanged="CheckBox1_CheckedChanged" />
<asp:CheckBox ID="CheckBox2" runat="server" Text="Italic" AutoPostBack="true"
OnCheckedChanged="CheckBox2_CheckedChanged" />
<asp:CheckBox ID="CheckBox3" runat="server" Text="Bold" AutoPostBack="true"
OnCheckedChanged="CheckBox3_CheckedChanged" />
<br />
<asp:Label ID="Label1" runat="server" Text="SIES COllege of Nerul"></asp:Label>
</div>
</form>
</body>
</html>
WebForm9.aspx.cs
namespace WebApplication2
{
public partial class WebForm9 : 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>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Calendar ID="Calendar1" runat="server" OnDayRender="Calendar1_DayRender"
OnSelectionChanged="Calendar1_SelectionChanged"></asp:Calendar>
</div>
</form>
</body>
</html>
WebForm10.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace WebApplication2
{
public partial class WebForm10 : 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>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Calendar ID="Calendar1" runat="server" OnDayRender="Calendar1_DayRender"
OnSelectionChanged="Calendar1_SelectionChanged"></asp:Calendar>
<asp:Label ID="Label1" runat="server" Text=""></asp:Label>
</div>
</form>
</body>
</html>
WebForm11.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
}
}
Output:-
<!DOCTYPE html>
WebForm12.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace WebApplication2
{
public partial class WebForm12 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Calendar1_SelectionChanged1(object sender, EventArgs e)
{
Response.Write("selected date= " + Calendar1.SelectedDate.ToShortDateString());
}
}
}
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:Calendar ID="Calendar1" runat="server" OnDayRender="Calendar1_DayRender"
OnSelectionChanged="Calendar1_SelectionChanged"></asp:Calendar>
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
</div>
</form>
</body>
</html>
WebForm13.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
Output:-
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
Enter Name:<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server"
ControlToValidate="TextBox1"
ErrorMessage="Please Enter Your Name"></asp:RequiredFieldValidator>
<br />
Enter Age:<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
<asp:RangeValidator ID="RangeValidator1" runat="server" ControlToValidate="TextBox2"
MinimumValue="18" MaximumValue="60" Type="Integer"
ErrorMessage="Enter Valid Age"></asp:RangeValidator>
<br />
</div>
</form>
</body>
</html>
WebForm14.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace WebApplication2
{
public partial class WebForm14 : 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>
</head>
<body>
<form id="form1" runat="server">
XMLFile1.xml
<?xml version="1.0" encoding="utf-8" ?>
<Advertisements>
<Ad>
<ImageUrl>google.png</ImageUrl>
<NavigateUrl>https://www.google.com/</NavigateUrl>
<AlternateText>Google</AlternateText>
<Keyword>Google</Keyword>
<Impressions>50</Impressions>
</Ad>
<Ad>
<ImageUrl>download.png</ImageUrl>
<NavigateUrl>https://mail.google.com/</NavigateUrl>
<AlternateText>Gmail</AlternateText>
<Keyword>Google</Keyword>
<Impressions>20</Impressions>
</Ad>
</Advertisements>
Output:-
WebUserControl.ascx.cs
namespace WebApplication2
{
public partial class WebUserControl1 : System.Web.UI.UserControl
{
protected void Page_Load(object sender, EventArgs e)
{
WebForm16.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm16.aspx.cs"
Inherits="WebApplication2.WebForm16" %>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
ENTER DOB<uc1:WebUserControl1 ID="WebUserControl11" runat="server" />
</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>
<uc1:WebUserControl1 ID="WebUserControl11" runat="server" />
</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>
<uc1:WebUserControl1 ID="WebUserControl11" runat="server" />
</div>
</form>
</body>
</html>
Output:-
<!DOCTYPE html>
<html lang="en">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<table style="width:100%;">
<tr>
<td colspan="2">Welcome.....
<asp:SiteMapPath ID="SiteMapPath1" runat="server"></asp:SiteMapPath>
</td>
</tr>
<tr>
<td>
<asp:Menu ID="Menu1" runat="server">
<Items>
<asp:MenuItem Text="SPM" NavigateUrl="~/WebForm20.aspx">
<asp:MenuItem Text="AWP" NavigateUrl="~/WebForm21.aspx"></asp:MenuItem>
</asp:MenuItem>
<asp:MenuItem Text="NGT" NavigateUrl="~/WebForm20.aspx">
<asp:MenuItem Text="AI" NavigateUrl="~/WebForm21.aspx"></asp:MenuItem>
</asp:MenuItem>
<asp:MenuItem Text="IOT" NavigateUrl="~/WebForm20.aspx"></asp:MenuItem>
</Items>
</asp:Menu>
</div>
</form>
</body>
</html>
WebForm20.aspx
WebForm21.aspx
<%@ Page Title="" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true"
CodeBehind="WebForm21.aspx.cs" Inherits="WebApplication2.WebForm21" %>
<asp:Content ID="Content1" ContentPlaceHolderID="MainContent" runat="server">
AWP
</asp:Content>
Web.sitemap
<?xml version="1.0" encoding="utf-8" ?>
<siteMap xmlns="http://schemas.microsoft.com/AspNet/SiteMap-File-1.0" >
<siteMapNode url="" title="SPM" description="">
<siteMapNode url="" title="AWP" description="" />
<siteMapNode url="" title="AI" description="" />
<siteMapNode url="" title="IOT" description="" />
<siteMapNode url="" title="NGT" description="" />
</siteMapNode>
</siteMap>
StyleSheet.css
body {
background-color: bisque;
color: sandybrown;
font-size: xx-large;
font-family: Jokerman;
}
Output:-
<!DOCTYPE html>
<html lang="en">
<head runat="server">
<title></title>
<link href="App_Themes/Theme1/StyleSheet1.css" rel="stylesheet" />
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ContentPlaceHolder ID="MainContent" runat="server"></asp:ContentPlaceHolder>
</div>
</form>
</body>
</html>
WebForm19.aspx
StyleSheet1.css
body {
background-color: bisque;
color: sandybrown;
font-size: xx-large;
font-family: Jokerman;
}
<!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>
<asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" />
</div>
</form>
</body>
</html>
WebForm22.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace WebApplication2
{
public partial class WebForm22 : System.Web.UI.Page
{
int x = 1;
protected void Page_Load(object sender, EventArgs e)
}
}
}
Output:-
Session State
WebForm23.aspx
<!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>
<asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" />
</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 WebApplication2
{
public partial class WebForm23 : System.Web.UI.Page
{
int x = 1;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
TextBox1.Text = "0";
}
}
}
}
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:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" />
</div>
</form>
</body>
</html>
WebForm24.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace WebApplication2
{
public partial class WebForm24 : System.Web.UI.Page
{
int x = 1;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
TextBox1.Text = "0";
}
}
}
}
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:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" />
<br />
<asp:TextBox ID="TextBox2" runat="server" TextMode="MultiLine"></asp:TextBox>
</div>
</form>
</body>
</html>
WebForm23.aspx.cs
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
namespace WebApplication2
{
public partial class WebForm23 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
while (rd.Read())
{
TextBox2.Text += rd[0] + " " + rd[1] + " " + rd[2] + "\n";
}
}
}
}
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:GridView ID="GridView1" runat="server" ></asp:GridView>
WebForm24.aspx.cs
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace WebApplication2
{
public partial class WebForm24 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection("data source=SQL;Initial Catalog=tyit911;user
Id=user1;Password=user1");
SqlCommand cmd = new SqlCommand("select * from Student1",con);
con.Open();
SqlDataReader rd = cmd.ExecuteReader();
GridView1.DataSource = rd;
GridView1.DataBind();
con.Close();
}
}
}
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:DropDownList ID="DropDownList1" AutoPostBack="true" runat="server"
OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged"></asp:DropDownList>
</div>
</form>
</body>
</html>
WebForm25.aspx.cs
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace WebApplication2
{
public partial class WebForm25 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
SqlConnection con = new SqlConnection("data source=SQL;Initial Catalog=tyit911;user
Id=user1;Password=user1");
SqlCommand cmd = new SqlCommand("select Id,name from Student1", con);
Output:-
c) Create a web application for inserting and deleting record from a database. (Using Execute-Non Query).
Code:-
WebForm26.aspx
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
Enter id:<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox><br />
Enter name:<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox><br />
Enter class:<asp:TextBox ID="TextBox3" runat="server"></asp:TextBox><br />
<asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" />
WebForm26.aspx.cs
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace WebApplication2
{
public partial class WebForm26 : 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>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="Id"
DataSourceID="SqlDataSource1">
<Columns>
<asp:CommandField ShowSelectButton="True" />
<asp:BoundField DataField="Id" HeaderText="Id" ReadOnly="True" SortExpression="Id" />
<asp:BoundField DataField="Name" HeaderText="Name" SortExpression="Name" />
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$
ConnectionStrings:tyit911ConnectionString %>" SelectCommand="SELECT [Id], [Name] FROM
[sg01]"></asp:SqlDataSource>
<asp:FormView ID="FormView1" runat="server" DataKeyNames="Id"
DataSourceID="SqlDataSource2">
<EditItemTemplate>
Id:
<asp:Label ID="IdLabel1" runat="server" Text='<%# Eval("Id") %>' />
<br />
Name:
<asp:TextBox ID="NameTextBox" runat="server" Text='<%# Bind("Name") %>' />
<br />
roll no:
<asp:TextBox ID="roll_noTextBox" runat="server" Text='<%# Bind("[roll no]") %>' />
<br />
class:
<asp:TextBox ID="classTextBox" runat="server" Text='<%# Bind("class") %>' />
<br />
address:
<asp:TextBox ID="addressTextBox" runat="server" Text='<%# Bind("address") %>' />
<br />
gender:
<asp:TextBox ID="genderTextBox" runat="server" Text='<%# Bind("gender") %>' />
<br />
marks:
<asp:TextBox ID="marksTextBox" runat="server" Text='<%# Bind("marks") %>' />
<br />
roll no:
<asp:Label ID="roll_noLabel" runat="server" Text='<%# Bind("[roll no]") %>' />
<br />
class:
<asp:Label ID="classLabel" runat="server" Text='<%# Bind("class") %>' />
<br />
address:
<asp:Label ID="addressLabel" runat="server" Text='<%# Bind("address") %>' />
<br />
gender:
<asp:Label ID="genderLabel" runat="server" Text='<%# Bind("gender") %>' />
</div>
</form>
</body>
</html>
Output:-
DetailView Control
WebForm28.aspx
<!DOCTYPE html>
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:GridView ID="GridView1" runat="server"></asp:GridView>
</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;
using System.Data;
using System.Data.SqlClient;
namespace WebApplication25
Practical 9
Working with GridView control
b. Create a web application to demonstrate use of GridView button column and GridView
events.
Code:
WebForm2.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm3.aspx.cs"
Inherits="WebApplication21.WebForm3" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</ItemTemplate>
</asp:FormView>
</div>
<br />
<asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$
ConnectionStrings:tyit911ConnectionString %>" SelectCommand="SELECT * FROM [test] WHERE ([Id] =
@Id)">
<SelectParameters>
<asp:ControlParameter ControlID="GridView1" Name="Id" PropertyName="SelectedValue"
Type="Int32" />
</SelectParameters>
</asp:SqlDataSource>
</form>
</body>
</html>
Output:
a. Create a web application to demonstrate reading and writing operations with XML.
Code:
XMLFile1.xml
<?xml version="1.0" encoding="utf-8" ?>
<students>
<student>
<rollno>1</rollno>
<name>Sam</name>
<class>tyit</class>
</student>
<student>
<rollno>2</rollno>
<name>Rom</name>
<class>syit</class>
</student>
</students>
WebForm1.aspx
<!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>
<br />
enter name:<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<br />
enter rollno:<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
<br />
enter class:<asp:TextBox ID="TextBox3" runat="server"></asp:TextBox>
<br />
<br />
<br />
<br />
<asp:Button ID="Button1" runat="server" Text="read" OnClick="Button1_Click" />
<asp:Button ID="Button2" runat="server" Text="write" OnClick="Button2_Click" />
</div>
</form>
</body>
aspx.cs code:
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.Xml;
namespace WebApplication23
{
public partial class WebForm2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Output:-
Webform2.aspx:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm2.aspx.cs"
Inherits="WebApplication17.WebForm2" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
Webform2.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.Web.Security;
namespace WebApplication17
{
public partial class WebForm2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Webform3.aspx:
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
Welcome
</div>
</form>
</body>
</html>
Output:
<!DOCTYPE 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 WebApplication22
{
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Label1.Text = DateTime.Now.ToLongTimeString();
}
Practical 11
Programs to create and use DLL
ClassLibrary1:-
WebForm1.aspx:-
WebForm1.aspx.cs:-