Delivering Excellence in Software Engineering ® 2006. EPAM Systems. All rights reserved. Data Binding in ASP.NET.

Slides:



Advertisements
Similar presentations
Chapter 3 – Web Design Tables & Page Layout
Advertisements

Internetteknologi (ITNET2) Presentation 21: ASP.NET Advanced.
Chapter 10 Database Applications Copyright © 2011 by The McGraw-Hill Companies, Inc. All Rights Reserved. McGraw-Hill.
User Controls, Master Pages, GridView. Content User Controls Styles, Themes, Master Pages Working with Data GridView Muzaffer DOĞAN - Anadolu University2.
Chapter 9 Customizing Data with Web Controls. ASP.NET 2.0, Third Edition2.
Bind Controls to Data by Using Data-Binding Syntax Web Development Fundamentals LESSON 2.5.
Unit 5: Building Presentation Layer Applications with ASP.NET 2.0.
ASP.NET Data Binding. Slide 2 Lecture Overview Understanding the ASP.NET data binding model.
Introduction to Database Processing with ADO.NET.
1 Chapter 12 Working With Access 2000 on the Internet.
Chapter 12: ADO.NET and ASP.NET Programming with Microsoft Visual Basic.NET, Second Edition.
Web Development Using ASP.NET CA – 240 Kashif Jalal Welcome to week – 3-1 of…
Building ASP.NET Applications 2 Lecture 3,4 T. Ahlam Algharasi 4 th Level.
Chapter 7: Creating Database Reports
Tutorial 11: Connecting to External Data
From VS C# 2010 Programming, John Allwork 1 VS2010 C# Programming - DB intro 1 Topics – Database Relational - linked tables SQL ADO.NET objects Referencing.
Philip Wolfe Senior Consultant Sogeti Session 3 - Leveraging Data in ASP.NET 2.0 (Level 200)
Tutorial: Introduction to ASP.NET Internet Technologies and Web Application 4 th February 2010.
Chapter 8 Binding Data to Web Controls. ASP.NET 2.0, Third Edition2.
Chapter 9 Using the SqlDataSource Control. References aspx.
Ch6:creating consistent looking web sites. Master pages Master page defines a combination of fixed content and content place holder to hold the web page(.aspx)
Chapter 10 Managing Data with ASP.NET. ASP.NET 2.0, Third Edition2.
Introduction to ADO.Net and Visual Studio Database Tools ISYS 512.
Overview of Previous Lesson(s) Over View  ASP.NET Pages  Modular in nature and divided into the core sections  Page directives  Code Section  Page.
1 PHP and MySQL. 2 Topics  Querying Data with PHP  User-Driven Querying  Writing Data with PHP and MySQL PHP and MySQL.
10-1 aslkjdhfalskhjfgalsdkfhalskdhjfglaskdhjflaskdhjfglaksjdhflakshflaksdhjfglaksjhflaksjhf.
ASP.Net Web Applications. Characteristics of a typical data driven web application Web Server HTML Graphics Active-X Java Applets HTTP Request ADO / JDBC.
MSIS 5133 Advanced MIS - E-Commerce Spring 2003 Lecture 4: DotNet Technologies - Part 4 Using Controls with Databases Dr. Rathindra Sarathy.
Chapter 81 Building Data-Driven Web Applications Introduction to ASP.NET By Kathleen Kalata.
Chapter 71 Building Data-Driven ASP.NET Applications Introduction to ASP.NET By Kathleen Kalata.
Web Development Using ASP.NET CA – 240 Kashif Jalal Welcome to week – 4-1 of…
ASP.NET Web Server Controls Basic Web Server Controls.
Tutorial 121 Creating a New Web Forms Page You will find that creating Web Forms is similar to creating traditional Windows applications in Visual Basic.
CIS 375—Web App Dev II ASP.NET 10 Database 2. 2 Introduction to Server-Side Data Server-side data access is unique in that Web pages are basically ___________.
Needs for Accessing Database To make your web site more dynamic and maintainable, you can display information on your web pages that are retrieved from.
1 Data Bound Controls II Chapter Objectives You will be able to Use a Data Source control to get data from a SQL database and make it available.
ASP.NET.. ASP.NET Environment ASP.NET is Microsoft's programming framework that enables the development of Web applications and services. It is an easy.
Ventsislav Popov Crossroad Ltd.. 1. ASP.NET Data Source Controls  SqlDataSource  EntityDataSource  ObjectDataSource 2. Entity Data Model and ADO.NET.
Handy separation the report template into pages Handy visual separation of the report template into pages is available in Stimulsoft Reports.Net. You.
CSCI 6962: Server-side Design and Programming Database Manipulation in ASP.
Chapter 8 Working With Databases in ASP.NET. Listing 8.1 – ShowListControls Uses The SqlDataSource control for estabishing database connectivity and.
WaveMaker Visual AJAX Studio 4.0 Training Basics: Building Your First Application Binding Basics.
ASP.NET OPTIMIZATION. Why Optimize? $$$ Whether you build applications for customers or not, enhanced applications save money.
Database Handling, Sessions, and AJAX. Post Back ASP.NET Functionality The IsPostBack method in ASP.NET is similar to the BlackBerry.refresh method –IsPostBack.
Data Access in ASP.NET 2.0 Bradley Millington Program Manager Web Platform and Tools.
Security Attacks CS 795. Buffer Overflow Problem Buffer overflows can be triggered by inputs that are designed to execute code, or alter the way the program.
Data Binding with Tabular Data Control. Objective To understand Dynamic HTML data binding. To be able to sort and filter data directly on the client without.
3 Copyright © 2004, Oracle. All rights reserved. Working in the Forms Developer Environment.
TRAINING SESSIONS.NET Controls.  Standard Controls  Label  Textbox  Checkbox  Button, Image Button, Image control  Radio Button  Literal  Hyperlink.
Reference: “ASP.NET 2.0 Illustrated” by Alex Homer and Dave Sussman. -ch3 illustrated book
Ventsislav Popov Crossroad Ltd.. 1. ASP.NET Data Source Controls  SqlDataSource  EntityDataSource  ObjectDataSource 2. Entity Data Model and ADO.NET.
BlackBerry Applications using Microsoft Visual Studio and Database Handling.
Security Attacks CS 795. Buffer Overflow Problem Buffer overflow Analysis of Buffer Overflow Attacks.
Chapter 5 Introduction To Form Builder. Lesson A Objectives  Display Forms Builder forms in a Web browser  Use a data block form to view, insert, update,
8 Chapter Eight Server-side Scripts. 8 Chapter Objectives Create dynamic Web pages that retrieve and display database data using Active Server Pages Process.
WaveMaker Visual AJAX Studio 4.0 Training Java Script Events.
ASP.NET Data Binding. Slide 2 Lecture Overview Understanding the ASP.NET data binding model.
1 CS 3870/CS 5870: Note07 Prog 4. Master Pages Creating a master page based on another master page MainMasterPage –For all Progs and Tests Prog4MasterPage.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved Address Book Application Introducing Database Programming.
Understand Databound Controls Windows Development Fundamentals LESSON 4.2A.
Module 10: Data Access in ASP.NET. Overview Overview of the ASP.NET Data Access What is Data Access List of Data Source Control What is Data Bound How.
CHAPTER 7 LESSON C Creating Database Reports. Lesson C Objectives  Display image data in a report  Manually create queries and data links  Create summary.
Working with Data Lesson 4. Objectives DataSource Controls A requirement for most modern Web sites is that they be dynamic. –Static pages are not often.
Introduction to Database Processing with ADO.NET
Brief description on how to navigate within this presentation (ppt)
Chapter 10 ADO.
Database Applications
Web Development Using ASP .NET
PROG Advanced Web Apps 2/24/2019 Session 9.2 Data Binding Wendi Jollymore, ACES.
Chapter 10 Accessing Database Files
Presentation transcript:

