0% found this document useful (0 votes)
2 views48 pages

PROGRAMMING

The document outlines the development of a web application using ASP.NET with various controls including server controls, HTML controls, and list controls. It includes code snippets for creating forms for user registration, student registration, and exam registration, demonstrating how to handle user input and display results. Each section provides a structured approach to implementing different types of controls and handling events in a web application context.

Uploaded by

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

PROGRAMMING

The document outlines the development of a web application using ASP.NET with various controls including server controls, HTML controls, and list controls. It includes code snippets for creating forms for user registration, student registration, and exam registration, demonstrating how to handle user input and display results. Each section provides a structured approach to implementing different types of controls and handling events in a web application context.

Uploaded by

inbavallim2006
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

1.

CREATE AN EXPOSURE OF WEB APPLICATIONS AND TOOLS


[Link]:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="[Link]"
Inherits="WebApplication20._Default" %>

<!DOCTYPE html>
<html xmlns="[Link]
<head runat="server">
<title>Exposure of Web Applications and Tools</title>
</head>
<body>
<form id="form1" runat="server">
<div style="text-align:center">
<h1>Exposure of Web Applications and Tools</h1>

<asp:Label ID="Label1" runat="server" Text="Enter your name:"


Width="130px"></asp:Label>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<br /><br />

<asp:Label ID="Label2" runat="server" Text="Select your gender:"


Width="130px"></asp:Label>
<asp:RadioButton ID="RadioButton1" runat="server" GroupName="Gender"
Text="Male" />
<asp:RadioButton ID="RadioButton2" runat="server" GroupName="Gender"
Text="Female" />
<br /><br />

<asp:Label ID="Label3" runat="server" Text="Select your course:"


Width="130px"></asp:Label>
<asp:DropDownList ID="DropDownList1" runat="server">
<asp:ListItem Text="--Select Course--" Value=""></asp:ListItem>
<asp:ListItem>BCA</asp:ListItem>
<asp:ListItem>[Link]</asp:ListItem>
<asp:ListItem>MCA</asp:ListItem>
<asp:ListItem>[Link]</asp:ListItem>
</asp:DropDownList>
<br /><br />

<asp:Button ID="Button1" runat="server" Text="Submit"


OnClick="Button1_Click" Height="30px" Width="100px" />
<br /><br />

<asp:Label ID="Label4" runat="server" Width="300px"></asp:Label>


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

[Link]

using System;

namespace WebApplication20
{
public partial class _Default : [Link]
{
protected void Page_Load(object sender, EventArgs e)
{

protected void Button1_Click(object sender, EventArgs e)


{
string name = [Link]();
string gender = "";
string course = [Link];

if ([Link])
gender = "Male";
else if ([Link])
gender = "Female";
else
gender = "Not Selected";

[Link] = "Hello, " + name + "<br/>" +


"Gender: " + gender + "<br/>" +
"Course: " + course;
}
}
}
2. IMPLEMENT THE HTML CONTROLS
[Link]:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="[Link]"
Inherits="WebApplication20._Default" %>

<!DOCTYPE html>
<html xmlns="[Link]
<head runat="server">
<title>Student Registration Form</title>
</head>
<body>
<form id="form1" runat="server">
<div style="text-align:center;">
<h1>Student Registration Form using HTML Controls</h1>

<label>Enter your name:</label>


<input type="text" id="txtName" runat="server" />
<br /><br />

<label>Enter your email:</label>


<input type="text" id="txtEmail" runat="server" />
<br /><br />

<label>Enter your phone number:</label>


<input type="text" id="txtPhone" runat="server" />
<br /><br />

<label>Enter your age:</label>


<input type="text" id="txtAge" runat="server" />
<br /><br />

<input type="submit" id="btnSubmit" runat="server"


value="Submit"
onserverclick="btnSubmit_ServerClick" />
<br /><br />

<span id="spnResult" runat="server"></span>


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

[Link]
using System;
namespace WebApplication20 // Must match project name
{
public partial class _Default : [Link]
{
protected void Page_Load(object sender, EventArgs e)
{
}

protected void btnSubmit_ServerClick(object sender, EventArgs e)


{
string name = [Link];
string email = [Link];
string phone = [Link];
string age = [Link];

int phoneNumber;
int userAge;

if (![Link](phone, out phoneNumber))


{
[Link] = "Invalid phone number. Please enter numbers only.";
return;
}

if (![Link](age, out userAge))


{
[Link] = "Invalid age. Please enter numbers only.";
return;
}
if (![Link]("@") || ![Link]("."))
{
[Link] = "Invalid email address.";
return;
}

[Link] =
"Hello, " + name + "<br/>" +
"Email: " + email + "<br/>" +
"Phone: " + phoneNumber + "<br/>" +
"Age: " + userAge;
}
}
}
3. IMPLEMENT THE SERVER CONTROLS
[Link]:
<%@ Page Language="C#" AutoEventWireup="true"
CodeFile="[Link]"
Inherits="_Default" %>

<!DOCTYPE html>
<html xmlns="[Link]
<head runat="server">
<title>Simple Exam Registration Platform</title>
</head>
<body>
<form id="form1" runat="server">
<div style="text-align:center;">

<h2>Exam Registration Form using Server Controls</h2>

<asp:Label ID="Label1" runat="server" Text="Enter your name:"></asp:Label>


<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<br /><br />

<asp:Label ID="Label2" runat="server" Text="Enter your email:"></asp:Label>


<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
<br /><br />

<asp:Label ID="Label3" runat="server" Text="Enter your phone number:"></asp:Label>


<asp:TextBox ID="TextBox3" runat="server"></asp:TextBox>
<br /><br />

<asp:Label ID="Label4" runat="server" Text="Select an exam:"></asp:Label>


<asp:DropDownList ID="DropDownList1" runat="server">
<asp:ListItem>Java</asp:ListItem>
<asp:ListItem>C++</asp:ListItem>
<asp:ListItem>.NET</asp:ListItem>
<asp:ListItem>JavaScript</asp:ListItem>
</asp:DropDownList>
<br /><br />

<asp:Button ID="Button1"
runat="server"
Text="Register"
OnClick="Button1_Click" />
<br /><br />

<asp:Label ID="Label6" runat="server"></asp:Label>


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

[Link]
using System;
using [Link];
using [Link];

public partial class _Default : Page


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

protected void Button1_Click(object sender, EventArgs e)


{
// Access controls using FindControl
TextBox txtName = (TextBox)FindControl("TextBox1");
TextBox txtEmail = (TextBox)FindControl("TextBox2");
TextBox txtPhone = (TextBox)FindControl("TextBox3");
DropDownList ddlExam = (DropDownList)FindControl("DropDownList1");
Label lblResult = (Label)FindControl("Label6");

string name = [Link]();


string email = [Link]();
string phone = [Link]();
string exam = [Link];

long phoneNumber;

if ([Link](name))
{
[Link] = "Please enter your name.";
return;
}

if (![Link]("@") || ![Link]("."))
{
[Link] = "Invalid email address.";
return;
}
if (![Link](phone, out phoneNumber))
{
[Link] = "Invalid phone number.";
return;
}

[Link] = "Registration Successful!<br/>" +


"Name: " + name + "<br/>" +
"Email: " + email + "<br/>" +
"Phone: " + phoneNumber + "<br/>" +
"Exam Selected: " + exam;
}
}
4. WEB APPLICATION USING WEB CONTROLS
[Link]:
<%@ Page Language="C#" AutoEventWireup="true"
CodeBehind="[Link]"
Inherits="WebApplication20._Default" %>

