0% found this document useful (0 votes)
13 views10 pages

AWP Unit4

The document provides an overview of data binding in web applications, explaining single value binding and repeated value binding, along with their use cases and benefits. It also discusses various data controls like FormView, DetailsView, and GridView, detailing their purposes, features, and code examples. Additionally, it covers connected and disconnected data access methods, types of relationships among database tables, and the ADO.NET model for data access in .NET applications.

Uploaded by

pranavkadam1205
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)
13 views10 pages

AWP Unit4

The document provides an overview of data binding in web applications, explaining single value binding and repeated value binding, along with their use cases and benefits. It also discusses various data controls like FormView, DetailsView, and GridView, detailing their purposes, features, and code examples. Additionally, it covers connected and disconnected data access methods, types of relationships among database tables, and the ADO.NET model for data access in .NET applications.

Uploaded by

pranavkadam1205
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

Q1) What is Data Binding?

· Data binding means linking the data in your program (like variables,
database, arrays) with the controls on a web page (like TextBox, Label,
GridView).
· When data changes, the control shows the new value.
· This makes web apps dynamic and reduces extra coding.

1. Single Value Binding


· Definition: Binding one field or one record to a control.
· Purpose: To display or edit a single piece of data at a time.
· How it works:
o The control is linked to a variable or one column from the
database.
o When the value changes in the source, it is shown in the control.
· Examples:
o A TextBox showing the name of a student.
o A Label displaying “Your balance = ₹5000”.
o A DropDownList showing the selected department.
· Controls Used: TextBox, Label, RadioButton, DropDownList (single
select).
· Use Cases:
o Profile pages → show only one student’s personal details.
o Forms → where only one record is edited at a time.
· Benefits: Simple, easy to use, less coding.

2. Repeated Value Binding


· Definition: Binding a collection of records (multiple values) to a control.
· Purpose: To display lists, tables, or repeated sets of data.
· How it works:
o The control is connected to a database table, query result, or
collection.
o Each record is displayed in a repeated format (row or item).
· Examples:
o A GridView showing all students (Roll No, Name, Marks).
o A ListBox showing all courses in the semester.
o A DropDownList filled with product categories from a shop
database.
· Controls Used: GridView, DataList, Repeater, ListBox, DropDownList
(multi).
· Use Cases:
o Student list page → show data of all students.
o Product catalog in online shopping websites.
o Employee directory in a company intranet.
· Benefits: Saves time, shows bulk data easily, automatically updates
when database changes

Point Single Value Binding Repeated Value


Binding
1. Definition Connects one data item Connects multiple data
to a control. items (collection) to a
control.
2. Data Source Uses a single field or Uses a table, query
variable. result, or collection.
3. Controls Used TextBox, Label, GridView, DataList,
DropDownList (single), Repeater, ListBox,
RadioButton. DropDownList
(multiple).
4. Output Displays or edits only Displays lists, tables, or
one record/field. sets of records.
5. Use Case Profile page, login form, Product catalog,
single student details. student list, reports,
dropdown from DB.
6. Complexity Simple, easy to More complex, handles
implement. large sets of data.

Q2 . Data Controls
· GridView
· DetailsView
· FormView

1. Form View
Purpose:
Form View is used to display, edit, insert, or delete a single record at a time
in a more flexible and customizable way than a grid.

Key Points:

· Displays one record from a data source at a time.


· Allows editing, inserting, and deleting a record.
· Fully template-based, so you can define exactly how fields appear.
· Useful when you need a custom layout, unlike GridView which is
tabular.
· Can work with data sources like SqlDataSource or ObjectDataSource.

Modes of FormView:

1. ReadOnly – Just display data.


2. Edit – Modify existing data.
3. Insert – Add new data.

Code :

private void BindFormView()

{ SqlDataAdapter adapter = new SqlDataAdapter("SELECT * FROM


Employee",

"Data Source=COMP105;Initial Catalog=Patkar;Integrated


Security=True");

DataSet ds = new DataSet();

adapter.Fill(ds);

FormView1.DataSource = ds;

FormView1.DataBind();

}
protected void FormView1_PageIndexChanging(object sender,
FormViewPageEventArgs e)

{ FormView1.PageIndex = e.NewPageIndex;

BindFormView();

2. Details View
Purpose:
Details View is used to display a single record in a tabular (row-by-row)
format with automatic support for editing, inserting, and deleting.

Key Points:

· Automatically displays fields in a table (one field per row).


· Supports automatic paging, editing, inserting, and deleting without
much template customization.
· Simpler than FormView if you want default table-style presentation.
· Can be bound to SqlDataSource or ObjectDataSource.

Code

private void BindDetailsView()

{ SqlDataAdapter adapter = new SqlDataAdapter("SELECT * FROM


Employee",

"Data Source=COMP105;Initial Catalog=Patkar;Integrated


Security=True");

DataSet ds = new DataSet();

adapter.Fill(ds);

DetailsView1.DataSource = ds;

DetailsView1.DataBind();

protected void DetailsView1_PageIndexChanging(object sender,


DetailsViewPageEventArgs e)
{ DetailsView1.PageIndex = e.NewPageIndex;

BindDetailsView();

Feature FormView DetailsView


Layout Fully customizable Table format (rows
(templates) auto-generated)
Data Display One record at a time One record at a time
Editing Supported via Supported
templates automatically
Inserting Supported via Supported
templates automatically
Flexibility High (custom UI Low (predefined table
possible) style)
Use Case When you want custom When you want quick
look default table view

3. What is GridView?
The GridView is a powerful, tabular data-bound control in ASP.NET.
It allows developers to display, edit, delete, sort, and paginate records
easily.
It’s often used to show results from a database query.

1. Formatting the GridView


GridView allows custom formatting using properties like HeaderStyle,
RowStyle, AlternatingRowStyle, and FooterStyle. Developers can apply CSS
for better appearance. Formatting enhances readability, for example, using
alternating row colors, bold headers, and footer summaries. This makes large
data tables more user-friendly and visually organized for better data
interpretation.

2. Selecting a GridView Row


The GridView supports selecting rows using a Select button with
AutoGenerateSelectButton = true. Selecting retrieves row values, often
displayed in another control such as DetailsView or FormView. It is widely
used when users need to drill down into a record’s details or perform specific
operations on selected rows.
3. Editing with the GridView
The GridView has inline editing capabilities with AutoGenerateEditButton =
true. On clicking Edit, fields change to editable controls like textboxes. Users
can modify data, then click Update to save changes to the database or
Cancel to discard. This feature enables quick, user-friendly updates without
navigating away from the table.

4. Sorting and Paging the GridView


Sorting is enabled with AllowSorting = true, letting users click column
headers to arrange data in ascending or descending order. Paging, enabled
with AllowPaging = true, divides data into pages, making navigation easier in
large datasets. Together, sorting and paging improve efficiency, usability,
and performance when handling big data tables.

5. Using GridView Templates


Templates give developers complete control over GridView’s layout. They
include ItemTemplate, EditItemTemplate, and FooterTemplate. Instead of
plain text, templates can display images, hyperlinks, buttons, or custom
controls. They also allow advanced functionality, like integrating “Buy Now”
buttons or displaying product images, making GridView highly customizable
and suitable for modern applications.

6. The DetailsView and FormView


DetailsView shows one record at a time in a table layout, supporting editing
and inserting. FormView is similar but offers more flexibility through
templates for custom layouts. Both work with GridView: users select a row in
GridView, and its details are shown in DetailsView or FormView for deeper
interaction.

Q3. Connected Data Access (Direct Architecture)


· Connected data access means the application stays continuously
linked to the database while performing operations. Data is read
directly, usually in a forward-only and read-only way. It gives quick and
real-time access but uses more resources since the connection
remains open. Best suited for small, fast tasks like fetching immediate
results.

Advantages of Connected Data Access


· Provides real-time and up-to-date results since the connection is
always active.
· Faster for small data operations as it directly communicates with the
database.
· Uses DataReader, which is lightweight and efficient for forward-only,
read-only tasks.
· Best suited for quick queries and applications where live data is
critical.

Disconnected Data Access (Indirect Architecture)


· Disconnected data access means the application connects to the
database only for a short time, fetches the required data, and then
closes the connection. The data is stored locally in memory and can be
used without keeping the connection open. This saves resources,
supports many users, and is ideal for web or multi-user applications.

Advantages of Disconnected Data Access


· Saves database resources by closing the connection after fetching
data.
· Data can be worked on offline since it is stored in memory (Dataset).
· Supports large-scale, multi-user applications without overloading the
database.
· Changes made in memory can later be updated back to the database.
· Flexible and safer for web-based applications.
Feature Connected Data Access Disconnected Data Access
Connection Stays open while fetching Opens only to fetch/update,
data then closes
Objects Used DataReader DataAdapter + DataSet
Nature Real-time, always up-to-date Works offline with temporary
copy
Speed Faster for small tasks Slightly slower due to in-
memory storage
Resource Consumes more database Saves resources, scalable for
Usage resources many users
Read/Write Forward-only, read-only Can read, update, and
modify data
Best For Small, quick operations Large or web-based apps
needing live data with many users

Q4. Types of relationship among table


In databases, relationships define how tables connect with each other using
keys (Primary Key & Foreign Key). Here are the main types of relationships
among tables explained simply:
1. One-to-One Relationship
· Each row in Table A relates to only one row in Table B.
· Example: A person and their unique passport.
· Used when data is split into multiple tables for clarity or security.

2️. One-to-Many Relationship


· A row in Table A can relate to multiple rows in Table B, but each row in
B relates to only one row in A.
· Example: One customer can place many orders.
· This is the most common relationship in databases.

3️. Many-to-Many Relationship


· Rows in Table A can relate to many rows in Table B, and vice versa.
· Example: Students and Courses (a student can take many courses, a
course can have many students).
· Usually implemented using a junction/bridge table with foreign keys.

Q5. DO.NET Model


ADO.NET is the data access technology in .NET used to connect applications
with data sources like SQL Server, Oracle, or XML. It provides classes to
fetch, manipulate, and update data. The model works on two approaches:
Connected and Disconnected.

🔑 Components of ADO.NET Model


1. Data Provider
a. Responsible for connecting to a database, executing commands,
and retrieving results.
b. Examples: SqlConnection, SqlCommand, SqlDataReader.
c. Works mainly in connected mode.
2. Connection Object
a. Establishes a link between application and database.
b. Example: SqlConnection.
3. Command Object
a. Used to run SQL queries, stored procedures, or commands.
b. Example: SqlCommand.
4. DataReader
a. Reads data in a fast, forward-only, read-only manner.
b. Best for real-time quick access.
5. DataAdapter
a. Acts as a bridge between the database and Dataset.
b. Fills data into Dataset and updates changes back to the
database.
6. Dataset
a. A disconnected, in-memory representation of data.
b. Can store multiple tables, relations, and constraints.
c. Works offline.

🟢 Two Models in ADO.NET


1. Connected Model – Uses DataReader for real-time, fast, read-only
access.
2. Disconnected Model – Uses DataAdapter and Dataset for offline storage
and updates.

You might also like