Delivering Excellence in Software Engineering ® EPAM Systems. All rights reserved. Data Binding in ASP.NET

® EPAM Systems. All rights reserved. What Is Data Binding? Data binding is a solution to a problem that developers used to solve over and over in user-interface applications. In the past, if you wanted to present data to a user, you had to retrieve the data from where it was stored and get it into your application. You then had to write custom code to render the data with graphics, or you could manually populate properties on controls with the data to display it. The way that you approached this would be different for each situation, each type of data, and each type of presentation that you provided. This required a lot of repetitive and error-prone code, which always cries out for a better solution.

® EPAM Systems. All rights reserved. Easily data binding with.Net 2.0 Nearly every dynamic web application performs some kind of data access, and fortunately ASP.NET 2.0 makes this incredibly easy to do. Unlike ASP.NET 1.0, which required developers to write custom code in order retrieve and bind data to server controls, ASP.NET 2.0 enables a declarative solution for data binding which requires no code at all for the most common data scenarios, such as: Selecting and displaying data Sorting, Paging and Caching Data Updating, Inserting and Deleting Data Filtering or Master-Details Using Parameters ASP.NET 2.0 introduces two types of server controls that participate in this declarative data binding model. These two types of data controls handle the complexity of the stateless Web model for data scenarios, so developers don't need to understand page request lifecycle events just to perform data binding. Another benefit of this control-based model is that it can be easily extended to support additional data access storage providers.