<!DOCTYPE html>
<html xmlns="[Link]
<head runat="server">
<title>User Registration Form</title>
</head>
<body>
<center>
<form id="form1" runat="server">
<div>

<h2>User Registration Form using Web Controls</h2>

<asp:Label ID="Label1" runat="server" Text="Enter your name:"></asp:Label>


<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<br /><br />

<asp:Label ID="Label2" runat="server" Text="Select Gender:"></asp:Label>


<br />
<asp:RadioButtonList ID="RadioButtonList1" runat="server">
<asp:ListItem>Male</asp:ListItem>
<asp:ListItem>Female</asp:ListItem>
</asp:RadioButtonList>
<br />

<asp:Label ID="Label3" runat="server" Text="Select Course:"></asp:Label>


<asp:DropDownList ID="DropDownList1" runat="server">
<asp:ListItem>BCA</asp:ListItem>
<asp:ListItem>[Link] IT</asp:ListItem>
<asp:ListItem>MCA</asp:ListItem>
</asp:DropDownList>
<br /><br />

<asp:Label ID="Label4" runat="server" Text="Select Your Skills:"></asp:Label>


<br />
<asp:CheckBoxList ID="CheckBoxList1" runat="server">
<asp:ListItem>HTML</asp:ListItem>
<asp:ListItem>CSS</asp:ListItem>
<asp:ListItem>JavaScript</asp:ListItem>
<asp:ListItem>C#</asp:ListItem>
</asp:CheckBoxList>
<br />

<asp:Button ID="Button1"
runat="server"
Text="Register"
OnClick="Button1_Click" />
<br /><br />

<asp:Label ID="Label5" runat="server" ForeColor="Green"></asp:Label>

</div>
</form>
</center>
</body>
</html>
[Link]:
using System;
using [Link];

