0% found this document useful (0 votes)
99 views3 pages

Web Application Using Data Controls

Uploaded by

gvnbca
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)
99 views3 pages

Web Application Using Data Controls

Uploaded by

gvnbca
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
You are on page 1/ 3

✅ ASP.

NET Web Application Using Data Controls (Without Database)

Aim

To develop an ASP.NET web application using Data Controls (GridView, DetailsView, FormView) in
C#, without connecting to a database.

Procedure

1. Open Visual Studio → Create a new ASP.NET Web Forms Application.

2. Add a Web Form DataControlsDemo.aspx.

3. Design the form with GridView, DetailsView, and FormView.

4. In code-behind, create a DataTable with sample data (StudentID, Name, Age, Course).

5. Bind the DataTable to Data Controls on Page_Load.

6. Run the project to view data in different formats.

Program

DataControlsDemo.aspx

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="DataControlsDemo.aspx.cs"


Inherits="DataControlsApp.DataControlsDemo" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">

<head runat="server">

<title>ASP.NET Data Controls Demo (No DB)</title>

</head>

<body>

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

<h2>ASP.NET Data Controls (Without Database)</h2>

<h3>GridView</h3>

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

BackColor="#f0f0f0" BorderColor="Black" CellPadding="5" />


<h3>DetailsView</h3>

<asp:DetailsView ID="DetailsView1" runat="server" AutoGenerateRows="True" />

<h3>FormView</h3>

<asp:FormView ID="FormView1" runat="server" DefaultMode="ReadOnly">

<ItemTemplate>

Student: <%# Eval("Name") %><br />

Age: <%# Eval("Age") %><br />

Course: <%# Eval("Course") %>

</ItemTemplate>

</asp:FormView>

</form>

</body>

</html>

DataControlsDemo.aspx.cs

using System;

using System.Data;

namespace DataControlsApp

public partial class DataControlsDemo : System.Web.UI.Page

protected void Page_Load(object sender, EventArgs e)

if (!IsPostBack)

// Create DataTable

DataTable dt = new DataTable();

dt.Columns.Add("StudentID", typeof(int));
dt.Columns.Add("Name", typeof(string));

dt.Columns.Add("Age", typeof(int));

dt.Columns.Add("Course", typeof(string));

// Add rows

dt.Rows.Add(1, "Arun", 20, "CSE");

dt.Rows.Add(2, "Priya", 21, "IT");

dt.Rows.Add(3, "Rahul", 22, "ECE");

// Bind to controls

GridView1.DataSource = dt;

GridView1.DataBind();

DetailsView1.DataSource = dt;

DetailsView1.DataBind();

FormView1.DataSource = dt;

FormView1.DataBind();

You might also like