0% found this document useful (0 votes)
8 views131 pages

Programming All Lab Program

The document outlines the implementation of various web applications using ASP.NET, showcasing different controls such as TextBoxes, RadioButtons, DropDownLists, and CheckBoxLists. Each section includes the HTML structure and corresponding C# code to handle user input and display results. The applications cover functionalities like user registration, course selection, and validation of input data.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views131 pages

Programming All Lab Program

The document outlines the implementation of various web applications using ASP.NET, showcasing different controls such as TextBoxes, RadioButtons, DropDownLists, and CheckBoxLists. Each section includes the HTML structure and corresponding C# code to handle user input and display results. The applications cover functionalities like user registration, course selection, and validation of input data.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

1.

Create an exposure of Web Applications and


tools

PROGRAM:
[Link]:

<%@ Page Language="C#" AutoEventWireup="true"


CodeFile="[Link]" Inherits="_Default" %>

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


"[Link]

<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" Height="30px" Text="Enter


your name:" Width="130px"></asp:Label>

&nbsp;

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

<br />

<asp:Label ID="Label2" runat="server" Height="30px" Text="Select


your gender:" Width="130px"></asp:Label>

&nbsp;

<asp:RadioButton ID="RadioButton1" runat="server"


GroupName="Gender" Text="Male" />

&nbsp;

<asp:RadioButton ID="RadioButton2" runat="server"


GroupName="Gender" Text="Female" />&nbsp;<br />
<br />

<asp:Label ID="Label3" runat="server" Height="30px" Text="Select


your course:" Width="130px"></asp:Label>

&nbsp;

<asp:DropDownList ID="DropDownList1" runat="server">

<asp:ListItem>BCA</asp:ListItem>

<asp:ListItem>[Link]</asp:ListItem>

<asp:ListItem>MCA</asp:ListItem>

<asp:ListItem>[Link]</asp:ListItem>

</asp:DropDownList>&nbsp;<br />

<br />

<asp:Button ID="Button1" runat="server" Height="30px"


Text="Submit" Width="100px" OnClick="Button1_Click" />&nbsp;<br />

<br />

<asp:Label ID="Label4" runat="server" Height="30px"


Width="250px"></asp:Label>&nbsp;</div>

</form>

</body>

</html>
[Link] (Design Window):

[Link]:

using System;

using [Link];

using [Link];

using [Link];

using [Link];

using [Link];

using [Link];

using [Link];

using [Link];
public partial class _Default : [Link]

protected void Page_Load(object sender, EventArgs e)

// Button1_Click event: Runs when the button is clicked

protected void Button1_Click(object sender, EventArgs e)

// Get the value from the TextBox (default ID: TextBox1)

string name = [Link];

// Get the selected value from the RadioButtons (default ID:


RadioButton1)

string gender = [Link] ? "Male" : "Female";

// Get the selected value from the DropDownList (default ID:


DropDownList1)

string course = [Link];

// Display the values in the Label (default ID: Label4)

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

"Your gender is " + gender + ".<br />" +

"You have selected " + course + ".";

}
OUTPUT:

2. Implement the HTML Controls

PROGRAM:
[Link]:

<%@ Page Language="C#" AutoEventWireup="true"


CodeFile="[Link]" Inherits="_Default" %>

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


"[Link]

<html xmlns="[Link]

<head id="Head1" 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>

<!-- Name Control -->

<label for="txtName">Enter your name:</label>

&nbsp;&nbsp;

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

<br /><br />

<!-- Email Control -->

<label for="txtEmail">Enter your email:</label>

&nbsp;&nbsp;

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

<br /><br />

<!-- Phone Control -->

<label for="txtPhone">Enter your phone number:</label>

&nbsp;&nbsp;

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

<br /><br />

<!-- Age Control -->

<label for="txtAge">Enter your age:</label>

&nbsp;&nbsp;

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

<br /><br />

<!-- Button Control -->


<input type="submit" id="btnSubmit" runat="server"
value="Submit" onserverclick="btnSubmit_ServerClick" />

<br /><br />

<!-- Label to display results -->

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

</div>

</form>

</body>

</html>

[Link]:

using System;

using [Link];

using [Link];

public partial class _Default : [Link]

// Page_Load event: Runs every time the page is loaded

protected void Page_Load(object sender, EventArgs e)

// btnSubmit_ServerClick event: Runs when the button is clicked

protected void btnSubmit_ServerClick(object sender, EventArgs e)

// Get the value from the TextBox

string name = [Link];


// Get the value from the Email field

string email = [Link];

// Get the value from the Phone field

string phone = [Link];

// Get the value from the Age field

string age = [Link];

// Variables to store parsed values

int phoneNumber;

int userAge;

// Validate Phone (ensure it is an integer)

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

[Link] = "Invalid phone number. Please enter a valid


integer.";

return;

// Validate Age (ensure it is an integer)

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

[Link] = "Invalid age. Please enter a valid integer.";

return;

}
// Validate Email (basic validation)

if (![Link]("@") || ![Link]("."))

[Link] = "Invalid email address. Please enter a valid


email.";

return;

// Display the values in the Span (default ID: spnResult)

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

"Your email is: " + email + "<br />" +

"Your phone number is: " + phoneNumber + "<br />" +

"Your age is: " + userAge;

OUTPUT:
3. Implement the Server Controls

PROGRAM:
[Link]:

<%@ Page Language="C#" AutoEventWireup="true"


CodeFile="[Link]" Inherits="_Default" %>

<!DOCTYPE html>

<html xmlns="[Link]

<head id="Head1" 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>

<!-- Label for name -->

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


name:"></asp:Label>

&nbsp;&nbsp;

<!-- TextBox for name -->

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

<br /><br />

<!-- Label for email -->


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

&nbsp;&nbsp;

<!-- TextBox for email -->

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

<br /><br />

<!-- Label for phone number -->

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


number:"></asp:Label>

&nbsp;&nbsp;

<!-- TextBox for phone number -->

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

<br /><br />

<!-- Label for exam selection -->

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


exam:"></asp:Label>

&nbsp;&nbsp;

<!-- DropDownList for exam selection -->

<asp:DropDownList ID="DropDownList1" runat="server">

<asp:ListItem Text="Java" Value="Java"></asp:ListItem>

<asp:ListItem Text="C++" Value="C++"></asp:ListItem>

<asp:ListItem Text=".NET" Value=".NET"></asp:ListItem>

<asp:ListItem Text="Javacript"
Value="Javacript"></asp:ListItem>

</asp:DropDownList>

<br /><br />

<!-- Button to register -->


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

<br /><br />

<!-- Label to display registration details -->

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

</div>

</form>

</body>

</html>

[Link] (Design Window):

[Link]:

using System;

using [Link];
public partial class _Default : [Link]

protected void Page_Load(object sender, EventArgs e)

protected void Button1_Click(object sender, EventArgs e)

// Get user input

string name = [Link];

string email = [Link];

string phone = [Link];

string exam = [Link];

// Display registration details

[Link] = "<b>Thank you for registering!</b><br />" +

"Name: " + name + "<br />" +

"Email: " + email + "<br />" +

"Phone: " + phone + "<br />" +

"Exam: " + exam;

}
OUTPUT:

4. Web Application using Web Controls

PROGRAM:
[Link]:

<%@ Page Language="C#" AutoEventWireup="true"


CodeFile="[Link]" Inherits="_Default" %>

<!DOCTYPE html>

<html xmlns="[Link]

<head id="Head1" runat="server">

<title>User Registration Form</title>

</head>

<body>

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

<div>

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


<!-- Label for name -->

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


name:"></asp:Label>

&nbsp;&nbsp;

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

<br /><br />

<!-- Label for gender selection -->

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


Gender:"></asp:Label>

&nbsp;&nbsp;<br />

<br />

<asp:RadioButtonList ID="RadioButtonList1" runat="server">

<asp:ListItem>Male</asp:ListItem>

<asp:ListItem>Female</asp:ListItem>

</asp:RadioButtonList>

<br />

<!-- Label for course selection -->

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


Course:"></asp:Label>

&nbsp;&nbsp;

<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 />

<!-- Label for selecting skills -->


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

<br />

<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 to submit form -->

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


OnClick="Button1_Click" />

<br /><br />

<!-- Label to display registration details -->

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

</div>

</form>

</body>

</html>

[Link] (Design Window):


[Link]:

using System;

using [Link];

using [Link];

public partial class _Default : [Link]

// Page_Load event: Runs every time the page is loaded or refreshed

protected void Page_Load(object sender, EventArgs e)

// Initialization code can be added here if required

// Button1_Click event: Executes when the Register button is clicked


protected void Button1_Click(object sender, EventArgs e)

// Retrieving user input from TextBox

string name = [Link];

// Retrieving selected gender from RadioButtonList

string gender = [Link];

// Retrieving selected course from DropDownList

string course = [Link];

// Creating a list to store selected skills from CheckBoxList

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

// Looping through CheckBoxList items to check which skills are


selected

foreach ([Link] item in


[Link])

if ([Link]) // If checkbox is checked, add the value to skills


list

[Link]([Link]);

//Convert List<string> to string[] before using [Link]()

string selectedSkills = [Link] > 0 ? [Link](", ",


[Link]()) : "None";
// Displaying registration details dynamically in Label5

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

"Name: " + name + "<br />" +

"Gender: " + gender + "<br />" +

"Course: " + course + "<br />" +

"Skills: " + selectedSkills;

OUTPUT:

5. Web Application using List Controls


PROGRAM:
[Link]:

<%@ Page Language="C#" AutoEventWireup="true"


CodeFile="[Link]" Inherits="_Default" %>

<!DOCTYPE html>

<html xmlns="[Link]

<head id="Head1" runat="server">

<title>Web Application using List Controls</title>

</head>

<body>

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

<div>

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


Controls</h1>

<!-- RadioButtonList Control -->

<asp:Label ID="Label3" 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 />

<!-- DropDownList Control -->

<asp:Label ID="Label1" runat="server" Text="Select a


Course:"></asp:Label><br />

<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 />

<!-- ListBox Control (Multiple Selection Enabled) -->

<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 />

<!-- CheckBoxList Control -->

<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 />
<!-- Submit Button -->

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


OnClick="Button1_Click" />

<br /><br />

<!-- Label to display selected values -->

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

</div>

</form>

</body>

</html>

[Link] (Design Window):


[Link]:

using System;

using [Link];

using [Link];

public partial class _Default : [Link]

protected void Page_Load(object sender, EventArgs e)

// Runs every time the page loads or refreshes

protected void Button1_Click(object sender, EventArgs e)

// Retrieve selected gender

string gender = [Link];

// Retrieve selected course

string selectedCourse = [Link];

// Retrieve selected subjects from ListBox

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

foreach ([Link] item in [Link])

if ([Link])

[Link]([Link]); // Using .Text to get subject


names

}
}

// Retrieve selected skills from CheckBoxList

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

foreach ([Link] item in


[Link])

if ([Link])

[Link]([Link]); // Using .Text for skill names

//Convert List<string> to string[] before using [Link]()

string subjects = [Link] > 0 ? [Link](", ",


[Link]()) : "None";

string skills = [Link] > 0 ? [Link](", ",


[Link]()) : "None";

// Display selected values

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

"<b>Selected Course:</b> " + selectedCourse + "<br />"


+

"<b>Selected Subjects:</b> " + subjects + "<br />" +

"<b>Selected Skills:</b> " + skills;

}
OUTPUT:

6. Web Page with Rich Controls, User Input


Validation, and File Upload

PROGRAM:
[Link]:

<%@ Page Language="C#" AutoEventWireup="true"


CodeFile="[Link]" Inherits="_Default" %>

<!DOCTYPE html>

<html xmlns="[Link]

<head id="Head1" runat="server">

<title>Web Application Using Rich Controls</title>

</head>
<body>

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

<div>

<h1 style="text-align:center;">Web Page with Rich Controls, User


Input Validation, and File Upload</h1>

<!-- Name Input with Validation -->

<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"></asp:RequiredFieldValidator>

<br /><br />

<!-- Email Input with Validation -->

<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"></asp:RequiredFieldValidator>

<asp:RegularExpressionValidator ID="revEmail" runat="server"

ControlToValidate="txtEmail"

ValidationExpression="^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$"

ErrorMessage="Invalid email format!"


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

<br /><br />

<!-- Calendar Control -->


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

<br />

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

<br /><br />

<!-- File Upload Control -->

<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"></asp:RequiredFieldValidator>

<br /><br />

<!-- Submit Button -->

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


OnClick="btnSubmit_Click" />

<br /><br />

<!-- Display Output -->

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

<br /><br />

<!-- Image Preview -->

<asp:Image ID="imgUploaded" runat="server" Visible="false"


Width="300px" Height="200px" />

</div>

</form>

</body>
</html>

[Link] (Design Window):

[Link]:

using System;

using [Link]; // Required for file handling

using [Link];

public partial class _Default : [Link]

protected void Page_Load(object sender, EventArgs e)

// Runs every time the page loads or refreshes

protected void btnSubmit_Click(object sender, EventArgs e)


{

// Retrieve input values

string name = [Link];

string email = [Link];

string selectedDate = [Link]();

// Ensure a date is selected

if ([Link] == [Link])

selectedDate = "No date selected!";

// File Upload Handling

string filePath = "";

if ([Link])

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


Corrected Path usage

filePath = "~/Uploads/" + fileName;

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

// Display uploaded image

[Link] = filePath;

[Link] = true;

else

filePath = "No file uploaded.";

}
// Display output

[Link] = "<b>Name: </b>" + name + "<br />" +

"<b>Email: </b>" + email + "<br />" +

"<b>Selected Date: </b>" + selectedDate + "<br />" +

"<b>Uploaded File: </b>" + filePath;

OUTPUT:
O/P Type 1 (Not Valid):
O/P Type 2 (Valid):

7. Web application using Data Controls.


PROGRAM:
[Link] [Design Window]:
[Link] [Source Code]:

<%@ Page Language="VB" AutoEventWireup="false"


CodeFile="[Link]" Inherits="_Default" %>

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


"[Link]

<html xmlns="[Link] >

<head runat="server">

<title>Data Controls using Web Application</title>

</head>

<body>

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

<div>

<h1 style="text-align:center;">Web application using Data


Controls</h1>

<asp:Label ID="Label1" runat="server" Height="25px" Text="Book


No" Width="85px"></asp:Label>

&nbsp; &nbsp;<asp:TextBox ID="txtBookNo" runat="server"


Height="22px" Width="155px"></asp:TextBox>&nbsp;<br />

<br />

<asp:Label ID="Label2" runat="server" Height="25px" Text="Book


Name" Width="85px"></asp:Label>

&nbsp; &nbsp;<asp:TextBox ID="txtBookName" runat="server"


Height="22px" Width="155px"></asp:TextBox>&nbsp;<br />

<br />

<asp:Label ID="Label3" runat="server" Height="25px"


Text="Publish Year" Width="85px"></asp:Label>

&nbsp; &nbsp;<asp:TextBox ID="txtYear" runat="server"


Height="22px" Width="155px"></asp:TextBox>&nbsp;<br />

<br />
<asp:Button ID="btnInsert" runat="server" Height="25px"
Text="Insert" Width="70px" />&nbsp;<br />

<br />

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


AutoGenerateColumns="False" AutoGenerateDeleteButton="True"

AutoGenerateEditButton="True" DataKeyNames="BookNo"
DataSourceID="AccessDataSource1"

Height="141px" Width="580px">

<Columns>

<asp:BoundField DataField="BookNo" HeaderText="BookNo"


ReadOnly="True" SortExpression="BookNo" />

<asp:BoundField DataField="BookName"
HeaderText="BookName" SortExpression="BookName" />

<asp:BoundField DataField="PublishYear"
HeaderText="PublishYear" SortExpression="PublishYear" />

</Columns>

</asp:GridView>

</div>

<br />

<asp:AccessDataSource ID="AccessDataSource1" runat="server"


DataFile="~/App_Data/[Link]"

DeleteCommand="DELETE FROM Books WHERE BookNo = ?"

InsertCommand="INSERT INTO Books (BookNo, BookName,


PublishYear) VALUES (?, ?, ?)"

SelectCommand="SELECT * FROM Books"

UpdateCommand="UPDATE Books SET BookName = ?, PublishYear


= ? WHERE BookNo = ?">

<InsertParameters>

<asp:Parameter Name="BookNo" Type="Int32" />

<asp:Parameter Name="BookName" Type="String" />


<asp:Parameter Name="PublishYear" Type="Int32" />

</InsertParameters>

<UpdateParameters>

<asp:Parameter Name="BookName" Type="String" />

<asp:Parameter Name="PublishYear" Type="Int32" />

<asp:Parameter Name="BookNo" Type="Int32" />

</UpdateParameters>

<DeleteParameters>

<asp:Parameter Name="BookNo" Type="Int32" />

</DeleteParameters>

</asp:AccessDataSource>

</form>

</body>

</html>

[Link] [Visual Basic (Backend Code)]:

Partial Class _Default

Inherits [Link]

Protected Sub btnInsert_Click(ByVal sender As Object, ByVal e As


[Link]) Handles [Link]

' Check if any textbox is empty

If [Link] = "" Or [Link] = "" Or [Link] = ""


Then

[Link]("<script>alert('Please fill all fields.');</script>")

Exit Sub

End If
' Set values to InsertParameters

[Link]("BookNo").DefaultValue =
[Link]

[Link]("BookName").DefaultValue =
[Link]

[Link]("PublishYear").DefaultValue =
[Link]

' Insert the record

[Link]()

' Refresh the GridView to show new record

[Link]()

' Clear the textboxes for next entry

[Link] = ""

[Link] = ""

[Link] = ""

End Sub

End Class
OUTPUT:
After Values Inserted:

Values Editing:
After Values Edited:

After Values Deleted:


8. Data binding with Web controls.
[Link] [Design Window]:
[Link] [Source Code]:

<%@ Page Language="VB" AutoEventWireup="false"


CodeFile="[Link]" Inherits="_Default" %>

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


"[Link]

<html xmlns="[Link] >


<head runat="server">
<title>Data Binding with Web controls</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<h1 style="text-align:center;">Data Binding with Web controls</h1>
<asp:Label ID="Label1" runat="server" Font-Bold="True"
Height="25px" Text="Choose Books Title (DropDownList):"
Width="300px"></asp:Label>&nbsp;<br />
<asp:DropDownList ID="ddlTitle" runat="server"
DataSourceID="AccessDataSource1" DataTextField="BookTitle"
DataValueField="BookTitle">
</asp:DropDownList>&nbsp;<br />
<br />
<asp:Label ID="Label2" runat="server" Font-Bold="True"
Height="25px" Text="Choose Author Name (ListBox):"
Width="300px"></asp:Label>&nbsp;<br />
<asp:ListBox ID="lstAuthor" runat="server"
DataSourceID="AccessDataSource1" DataTextField="AuthorName"
DataValueField="AuthorName"></asp:ListBox>&nbsp;<br />
<br />
<asp:Label ID="Label3" runat="server" Font-Bold="True"
Height="25px" Text="Choose Publish Year (RadioButtonList):"
Width="300px"></asp:Label>&nbsp;<br />
<asp:RadioButtonList ID="rblYear" runat="server"
DataSourceID="AccessDataSource1" DataTextField="PublishYear"
DataValueField="PublishYear">
</asp:RadioButtonList></div>
<br />
<asp:Button ID="btnShow" runat="server" Height="25px"
Text="Submit" Width="100px" />&nbsp;<br />
<br />
<asp:Label ID="lblResult" runat="server" Height="50px"
Width="300px"></asp:Label>&nbsp;<br />
<br />
<asp:AccessDataSource ID="AccessDataSource1" runat="server"
DataFile="~/App_Data/[Link]" SelectCommand="SELECT * FROM
LibraryItems"></asp:AccessDataSource>
</form>
</body>
</html>

[Link] [Visual Basic]:


Partial Class _Default
Inherits [Link]
Protected Sub btnShow_Click(ByVal sender As Object, ByVal e As
[Link]) Handles [Link]
' Combine all selected values into one label with <br> line breaks
[Link] = "<b> Selected Values </b> <br /><br />" & _
"<b> Book Title: </b>" & [Link] & "<br
/><br />" & _
"<b> Author Name: </b>" & [Link] &
"<br /><br />" & _
"<b> Published Year: </b>" & [Link]
End Sub
End Class
OUTPUT:
9. Data binding with Data controls.
PROGRAM:
[Link] [Design Window]:
[Link] [Source Code]:
<%@ Page Language="VB" AutoEventWireup="false"
CodeFile="[Link]" Inherits="_Default" %>

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


"[Link]

<html xmlns="[Link] >


<head runat="server">
<title>Data Binding with Data Controls</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<h1 style="text-align:center;">Data Binding with Data Controls</h1>
<asp:GridView ID="GridView1" runat="server" Height="119px"
Width="450px" AllowPaging="True" AutoGenerateColumns="False"
DataSourceID="AccessDataSource1">
<Columns>
<asp:BoundField DataField="BookTitle" HeaderText="BookTitle"
SortExpression="BookTitle" />
<asp:BoundField DataField="AuthorName"
HeaderText="AuthorName" SortExpression="AuthorName" />
<asp:BoundField DataField="PublishYear"
HeaderText="PublishYear" SortExpression="PublishYear" />
</Columns>
</asp:GridView>

</div>
<br />
<asp:DetailsView ID="DetailsView1" runat="server" Height="120px"
Width="450px" AllowPaging="True" AutoGenerateRows="False"
DataSourceID="AccessDataSource1">
<Fields>
<asp:BoundField DataField="BookTitle" HeaderText="BookTitle"
SortExpression="BookTitle" />
<asp:BoundField DataField="AuthorName"
HeaderText="AuthorName" SortExpression="AuthorName" />
<asp:BoundField DataField="PublishYear"
HeaderText="PublishYear" SortExpression="PublishYear" />
</Fields>
</asp:DetailsView>
<br />
<asp:FormView ID="FormView1" runat="server" Height="50px"
Width="400px" AllowPaging="True"
DataSourceID="AccessDataSource1">
<EditItemTemplate>
BookTitle:
<asp:TextBox ID="BookTitleTextBox" runat="server" Text='<%#
Bind("BookTitle") %>'>
</asp:TextBox><br />
AuthorName:
<asp:TextBox ID="AuthorNameTextBox" runat="server" Text='<
%# Bind("AuthorName") %>'>
</asp:TextBox><br />
PublishYear:
<asp:TextBox ID="PublishYearTextBox" runat="server" Text='<
%# Bind("PublishYear") %>'>
</asp:TextBox><br />
<asp:LinkButton ID="UpdateButton" runat="server"
CausesValidation="True" CommandName="Update"
Text="Update">
</asp:LinkButton>
<asp:LinkButton ID="UpdateCancelButton" runat="server"
CausesValidation="False" CommandName="Cancel"
Text="Cancel">
</asp:LinkButton>
</EditItemTemplate>
<InsertItemTemplate>
BookTitle:
<asp:TextBox ID="BookTitleTextBox" runat="server" Text='<%#
Bind("BookTitle") %>'>
</asp:TextBox><br />
AuthorName:
<asp:TextBox ID="AuthorNameTextBox" runat="server" Text='<
%# Bind("AuthorName") %>'>
</asp:TextBox><br />
PublishYear:
<asp:TextBox ID="PublishYearTextBox" runat="server" Text='<
%# Bind("PublishYear") %>'>
</asp:TextBox><br />
<asp:LinkButton ID="InsertButton" runat="server"
CausesValidation="True" CommandName="Insert"
Text="Insert">
</asp:LinkButton>
<asp:LinkButton ID="InsertCancelButton" runat="server"
CausesValidation="False" CommandName="Cancel"
Text="Cancel">
</asp:LinkButton>
</InsertItemTemplate>
<ItemTemplate>
BookTitle:
<asp:Label ID="BookTitleLabel" runat="server" Text='<%#
Bind("BookTitle") %>'></asp:Label><br />
AuthorName:
<asp:Label ID="AuthorNameLabel" runat="server" Text='<%#
Bind("AuthorName") %>'>
</asp:Label><br />
PublishYear:
<asp:Label ID="PublishYearLabel" runat="server" Text='<%#
Bind("PublishYear") %>'>
</asp:Label><br />
</ItemTemplate>
</asp:FormView>
<br />
<asp:AccessDataSource ID="AccessDataSource1" runat="server"
DataFile="~/App_Data/[Link]" SelectCommand="SELECT * FROM
Books"></asp:AccessDataSource>
<br />
</form>
</body>
</html>

OUTPUT:
10. Database application to perform insert,
update and delete operations.

[Link][Design]:
PROGRAM:
[Link]:

Public Class Form1

Private Sub Form1_Load(ByVal sender As [Link], ByVal e As


[Link]) Handles [Link]

'TODO: This line of code loads data into the


'Database1DataSet.Table1' table. You can move, or remove it, as needed.

[Link](Me.Database1DataSet.Table1)

End Sub

Private Sub Button1_Click(ByVal sender As [Link], ByVal e As


[Link]) Handles [Link]

[Link]()
End Sub

Private Sub Button2_Click(ByVal sender As [Link], ByVal e As


[Link]) Handles [Link]

[Link]()

[Link](Database1DataSet.Table1)

[Link]("Updated Successfully!")

Exit Sub

End Sub

Private Sub Button3_Click(ByVal sender As [Link], ByVal e As


[Link]) Handles [Link]

[Link]()

[Link](Database1DataSet.Table1)

[Link]("Deleted Successfully!")

End Sub

Private Sub Button4_Click(ByVal sender As [Link], ByVal e As


[Link]) Handles [Link]

[Link]()

End Sub

End Class
INSERT

Inserting Data into Database through Windows


Application:

Inserted Data into Database from Windows Application:


UPDATE

Updating a Data into Database through Windows


Application:

Updated Data into Database from Windows Application:


DELETE

Deleting an inserted Data from Database through


Windows Application:

Deleted Data removed from Database:


OUTPUT:
11. Database application using Data Controls to
perform insert, delete, edit, paging and sorting
operation.

[Link][Design]:
PROGRAM:
[Link]:

Public Class Form1

Private Sub Form1_Load(ByVal sender As [Link], ByVal e As


[Link]) Handles [Link]

'TODO: This line of code loads data into the


'Database1DataSet.Table1' table. You can move, or remove it, as needed.

[Link](Me.Database1DataSet.Table1)

' Clear the ComboBox and auto-load column names

[Link] = Nothing

[Link]()
' Automatically add all column names from the DataTable

For Each column As DataColumn In


[Link]

[Link]([Link])

Next

End Sub

Private Sub btnAdd_Click(ByVal sender As [Link], ByVal e As


[Link]) Handles [Link]

[Link]()

End Sub

Private Sub btnUpdate_Click(ByVal sender As [Link], ByVal e As


[Link]) Handles [Link]

[Link]()

[Link](Database1DataSet.Table1)

[Link]("Updated Successfully!")

Exit Sub

End Sub

Private Sub btnDelete_Click(ByVal sender As [Link], ByVal e As


[Link]) Handles [Link]

[Link]()
[Link](Database1DataSet.Table1)

[Link]("Deleted Successfully!")

End Sub

Private Sub btnExit_Click(ByVal sender As [Link], ByVal e As


[Link]) Handles [Link]

[Link]()

End Sub

Private Sub btnFirst_Click(ByVal sender As [Link], ByVal e As


[Link]) Handles [Link]

[Link]()

End Sub

Private Sub btnLast_Click(ByVal sender As [Link], ByVal e As


[Link]) Handles [Link]

[Link]()

End Sub

Private Sub btnPrevious_Click(ByVal sender As [Link], ByVal e


As [Link]) Handles [Link]

[Link]()
End Sub

Private Sub btnNext_Click(ByVal sender As [Link], ByVal e As


[Link]) Handles [Link]

[Link]()

End Sub

Private Sub btnAsc_Click(ByVal sender As [Link], ByVal e As


[Link]) Handles [Link]

Dim selectedColumn As String = [Link]

If selectedColumn <> "" Then

Try

' Sort ascending

[Link] = selectedColumn & " ASC"

Catch ex As Exception

[Link]("Error: " & [Link])

End Try

Else

[Link]("Please select a column to sort by.")

End If

End Sub

Private Sub btnDesc_Click(ByVal sender As [Link], ByVal e As


[Link]) Handles [Link]
Dim selectedColumn As String = [Link]

If selectedColumn <> "" Then

Try

' Sort descending

[Link] = selectedColumn & " DESC"

Catch ex As Exception

[Link]("Error: " & [Link])

End Try

Else

[Link]("Please select a column to sort by.")

End If

End Sub

End Class

OUTPUT:
CRUD+ OPERATION:
PAGING OPERATION:

SORTING OPERATION:
SORT ↑ (SORT ASCENDING ORDER):

SORT ↓ (SORT DESCENDING ORDER):


12. Implement the xml classes.

PROGRAM:
[Link] [Design Window]:
[Link] [Source Code]:

<%@ Page Language="C#" AutoEventWireup="true"


CodeFile="[Link]" Inherits="_Default" %>

<!DOCTYPE html>

<html xmlns="[Link]

<head>

<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] [C# Code]:

using System;

using [Link];// It's very important to implemet XML in C#

using [Link];

using [Link];

using [Link];

using [Link];

using [Link];

using [Link];

using [Link];

using [Link];

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)

XmlTextWriter writer = new XmlTextWriter(xmlPath, null);

[Link]();

[Link]("Students");

[Link]("Student");
[Link]("Name", "abc");

[Link]("Department", "BCA");

[Link]("Year", "2");

[Link]();

[Link]("Student");

[Link]("Name", "xyz");

[Link]("Department", "BBA");

[Link]("Year", "1");

[Link]();

[Link]();

[Link]();

[Link]();

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

protected void btnRead_Click(object sender, EventArgs e)

XmlTextReader reader = new XmlTextReader(xmlPath);

string output = "";

while ([Link]())

if ([Link] == [Link] && [Link] !=


"Students" && [Link] != "Student")

output += "<b>" + [Link] + ":</b> ";


}

if ([Link] == [Link])

output += [Link] + "<br/>";

[Link]();

[Link] = output;

OUTPUT:
Write XML O/P:
Read XML O/P:
13. Implement Authentication - Authorization.
[Link] [Design View]:
[Link] [Source Code]:
<%@ Page Language="C#" AutoEventWireup="true"
CodeFile="[Link]" Inherits="Login" %>

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


"[Link]

<html xmlns="[Link] >

<head runat="server">

<title>Login</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" /><br


/><br />

Password: <asp:TextBox ID="txtPassword" runat="server"


TextMode="Password" /><br /><br />

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


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

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

</div>

</form>

</body>

</html>
[Link] [C# Code]:
using System;
using [Link];
using [Link];
using [Link];
using [Link];
using [Link];
using [Link];
using [Link];
using [Link];
using [Link];

public partial class Login : [Link]


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

}
protected void btnLogin_Click(object sender, EventArgs e)
{
string username = [Link]();
string password = [Link]();

// Simple authentication (hardcoded)


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] [Design View]:


[Link] [Source Code]:
<%@ Page Language="C#" AutoEventWireup="true"
CodeFile="[Link]" Inherits="AdminPage" %>

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


"[Link]

<html xmlns="[Link] >

<head runat="server">

<title>Admin Page</title>

</head>

<body>

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

<div style="text-align:center;">

<h2>Welcome Admin</h2>

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


/><br /><br />

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


OnClick="btnLogout_Click" />

</div>

</form>

</body>

</html>
[Link] [C# Code]:
using System;
using [Link];
using [Link];
using [Link];
using [Link];
using [Link];
using [Link];
using [Link];
using [Link];
using [Link];

public partial class AdminPage : [Link]


{
protected void Page_Load(object sender, EventArgs e)
{
if (Session["username"] == 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] [Design View]:

[Link] [Source Code]:


<%@ Page Language="C#" AutoEventWireup="true"
CodeFile="[Link]" Inherits="UserPage" %>

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


"[Link]

<html xmlns="[Link] >


<head runat="server">
<title>User Page</title>
</head>
<body>
<form id="form1" runat="server">
<div style="text-align:center;">
<h2>Welcome User</h2>
<asp:Label ID="lblUser" runat="server" ForeColor="Blue"
/><br /><br />
<asp:Button ID="btnLogout" runat="server" Text="Logout"
OnClick="btnLogout_Click" />
</div>
</form>
</body>
</html>

[Link] [C# Code]:


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

public partial class UserPage : [Link]


{
protected void Page_Load(object sender, EventArgs e)
{
if (Session["username"] == 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]");
}
}

OUTPUT:

Login Page [Set as Start Page]:


Admin Page Login Details:

Logged into Admin Page View:


User Page Login Details:

Logged into User Page View:


Invalid Login Details:
14. Ticket reservation using [Link] controls.

PROGRAM:
[Link] [Design Window]:

[Link] [Source Code]:

<%@ Page Language="C#" AutoEventWireup="true"


CodeFile="[Link]" Inherits="_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>

<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>

</body>

</html>
[Link] [C# Code]:

using System;

using [Link];

using [Link];

using [Link];

using [Link];

using [Link];

using [Link];

using [Link];

using [Link];

public partial class _Default : [Link]

protected void Page_Load(object sender, EventArgs e)

protected void btnReserve_Click(object sender, EventArgs e)

if ([Link] == null || [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]();

OUTPUT:
15. Online examination using [Link] controls.
PROGRAM:
[Link] [Design Window]:
[Link] [Source Code]:

<%@ Page Language="C#" AutoEventWireup="true"


CodeFile="[Link]" Inherits="_Default" %>

<!DOCTYPE html>

<html xmlns="[Link]

<head id="Head1" runat="server">

<title>Online Examination - [Link]</title>

</head>

<body>

<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" ForeColor="Black" Font-
Bold="True" />

</div>

</form>

</body>

</html>

[Link] [C# Code]:

using System;

using [Link];

using [Link];

using [Link];

using [Link];

using [Link];

using [Link];

using [Link];

using [Link];

public partial class _Default : [Link]

protected void btnSubmit_Click(object sender, EventArgs e)

// Validate inputs

if ([Link]() == "" ||

[Link] == -1 ||

[Link] == -1 ||

[Link] == -1)

{
// Show alert in browser

[Link]("<script>alert('Please enter your name and


answer all questions.');</script>");

return;

int score = 0;

// Correct Answers:

// Q1: 4 (index 1), Q2: Delhi (index 1), Q3: William Shakespeare
(index 2)

if ([Link] == 1) score++;

if ([Link] == 1) score++;

if ([Link] == 2) score++;

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


"</b>!<br/>" +

"Subject: <b>" + [Link] +


"</b><br/>" +

"Your Score: <b>" + [Link]() + " / 3</b>";

}
OUTPUT:

You might also like