namespace WebApplication20
{
public partial class _Default : [Link]
{
protected void Page_Load(object sender, EventArgs e)
{

protected void Button1_Click(object sender, EventArgs e)


{
string name = [Link]();
string gender = [Link];
string course = [Link];

List<string> skills = new List<string>();

foreach ([Link] item in [Link])


{
if ([Link])
{
[Link]([Link]);
}
}
string selectedSkills = [Link] > 0
? [Link](", ", skills)
: "None";

[Link] = "<b>Registration Successful!</b><br/>" +


"Name: " + name + "<br/>" +
"Gender: " + gender + "<br/>" +
"Course: " + course + "<br/>" +
"Skills: " + selectedSkills;
}
}
}
5. WEB APPLICATION USING LIST CONTROLS
[Link]:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="[Link]"
Inherits="[Link]" %>

<!DOCTYPE html>
<html xmlns="[Link]
<head runat="server">
<title>Web Application Using List Controls</title>
</head>
<body>
<CENTER>
<form id="form1" runat="server">
<div>

<h1 style="text-align:center;">Web Application Using List Controls</h1>

<!-- Gender -->


<asp:Label ID="Label3" runat="server" Text="Select Gender:"></asp:Label><br />
<asp:RadioButtonList ID="RadioButtonList1" runat="server">
<asp:ListItem Text="Male" Value="Male"></asp:ListItem>
<asp:ListItem Text="Female" Value="Female"></asp:ListItem>
</asp:RadioButtonList>
<br />

<!-- Course -->


<asp:Label ID="Label1" runat="server" Text="Select a Course:"></asp:Label><br />
<asp:DropDownList ID="DropDownList1" runat="server">
<asp:ListItem Text="BCA" Value="BCA"></asp:ListItem>
<asp:ListItem Text="[Link] IT" Value="[Link] IT"></asp:ListItem>
<asp:ListItem Text="MCA" Value="MCA"></asp:ListItem>
</asp:DropDownList>
<br /><br />

<!-- Subjects -->


<asp:Label ID="Label2" runat="server" Text="Select Your Subjects:"></asp:Label><br
/>
<asp:ListBox ID="ListBox1" runat="server" SelectionMode="Multiple">
<asp:ListItem>Computer Networks</asp:ListItem>
<asp:ListItem>Data Structures</asp:ListItem>
<asp:ListItem>Database Management</asp:ListItem>
<asp:ListItem>Web Technologies</asp:ListItem>
<asp:ListItem>C++</asp:ListItem>
<asp:ListItem>Java</asp:ListItem>
<asp:ListItem>Python</asp:ListItem>
</asp:ListBox>
<br /><br />

<!-- Skills -->


<asp:Label ID="Label4" runat="server" Text="Select Your Skills:"></asp:Label><br />
<asp:CheckBoxList ID="CheckBoxList1" runat="server">
<asp:ListItem>HTML</asp:ListItem>
<asp:ListItem>CSS</asp:ListItem>
<asp:ListItem>JavaScript</asp:ListItem>
<asp:ListItem>C#</asp:ListItem>
</asp:CheckBoxList>
<br />

<!-- Button -->


<asp:Button ID="Button1" runat="server" Text="Submit" OnClick="Button1_Click" />
<br /><br />

<!-- Result -->


<asp:Label ID="Label5" runat="server"></asp:Label>

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

[Link]:
using System;
using [Link];
using [Link];
using [Link];

namespace WebApplication20 // MUST match project name


{
public partial class Default : Page
{
protected void Page_Load(object sender, EventArgs e)
{
}

protected void Button1_Click(object sender, EventArgs e)


{
string gender = [Link];
string selectedCourse = [Link];
List<string> subjectsList = new List<string>();
foreach (ListItem item in [Link])
{
if ([Link])
[Link]([Link]);
}

List<string> skillsList = new List<string>();


foreach (ListItem item in [Link])
{
if ([Link])
[Link]([Link]);
}

string subjects = [Link] > 0 ? [Link](", ", subjectsList) : "None";


string skills = [Link] > 0 ? [Link](", ", skillsList) : "None";

[Link] = "<b>Gender:</b> " + gender + "<br/>" +


"<b>Course:</b> " + selectedCourse + "<br/>" +
"<b>Subjects:</b> " + subjects + "<br/>" +
"<b>Skills:</b> " + skills;
}
}
}
6. WEB PAGE DESIGN USING RICH CONTROLS VALIDATE USER INPUT
USING VALIDATION CONTROLS WORKING WITH FILE CONCEPTS.
[Link]:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="[Link]"
Inherits="WebApplication20._Default" %>

<!DOCTYPE html>
<html xmlns="[Link]
<head runat="server">
<title>Web Application Using Rich Controls</title>
</head>
<body>
<CENTER>
<form id="form1" runat="server">
<div style="padding: 20px;">
<h1 style="text-align:center;">User Input and File Upload</h1>

<asp:Label ID="lblName" runat="server" Text="Enter Name:"></asp:Label>


<asp:TextBox ID="txtName" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="rfvName" runat="server"
ControlToValidate="txtName"
ErrorMessage="Name is required!" ForeColor="Red" Display="Dynamic" />
<br /><br />

<asp:Label ID="lblEmail" runat="server" Text="Enter Email:"></asp:Label>


<asp:TextBox ID="txtEmail" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="rfvEmail" runat="server"
ControlToValidate="txtEmail"
ErrorMessage="Email is required!" ForeColor="Red" Display="Dynamic" />
<asp:RegularExpressionValidator ID="revEmail" runat="server"
ControlToValidate="txtEmail"
ValidationExpression="^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$"
ErrorMessage="Invalid email!" ForeColor="Red" Display="Dynamic" />
<br /><br />

<asp:Label ID="lblDate" runat="server" Text="Select a Date:"></asp:Label>


<asp:Calendar ID="Calendar1" runat="server"></asp:Calendar>
<br />

<asp:Label ID="lblFile" runat="server" Text="Upload a File:"></asp:Label>


<asp:FileUpload ID="FileUpload1" runat="server" />
<asp:RequiredFieldValidator ID="rfvFile" runat="server"
ControlToValidate="FileUpload1"
ErrorMessage="File is required!" ForeColor="Red" Display="Dynamic" />
<br /><br />
<asp:Button ID="btnSubmit" runat="server" Text="Submit"
OnClick="btnSubmit_Click" />
<br /><br />

<asp:Label ID="lblOutput" runat="server" Text=""></asp:Label>


<br /><br />
<asp:Image ID="imgUploaded" runat="server" Visible="false" Width="300px" />
</div>
</form>
</CENTER>
</body>
</html>

[Link]:
using System;
using [Link];
using [Link];

namespace WebApplication20
{
public partial class _Default : [Link]
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btnSubmit_Click(object sender, EventArgs e)
{
if ([Link])
{
// 1. Get Inputs
string name = [Link];
string email = [Link];
string selectedDate = ([Link] == [Link])
? "No date selected!"
: [Link]();

string fileDisplayPath = "No file uploaded.";

// 2. Handle File Upload


if ([Link])
{
try
{
string folderPath = [Link]("~/Uploads/");
if (![Link](folderPath))
{
[Link](folderPath);
}

string fileName = [Link]([Link]);


string fullPath = [Link](folderPath, fileName);
[Link](fullPath);

fileDisplayPath = "~/Uploads/" + fileName;


[Link] = fileDisplayPath;
[Link] = true;
}
catch (Exception ex)
{
[Link] = "Error: " + [Link];
return;
}
}

// 3. Display Result
[Link] = $"<b>Name:</b> {[Link](name)}<br />" +
$"<b>Email:</b> {[Link](email)}<br />" +
$"<b>Date:</b> {selectedDate}<br />" +
$"<b>File:</b> {fileDisplayPath}";
}
}
}
}
7. WEB APPLICATION USING DATA CONTROLS
[Link]:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="[Link]"
Inherits="[Link]" %>

<!DOCTYPE html>
<html xmlns="[Link]
<head runat="server">
<title>Web application using Data Controls</title>

<style>
body {
font-family: "Times New Roman";
}

.box {
width: 650px;
margin: auto;
border: 1px solid black;
padding: 20px;
}

table {
margin: auto;
}

td {
padding: 5px;
}
</style>
</head>

<body>
<form id="form1" runat="server">

<div class="box">

<h2 style="text-align:center;">Web Application using Data Controls</h2>

<table>
<tr>
<td>Book No</td>
<td>
<asp:TextBox ID="txtBookNo" runat="server"></asp:TextBox>
</td>
</tr>

<tr>
<td>Book Name</td>
<td>
<asp:TextBox ID="txtBookName" runat="server"></asp:TextBox>
</td>
</tr>

<tr>
<td>Publish Year</td>
<td>
<asp:TextBox ID="txtYear" runat="server"></asp:TextBox>
</td>
</tr>

<tr>
<td colspan="2" align="center">
<asp:Button ID="btnInsert" runat="server" Text="Insert" OnClick="btnInsert_Click" />
</td>
</tr>
</table>

<br />

<asp:GridView ID="GridView1" runat="server"


AutoGenerateColumns="False"
AutoGenerateEditButton="True"
AutoGenerateDeleteButton="True"
OnRowEditing="GridView1_RowEditing"
OnRowUpdating="GridView1_RowUpdating"
OnRowCancelingEdit="GridView1_RowCancelingEdit"
OnRowDeleting="GridView1_RowDeleting">

<Columns>

<asp:BoundField DataField="BookNo" HeaderText="Book No" />


<asp:BoundField DataField="BookName" HeaderText="Book Name" />
<asp:BoundField DataField="PublishYear" HeaderText="Publish Year" />

</Columns>

</asp:GridView>
</div>

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

[Link]:
using System;
using [Link];

namespace WebApplication47
{
public partial class Default : [Link]
{

DataTable dt;

protected void Page_Load(object sender, EventArgs e)


{
if (!IsPostBack)
{
dt = new DataTable();

[Link]("BookNo");
[Link]("BookName");
[Link]("PublishYear");

[Link]("10", "Java", "2012");


[Link]("15", "JavaScript", "2006");
[Link]("5310", "C++", "1996");

ViewState["Books"] = dt;

BindGrid();
}
}

void BindGrid()
{
[Link] = ViewState["Books"] as DataTable;
[Link]();
}

protected void btnInsert_Click(object sender, EventArgs e)


{
dt = ViewState["Books"] as DataTable;

[Link]([Link], [Link], [Link]);


ViewState["Books"] = dt;

BindGrid();

[Link] = "";
[Link] = "";
[Link] = "";
}

protected void GridView1_RowEditing(object sender,


[Link] e)
{
[Link] = [Link];

BindGrid();
}

protected void GridView1_RowCancelingEdit(object sender,


[Link] e)
{
[Link] = -1;

BindGrid();
}

protected void GridView1_RowUpdating(object sender,


[Link] e)
{
dt = ViewState["Books"] as DataTable;

[Link][[Link]]["BookNo"] =

(([Link])[Link][[Link]].Cells[1].Controls[0]).T
ext;

[Link][[Link]]["BookName"] =

(([Link])[Link][[Link]].Cells[2].Controls[0]).T
ext;

[Link][[Link]]["PublishYear"] =

(([Link])[Link][[Link]].Cells[3].Controls[0]).T
ext;
[Link] = -1;

ViewState["Books"] = dt;

BindGrid();
}

protected void GridView1_RowDeleting(object sender,


[Link] e)
{
dt = ViewState["Books"] as DataTable;

[Link]([Link]);

ViewState["Books"] = dt;

BindGrid();
}

}
}
8. DATA BINDING WITH WEB CONTROLS
[Link]:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="[Link]"
Inherits="WebApplication43._Default" %>

<!DOCTYPE html>
<html>
<head runat="server">
<title>Data Binding with Web controls</title>
</head>
<body>
<center>
<form id="form1" runat="server">
<div>
<h2>Data Binding with Web controls</h2>

<!-- DropDownList -->


<asp:Label ID="Label1" runat="server" Text="Choose Books Title
(DropDownList):"></asp:Label><br />
<asp:DropDownList ID="ddlBooks" runat="server"></asp:DropDownList>
<br /><br />

<!-- ListBox -->


<asp:Label ID="Label2" runat="server" Text="Choose Author Name
(ListBox):"></asp:Label><br />
<asp:ListBox ID="lstAuthors" runat="server"></asp:ListBox>
<br /><br />

<!-- RadioButtonList -->


<asp:Label ID="Label3" runat="server" Text="Choose Publish Year
(RadioButtonList):"></asp:Label><br />
<asp:RadioButtonList ID="rblYear" runat="server"></asp:RadioButtonList>
<br />

<!-- Button -->


<asp:Button ID="btnSubmit" runat="server" Text="Submit"
OnClick="btnSubmit_Click" />
<br /><br />

<!-- Output -->


<asp:Label ID="lblResult" runat="server"></asp:Label>

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

[Link]:
using System;
using [Link];

namespace WebApplication43 // MUST match project name


{
public partial class _Default : Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
[Link]("C");
[Link]("C++");
[Link]("Java");
[Link]("Python");

[Link]("Dennis M. Ritchie");
[Link]("Herbert Schildt");
[Link]("Bjarne Stroustrup");
[Link]("Adam Freeman");

[Link]("1978");
[Link]("1995");
[Link]("2008");
[Link]("2017");
[Link]("1986");
}
}

protected void btnSubmit_Click(object sender, EventArgs e)


{
[Link] =
"<b>Selected Values</b><br/>" +
"Book Title: " + [Link] + "<br/>" +
"Author Name: " + [Link] + "<br/>" +
"Published Year: " + [Link];
}
}
}
9. DATA BINDING WITH DATA CONTROLS
[Link]:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="[Link]"
Inherits="WebApplication43._Default" %>
<!DOCTYPE html>
<html xmlns="[Link]
<head runat="server">
<title>Data Binding with Data Controls</title>
</head>
<body>
<Center>
<form id="form1" runat="server">

<h2>Data Binding with Data Controls</h2>

<!-- GridView -->


<asp:GridView ID="GridView1" runat="server"
AutoGenerateColumns="False"
AllowPaging="True"
PageSize="3"
OnPageIndexChanging="GridView1_PageIndexChanging"
OnSelectedIndexChanged="GridView1_SelectedIndexChanged">

<Columns>
<asp:BoundField DataField="BookTitle" HeaderText="BookTitle" />
<asp:BoundField DataField="AuthorName" HeaderText="AuthorName" />
<asp:BoundField DataField="PublishYear" HeaderText="PublishYear" />
<asp:CommandField ShowSelectButton="True" />
</Columns>
</asp:GridView>

<br />

<!-- DetailsView -->


<asp:DetailsView ID="DetailsView1" runat="server"
AutoGenerateRows="False"
Height="50px"
Width="300px">
<Fields>
<asp:BoundField DataField="BookTitle" HeaderText="BookTitle" />
<asp:BoundField DataField="AuthorName" HeaderText="AuthorName" />
<asp:BoundField DataField="PublishYear" HeaderText="PublishYear" />
</Fields>
</asp:DetailsView>
<br />

<!-- Selected Output -->


<asp:Label ID="lblOutput" runat="server"></asp:Label>

</form>
</Center>
</body>
</html>

[Link]:
using System;
using [Link];
using [Link];

namespace WebApplication43 // MUST match project name


{
public partial class _Default : Page
{
DataTable dt;

protected void Page_Load(object sender, EventArgs e)


{
if (!IsPostBack)
{
BindGrid();
}
}

void BindGrid()
{
dt = new DataTable();
[Link]("BookTitle");
[Link]("AuthorName");
[Link]("PublishYear");

[Link]("[Link]", "Adam", "2017");


[Link]("JavaScript", "Crockford", "2008");
[Link]("Java", "Herbert", "1995");
[Link]("C", "Dennis M. Ritchie", "1978");
[Link]("DBMS", "Sudarshan", "1986");

ViewState["data"] = dt;
[Link] = dt;
[Link]();
}

protected void GridView1_PageIndexChanging(object sender,


[Link] e)
{
[Link] = [Link];
[Link] = ViewState["data"] as DataTable;
[Link]();
}

protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)


{
DataTable table = ViewState["data"] as DataTable;

[Link] = table;
[Link] = [Link];
[Link]();

[Link] =
"<b>BookTitle:</b> " + [Link][0].Text + "<br/>" +
"<b>AuthorName:</b> " + [Link][1].Text + "<br/>" +
"<b>PublishYear:</b> " + [Link][2].Text;
}
}
}
10. DATABASE APPLICATION TO PERFORM INSERT, UPDATE AND DELETE
OPERATION
[Link]:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="[Link]"
Inherits="[Link]" %>

<!DOCTYPE html>
<html xmlns="[Link]
<head runat="server">
<title>Student Database Application</title>
</head>
<body>
<form id="form1" runat="server">
<center>
<h2>Student Database Application</h2>

ID:
<asp:TextBox ID="txtId" runat="server"></asp:TextBox>
<br /><br />

Name:
<asp:TextBox ID="txtName" runat="server"></asp:TextBox>
<br /><br />

Department:
<asp:TextBox ID="txtDept" runat="server"></asp:TextBox>
<br /><br />

Marks:
<asp:TextBox ID="txtMarks" runat="server"></asp:TextBox>
<br /><br />

<asp:Button ID="btnInsert" runat="server" Text="Insert" OnClick="btnInsert_Click" />


<asp:Button ID="btnUpdate" runat="server" Text="Update"
OnClick="btnUpdate_Click" />
<asp:Button ID="btnDelete" runat="server" Text="Delete" OnClick="btnDelete_Click"
/>

<br /><br />

<asp:Label ID="lblMsg" runat="server" ForeColor="Green"></asp:Label>

<br /><br />


<asp:GridView ID="GridView1" runat="server"
AutoGenerateColumns="true"></asp:GridView>

</center>
</form>
</body>
</html>
[Link]:
using System;
using [Link];
using [Link];

namespace WebApplication45 // ⚠ Must match your project name


{
public partial class Default : [Link]
{
SqlConnection con = new SqlConnection(
@"Data Source=(localdb)\MSSQLLocalDB;Initial Catalog=StudentDB;Integrated
Security=True");

protected void Page_Load(object sender, EventArgs e)


{
if (!IsPostBack)
{
LoadData();
}
}

void LoadData()
{
SqlDataAdapter da = new SqlDataAdapter("SELECT * FROM Student", con);
DataTable dt = new DataTable();
[Link](dt);
[Link] = dt;
[Link]();
}

protected void btnInsert_Click(object sender, EventArgs e)


{
[Link]();
SqlCommand cmd = new SqlCommand(
"INSERT INTO Student(Name, Department, Marks) VALUES(@Name, @Dept,
@Marks)", con);

[Link]("@Name", [Link]);
[Link]("@Dept", [Link]);
[Link]("@Marks", Convert.ToInt32([Link]));

[Link]();
[Link]();

[Link] = "Record Inserted Successfully";


LoadData();
}

protected void btnUpdate_Click(object sender, EventArgs e)


{
[Link]();
SqlCommand cmd = new SqlCommand(
"UPDATE Student SET Name=@Name, Department=@Dept, Marks=@Marks
WHERE Id=@Id", con);

[Link]("@Id", Convert.ToInt32([Link]));
[Link]("@Name", [Link]);
[Link]("@Dept", [Link]);
[Link]("@Marks", Convert.ToInt32([Link]));

[Link]();
[Link]();

[Link] = "Record Updated Successfully";


LoadData();
}

protected void btnDelete_Click(object sender, EventArgs e)


{
[Link]();
SqlCommand cmd = new SqlCommand(
"DELETE FROM Student WHERE Id=@Id", con);

[Link]("@Id", Convert.ToInt32([Link]));

[Link]();
[Link]();

[Link] = "Record Deleted Successfully";


LoadData();
}
}
}
SQL TABLE:
CREATE TABLE Student
(
Id INT IDENTITY(1,1) PRIMARY KEY,
Name NVARCHAR(50),
Department NVARCHAR(50),
Marks INT
);
11. DATABASE APPLICATION TO PERFORM INSERT, UPDATE AND DELETE
OPERATIONS.
[Link]:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="[Link]"
Inherits="[Link]" %>

<!DOCTYPE html>
<html xmlns="[Link]
<head runat="server">
<title>Data Control Application</title>
</head>
<body>
<form id="form1" runat="server">
<center>
<h2>Student Database using Data Controls</h2>
Name:
<asp:TextBox ID="txtName" runat="server"></asp:TextBox>

Department:
<asp:TextBox ID="txtDept" runat="server"></asp:TextBox>

Marks:
<asp:TextBox ID="txtMarks" runat="server"></asp:TextBox>
<asp:Button ID="btnInsert" runat="server" Text="Insert" OnClick="btnInsert_Click" />
<br /><br />

<asp:GridView ID="GridView1" runat="server"


AutoGenerateColumns="False"
DataKeyNames="Id"
AllowPaging="True"
AllowSorting="True"
PageSize="5"
OnPageIndexChanging="GridView1_PageIndexChanging"
OnRowEditing="GridView1_RowEditing"
OnRowCancelingEdit="GridView1_RowCancelingEdit"
OnRowUpdating="GridView1_RowUpdating"
OnRowDeleting="GridView1_RowDeleting">

<Columns>
<asp:BoundField DataField="Id" HeaderText="ID" ReadOnly="True" SortExpression="Id"
/>
<asp:BoundField DataField="Name" HeaderText="Name" SortExpression="Name" />
<asp:BoundField DataField="Department" HeaderText="Department"
SortExpression="Department" />
<asp:BoundField DataField="Marks" HeaderText="Marks" SortExpression="Marks" />
<asp:CommandField ShowEditButton="True" ShowDeleteButton="True" />
</Columns>
</asp:GridView>
<br />
<asp:Label ID="lblMsg" runat="server" ForeColor="Green"></asp:Label>
</center>
</form>
</body>
</html>
[Link]:
using System;
using [Link];
using [Link];

namespace WebApplication45 // ⚠ Change if your project name different


{
public partial class Default : [Link]
{
SqlConnection con = new SqlConnection(
@"Data Source=(localdb)\MSSQLLocalDB;Initial Catalog=StudentDB;Integrated
Security=True");

protected void Page_Load(object sender, EventArgs e)


{
if (!IsPostBack)
{
BindGrid();
}
}

void BindGrid()
{
SqlDataAdapter da = new SqlDataAdapter("SELECT * FROM Student", con);
DataTable dt = new DataTable();
[Link](dt);
[Link] = dt;
[Link]();
}

protected void btnInsert_Click(object sender, EventArgs e)


{
[Link]();
SqlCommand cmd = new SqlCommand(
"INSERT INTO Student(Name, Department, Marks)
VALUES(@Name,@Dept,@Marks)", con);

[Link]("@Name", [Link]);
[Link]("@Dept", [Link]);
[Link]("@Marks", Convert.ToInt32([Link]));

[Link]();
[Link]();

[Link] = "Record Inserted Successfully";


BindGrid();
}

protected void GridView1_RowEditing(object sender,


[Link] e)
{
[Link] = [Link];
BindGrid();
}
protected void GridView1_RowCancelingEdit(object sender,
[Link] e)
{
[Link] = -1;
BindGrid();
}

protected void GridView1_RowUpdating(object sender,


[Link] e)
{
int id = Convert.ToInt32([Link][[Link]].Value);
string name =
(([Link])[Link][[Link]].Cells[1].Controls[0]).T
ext;
string dept =
(([Link])[Link][[Link]].Cells[2].Controls[0]).T
ext;
int marks =
Convert.ToInt32((([Link])[Link][[Link]].Cells[
3].Controls[0]).Text);

[Link]();
SqlCommand cmd = new SqlCommand(
"UPDATE Student SET Name=@Name, Department=@Dept, Marks=@Marks
WHERE Id=@Id", con);

[Link]("@Id", id);
[Link]("@Name", name);
[Link]("@Dept", dept);
[Link]("@Marks", marks);

[Link]();
[Link]();

[Link] = -1;
[Link] = "Record Updated Successfully";
BindGrid();
}

protected void GridView1_RowDeleting(object sender,


[Link] e)
{
int id = Convert.ToInt32([Link][[Link]].Value);

[Link]();
SqlCommand cmd = new SqlCommand("DELETE FROM Student WHERE Id=@Id",
con);
[Link]("@Id", id);
[Link]();
[Link]();

[Link] = "Record Deleted Successfully";


BindGrid();
}

protected void GridView1_PageIndexChanging(object sender,


[Link] e)
{
[Link] = [Link];
BindGrid();
}
}
}

SQL TABLE
CREATE TABLE Student
(
Id INT IDENTITY(1,1) PRIMARY KEY,
Name VARCHAR(50),
Department VARCHAR(50),
Marks INT
);
12. IMPLEMENT THE XML CLASSES
[Link]:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="[Link]"
Inherits="[Link]" %>

<!DOCTYPE html>
<html xmlns="[Link]
<head runat="server">
<title>XML Read and Write</title>
</head>
<body>
<form id="form1" runat="server">
<div style="text-align:center;">
<h1>XML File Write & Read Example</h1>

<asp:Button ID="btnWrite" runat="server" Text="Write XML"


OnClick="btnWrite_Click" />
<br /><br />

<asp:Button ID="btnRead" runat="server" Text="Read XML"


OnClick="btnRead_Click" />
<br /><br />

<asp:Label ID="lblResult" runat="server"


Font-Bold="True" ForeColor="Green" />
</div>
</form>
</body>
</html>

[Link]:
using System;
using [Link];
using [Link];

namespace WebApplication28
{
public partial class Default : [Link]
{
string xmlPath;

protected void Page_Load(object sender, EventArgs e)


{
xmlPath = [Link]("~/[Link]");
}

protected void btnWrite_Click(object sender, EventArgs e)


{
using (XmlWriter writer = [Link](xmlPath))
{
[Link]();
[Link]("Students");
[Link]("Student");
[Link]("Name", "ABC");
[Link]("Department", "BCA");
[Link]("Year", "2");
[Link](); // Student
[Link](); // Students
[Link]();
}

[Link] = "XML file created successfully!";


}

protected void btnRead_Click(object sender, EventArgs e)


{
if (![Link](xmlPath))
{
[Link] = "XML file not found. Please click Write XML first.";
return;
}

string output = "";

using (XmlReader reader = [Link](xmlPath))


{
while ([Link]())
{
if ([Link] == [Link] &&
[Link] != "Students" &&
[Link] != "Student")
{
output += "<b>" + [Link] + ":</b> ";
}

if ([Link] == [Link])
{
output += [Link] + "<br/>";
}
}
}

[Link] = output;
}
}
}
13. IMPLEMENT AUTHENTICATION-AUTHORIZATION
[Link]:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="[Link]"
Inherits="[Link]" %>

<!DOCTYPE html>
<html xmlns="[Link]
<head runat="server">
<title>Login Page</title>
</head>
<body>
<form id="form1" runat="server">
<div style="text-align:center; margin-top:100px;">

<h2>Login Page</h2>

Username:
<asp:TextBox ID="txtUsername" runat="server"></asp:TextBox>
<br /><br />

Password:
<asp:TextBox ID="txtPassword" runat="server" TextMode="Password"></asp:TextBox>
<br /><br />

<asp:Button ID="btnLogin" runat="server"


Text="Login" OnClick="btnLogin_Click" />
<br /><br />

<asp:Label ID="lblMsg" runat="server"


ForeColor="Red"></asp:Label>

</div>
</form>
</body>
</html>
[Link]:
using System;

namespace WebApplication44
{
public partial class Login : [Link]
{
protected void btnLogin_Click(object sender, EventArgs e)
{
string username = [Link]();
string password = [Link]();

if (username == "admin" && password == "admin123")


{
Session["username"] = "admin";
Session["role"] = "Admin";
[Link]("[Link]");
}
else if (username == "user" && password == "user123")
{
Session["username"] = "user";
Session["role"] = "User";
[Link]("[Link]");
}
else
{
[Link] = "Invalid Username or Password!";
}
}
}
}
[Link]:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="[Link]"
Inherits="[Link]" %>
<!DOCTYPE html>
<html xmlns="[Link]
<head runat="server">
<title>Admin Page</title>
</head>
<body>
<form id="form1" runat="server">
<div style="text-align:center; margin-top:100px;">

<h2>Welcome Admin</h2>

<asp:Label ID="lblUser" runat="server"


ForeColor="Green"></asp:Label>
<br /><br />

<asp:Button ID="btnLogout" runat="server"


Text="Logout" OnClick="btnLogout_Click" />
</div>
</form>
</body>
</html>
[Link]:
using System;

namespace WebApplication44
{
public partial class AdminPage : [Link]
{
protected void Page_Load(object sender, EventArgs e)
{
if (Session["username"] == null ||
Session["role"] == null ||
Session["role"].ToString() != "Admin")
{
[Link]("[Link]");
}
else
{
[Link] = "Logged in as: " +
Session["username"].ToString() +
" (Role: Admin)";
}
}

protected void btnLogout_Click(object sender, EventArgs e)


{
[Link]();
[Link]("[Link]");
}
}
}
[Link]:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="[Link]"
Inherits="[Link]" %>

<!DOCTYPE html>
<html xmlns="[Link]
<head runat="server">
<title>User Page</title>
</head>
<body>
<form id="form1" runat="server">
<div style="text-align:center; margin-top:100px;">

<h2>Welcome User</h2>

<asp:Label ID="lblUser" runat="server"


ForeColor="Blue"></asp:Label>
<br /><br />

<asp:Button ID="btnLogout" runat="server"


Text="Logout" OnClick="btnLogout_Click" />

</div>
</form>
</body>
</html>
[Link]:
using System;

namespace WebApplication44
{
public partial class UserPage : [Link]
{
protected void Page_Load(object sender, EventArgs e)
{
if (Session["username"] == null ||
Session["role"] == null ||
Session["role"].ToString() != "User")
{
[Link]("[Link]");
}
else
{
[Link] = "Logged in as: " +
Session["username"].ToString() +
" (Role: User)";
}
}

protected void btnLogout_Click(object sender, EventArgs e)


{
[Link]();
[Link]("[Link]");
}
}
}
14. TICKET RESERVATION USING [Link] CONTROLS
[Link]:
<%@ Page Language="C#" AutoEventWireup="true"
CodeBehind="[Link]"
Inherits="WebApplication28._Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"


"[Link]
<html xmlns="[Link] >
<head runat="server">
<title>Ticket Reservation Form using [Link] controls</title>
</head>
<body>
<center>
<form id="form1" runat="server">
<div>
<h1 style="text-align: center;">Ticket Reservation Form using [Link] controls</h1>

<asp:Label ID="Label1" runat="server" Height="20px" Text="Name"


Width="75px"></asp:Label>
&nbsp;
<asp:TextBox ID="txtName" runat="server"></asp:TextBox>&nbsp;
<br />
<br />

<asp:Label ID="Label2" runat="server" Height="20px" Text="Destination"


Width="75px"></asp:Label>
&nbsp;
<asp:DropDownList ID="ddlDestination" runat="server">
<asp:ListItem>Chennai</asp:ListItem>
<asp:ListItem>Salem</asp:ListItem>
<asp:ListItem>Madurai</asp:ListItem>
<asp:ListItem>Trichy</asp:ListItem>
<asp:ListItem>Namakkal</asp:ListItem>
</asp:DropDownList>&nbsp;<br />
<br />

<asp:Label ID="Label3" runat="server" Height="20px" Text="Class Type"


Width="75px"></asp:Label>
&nbsp;
<asp:RadioButtonList ID="rblClass" runat="server">
<asp:ListItem>AC</asp:ListItem>
<asp:ListItem>Non-AC</asp:ListItem>
</asp:RadioButtonList><br />
&nbsp;<asp:Label ID="Label4" runat="server" Height="20px" Text="Journey Date"
Width="85px"></asp:Label>
&nbsp;
<asp:Calendar ID="Calendar1" runat="server"></asp:Calendar>
<br />
<asp:Button ID="btnReserve" runat="server" Height="25px" OnClick="btnReserve_Click"
Text="Reserve Ticket" Width="100px" />&nbsp;<br />
<br />
<asp:Label ID="lblOutput" runat="server" Height="50px" Width="300px"></asp:Label>&nbsp;
</div>
</form>
</center>
</body>
</html>

[Link]:
using System;

namespace WebApplication28
{
public partial class _Default : [Link]
{
protected void Page_Load(object sender, EventArgs e)
{

protected void btnReserve_Click(object sender, EventArgs e)


{
if ([Link]([Link]) ||
[Link] == -1 ||
[Link] == [Link])
{
[Link]("<script>alert('Please fill all fields.');</script>");
return;
}

[Link] = "<b>Ticket Reserved Successfully!</b><br/><br/>" +


"<b>Name:</b> " + [Link] + "<br/>" +
"<b>Destination:</b> " + [Link] + "<br/>" +
"<b>Class:</b> " + [Link] + "<br/>" +
"<b>Journey Date:</b> " + [Link]();
}
}
}
15. ONLINE EXAMINATION USING [Link] CONTROLS
[Link]:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="[Link]"
Inherits="WebApplication28._Default" %>

<!DOCTYPE html>
<html xmlns="[Link]
<head runat="server">
<title>Online Examination - [Link]</title>
</head>
<body>
<center>
<form id="form1" runat="server">
<div>

<h1 style="text-align:center;">Online Examination Using [Link] Controls</h1>

<asp:Label ID="Label1" runat="server" Text="Student Name:" />


<asp:TextBox ID="txtStudentName" runat="server" />
<br /><br />

<asp:Label ID="Label2" runat="server" Text="Select Subject:" />


<asp:DropDownList ID="ddlSubject" runat="server">
<asp:ListItem>Maths</asp:ListItem>
<asp:ListItem>Science</asp:ListItem>
<asp:ListItem>English</asp:ListItem>
</asp:DropDownList>
<br /><br />

<asp:Label ID="Label3" runat="server" Text="1. What is 2 + 2?" /><br />


<asp:RadioButtonList ID="q1" runat="server">
<asp:ListItem>3</asp:ListItem>
<asp:ListItem>4</asp:ListItem>
<asp:ListItem>5</asp:ListItem>
<asp:ListItem>6</asp:ListItem>
</asp:RadioButtonList>
<br />

<asp:Label ID="Label4" runat="server" Text="2. What is the capital of India?" /><br />
<asp:RadioButtonList ID="q2" runat="server">
<asp:ListItem>Mumbai</asp:ListItem>
<asp:ListItem>Delhi</asp:ListItem>
<asp:ListItem>Chennai</asp:ListItem>
<asp:ListItem>Kolkata</asp:ListItem>
</asp:RadioButtonList>
<br />

<asp:Label ID="Label5" runat="server" Text="3. Who wrote 'Hamlet'?" /><br />


<asp:RadioButtonList ID="q3" runat="server">
<asp:ListItem>Charles Dickens</asp:ListItem>
<asp:ListItem>William Wordsworth</asp:ListItem>
<asp:ListItem>William Shakespeare</asp:ListItem>
<asp:ListItem>John Milton</asp:ListItem>
</asp:RadioButtonList>
<br />

<asp:Button ID="btnSubmit" runat="server"


Text="Submit Answers"
OnClick="btnSubmit_Click" />
<br /><br />

<asp:Label ID="lblResult" runat="server"


Font-Bold="true"
ForeColor="Blue" />

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

[Link]:
using System;

namespace WebApplication28
{
public partial class _Default : [Link]
{
protected void btnSubmit_Click(object sender, EventArgs e)
{
if ([Link]([Link]) ||
[Link] == -1 ||
[Link] == -1 ||
[Link] == -1)
{
[Link]([Link](), "alert",
"alert('Please enter your name and answer all questions.');", true);
return;
}
int score = 0;

if ([Link] == 1) score++; // 4
if ([Link] == 1) score++; // Delhi
if ([Link] == 2) score++; // Shakespeare

[Link] = "Hello, <b>" + [Link] + "</b><br/>" +


"Subject: <b>" + [Link] + "</b><br/>" +
"Your Score: <b>" + score + " / 3</b>";
}
}
}

You might also like