® EPAM Systems. All rights reserved. Data Source Controls Data source controls are ASP.NET controls that manage the tasks of connecting to a data source and reading and writing data. Data source controls do not render any user interface, but instead act as an intermediary between a particular data store (such as a database, business object, or XML file) and other controls on the ASP.NET Web page. Data source controls enable rich capabilities for retrieving and modifying data, including querying, sorting, paging, filtering, updating, deleting, and inserting. ASP.NET includes the following data source controls: NameDescription SqlDataSourceEnables binding to a SQL database represented by an ADO.NET provider, such as Microsoft™ SQL Server, OLEDB, ODBC, or Oracle. ObjectDataSourceEnables binding to a middle-tier object such as a data access layer or business component. AccessDataSourceEnables binding to a Microsoft™ Access (Jet) database. SiteMapDataSourceEnables binding to the hierarchy exposed by an ASP.NET 2.0 site navigation provider. XmlDataSourceEnables binding to an XML file or document.

® EPAM Systems. All rights reserved. Data Source Controls A data source control provides a single object in which you can declaratively define the following: Connection information. Query information, such as a SQL statement or the names of methods to invoke on an object. Insert, update, and delete commands to modify data. Parameters for queries, data modification, and filtering. Options such as paging and caching (if the data source supports these options).

® EPAM Systems. All rights reserved. Data-bound Controls Many server controls in ASP.NET support data binding for populating their contents. These controls expose a DataSource property to be initialized to any object that supports the IEnumerable interface, as well as DataTables and DataSets. When the control's DataBind() method is invoked, the collection is traversed, and the contents of the control are filled with whatever was in the collection. Like the Render method of controls, the DataBind method invokes DataBind on any of the control's child controls. So invoking the Page's top-level DataBind() method implicitly invokes all the DataBind() methods for all controls on that page. Alternatively, you can elect to invoke each control's DataBind() method independently.

® EPAM Systems. All rights reserved. Data-bound Controls Data-bound controls are UI controls that render data as markup to the requesting client device or browser. A data-bound control can auto-bind to data exposed from a data source and will fetch data at the appropriate time in the page request lifecycle. These controls can optionally take advantage of data source capabilities such as sorting, paging, filtering, updating, deleting, and inserting. A data- bound control connects to a data source control through its DataSourceID property. You may be familiar with some of the data-bound controls in ASP.NET v1.x, such as DataGrid, DataList, Repeater, and list controls like DropDownList. ASP.NET 2.0 contains several new data-bound controls as well, such as: NameDescription GridViewRenders data in a grid format. This control is an evolution of the DataGrid control, and can automatically take advantage of data source capabilities. DetailsViewRenders a single data item in a table of label/value pairs, similar to the form view in Microsoft™ Access. This control can also automatically take advantage of data source capabilities. FormViewRenders a single data item at a time in a form defined by a custom template. Renders a single data item in a table of label/value pairs, similar to the form view in Microsoft™ Access. This control can also automatically take advantage of data source capabilities. TreeViewRenders data in a hierarchical tree view of expandable nodes. MenuRenders data in a hierarchical dynamic menu (including flyouts).

® EPAM Systems. All rights reserved. Data-Binding Syntax Data-binding expressions are contained within delimiters and use the Eval and Bind functions. The Eval function is used to define one-way (read-only) binding. The Bind function is used for two-way (updatable) binding. In addition to calling Eval and Bind methods to perform data binding in a data-binding expression, you can call any publicly scoped code within the delimiters to execute that code and return a value during page processing. Data-binding expressions are resolved when the DataBind method of a control or of the Page class is called. For controls such as the GridView, DetailsView, and FormView controls, data-binding expressions are resolved automatically during the control's PreRender event and you are not required to call the DataBind method explicitly. The following code example shows the use of data-binding expressions with a FormView control in an ItemTemplate. <asp:FormView ID="FormView1" DataSourceID="SqlDataSource1« DataKeyNames="ProductID« RunAt="server"> Product ID: Product Name: Category ID: Quantity Per Unit: Unit Price:

® EPAM Systems. All rights reserved. Using the Eval Method The Eval method evaluates late-bound data expressions in the templates of data-bound controls such as the GridView, DetailsView, and FormView controls. At run time, the Eval method calls the Eval method of the DataBinder object, referencing the current data item of the naming container. The naming container is generally the smallest part of the data-bound control that contains a whole record, such as a row in a GridView control. You can therefore use the Eval method only for binding inside templates of a data-bound control. The Eval method takes the name of a data field and returns a string containing the value of that field from the current record in the data source. You can supply an optional second parameter to specify a format for the returned string. The string format parameter uses the syntax defined for the Format method of the String class.

® EPAM Systems. All rights reserved. Using the Bind Method The Bind method has some similarities to the Eval method, but there are significant differences. Although you can retrieve the values of data-bound fields with the Bind method, as you can with the Eval method, the Bind method is also used when data can be modified. In ASP.NET, data-bound controls such as the GridView, DetailsView, and FormView controls can automatically use the update, delete, and insert operations of a data source control. For example, if you have defined SQL Select, Insert, Delete, and Update statements for your data source control, using Bind in a GridView, DetailsView, or FormView control template enables the control to extract values from child controls in the template and pass them to the data source control. The data source control in turn performs the appropriate command for the database. For this reason, the Bind function is used inside the EditItemTemplate or InsertItemTemplate of a data-bound control. The Bind method is typically used with input controls such as the TextBox control rendered by a GridView row in edit mode. When the data-bound control creates these input controls as part of its own rendering, it can extract the input values.

® EPAM Systems. All rights reserved. Repeater Web Server Control Overview The Repeater Web server control is a container control that allows you to create custom lists out of any data that is available to the page. The Repeater control does not have a built-in rendering of its own, which means that you must provide the layout for the Repeater control by creating templates. When the page runs, the Repeater control loops through the records in the data source and renders an item for each record. Because the Repeater control has no default look, you can use it to create many kinds of lists, including the following: A table layout A comma-delimited list (for example, a, b, c, d, and so on) An XML formatted list

® EPAM Systems. All rights reserved. Using Templates with the Repeater Control To use the Repeater control, you create templates that define the layout of the control's content. Templates can contain any combination of markup and controls. If no templates are defined, or if none of the templates contain elements, the control does not appear on the page when the application is run. The following table describes the templates that are supported by the Repeater control. Template propertyDescription ItemTemplate Contains the HTML elements and controls to render once for each data item in the data source. AlternatingItemTemplate Contains the HTML elements and controls to render once for every other data item in the data source. Typically, this template is used to create a different look for the alternating items, such as a different background color than the color that is specified in the ItemTemplate. HeaderTemplate and FooterTemplate Contains the text and controls to render at the beginning and end of the list, respectively. SeparatorTemplate Contains the elements to render between each item. A typical example might be a line (using an hr element).

® EPAM Systems. All rights reserved. Binding Data to the Repeater Control The Repeater control must be bound to a data source. The most common data source is a data source control, such as a SqlDataSource or ObjectDataSource control. Alternatively, you can bind a Repeater control to any class that implements the IEnumerable interface, which includes the ADO.NET datasets (DataSet class), data readers (SqlDataReader or OleDbDataReader classes), or most collections. When binding data, you specify a data source for the Repeater control as a whole. When you add controls to the Repeater control — for example, when you add Label or TextBox controls in a template — you use data-binding syntax to bind the individual control to a field of the items returned by the data source.

® EPAM Systems. All rights reserved. Events Supported bu the Repeater Control The Repeater control supports several events. One of them, the ItemCreated event, gives you a way to customize the item-creation process at run time. The ItemDataBound event also gives you the ability to customize the Repeater control, but after the data is available for inspection. For example, if you were using the Repeater control to display a to-do list, you could display overdue items in red text, completed items in black text, and other tasks in green text. Either event can be used to override formatting from the template definition.ItemCreatedItemDataBound The ItemCommand event is raised in response to button clicks in individual items. This event is designed to allow you to embed a Button, LinkButton, or ImageButton Web server control in an item template and then be notified when the button is clicked. When a user clicks the button, the event is sent to the button's container — the Repeater control. The most common uses for the ItemCommand event are to program update and delete behaviors to the Repeater control. Since every button click raises the same ItemCommand event, you can determine which button was clicked by setting each button's CommandName property to a unique string value. The CommandSource property of the RepeaterCommandEventArgs parameter contains the CommandName property of the button that was clicked.ItemCommandButtonLinkButtonImageButtonCommandNameCommandSource RepeaterCommandEventArgsCommandName

Delivering Excellence in Software Engineering ® EPAM Systems. All rights reserved. For more information, please contact: