Creating Bindable Grids of Data. Slide 2 Lecture Overview Detailed discussion of using the GridView.

Slides:



Advertisements
Similar presentations
Use Tables for Layout Control Day 7. You will learn to: Understand Tables Create a Simple Table Modify Your Tables Appearance Create Page Layouts with.
Advertisements

Chapter 3 – Web Design Tables & Page Layout
Copyright © 2004 ProsoftTraining, All Rights Reserved. Lesson 6: HTML Tables.
Built-in Kentico CMS UI Controls
Using the DetailsView and FormView Controls. Slide 2 DetailsView (Introduction) Use the DetailsView control to Display a single record at a time Insert,
GridView Features, DetailsView, FormView. Content GridView Features DetailsView FormView Muzaffer DOĞAN - Anadolu University2.
Pasewark & Pasewark 1 Word Lesson 7 Working with Documents Microsoft Office 2007: Introductory.
® Microsoft Office 2010 Word Tutorial 3 Creating a Multiple-Page Report.
Word Lesson 7 Working with Documents
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.
COMPREHENSIVE ICT Document Preparation System Mr.S.Sajiharan Computer Unit Faculty of Arts and Culture South Eastern University of Srilanka.
Asp.NET Core Server Controls. Slide 2 Lecture Overview Understanding the types of ASP.NET controls HTML controls ASP.NET (Web) controls.
ASP.NET Data Binding. Slide 2 Lecture Overview Understanding the ASP.NET data binding model.
® Microsoft Office 2010 Word Tutorial 3 Creating a Multiple-Page Report.
Chapter 12: ADO.NET and ASP.NET Programming with Microsoft Visual Basic.NET, Second Edition.
XHTML1 Tables and Lists. XHTML2 Objectives In this chapter, you will: Create basic tables Structure tables Format tables Create lists.
Building ASP.NET Applications 2 Lecture 3,4 T. Ahlam Algharasi 4 th Level.
Tables And Lists. Slide 2 Lecture Overview Learn about the basics of tables Create simple 2-dimensional tables Format tables Create tables with complex.
Word Tutorial 3 Creating a Multiple-Page Report
Excel 2007 Part (2) Dr. Susan Al Naqshbandi
Chapter 8 Binding Data to Web Controls. ASP.NET 2.0, Third Edition2.
HTML Comprehensive Concepts and Techniques Second Edition Project 3 Creating Tables in a Web Site.
Databases and LINQ Visual Basic 2010 How to Program 1.
Chapter 10 Managing Data with ASP.NET. ASP.NET 2.0, Third Edition2.
Unit 8.2 Learning Objectives How data can be used – The Money Ball Example The Money Ball Example Data Warehouses – The Role of Data Warehouses The Role.
10-1 aslkjdhfalskhjfgalsdkfhalskdhjfglaskdhjflaskdhjfglaksjdhflakshflaksdhjfglaksjhflaksjhf.
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.
ASP.NET Web Server Controls Basic Web Server Controls.
CSS/417 Introduction to Database Management Systems Workshop 2.
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.
XP New Perspectives on Microsoft Word 2002 Tutorial 31 Microsoft Word 2002 Tutorial 3 – Creating a Multiple-Page Report.
JavaScript, Fourth Edition Chapter 5 Validating Form Data with JavaScript.
® Microsoft Office 2010 Word Tutorial 3 Creating a Multiple-Page Report.
Delivering Excellence in Software Engineering ® EPAM Systems. All rights reserved. Data Binding in ASP.NET.
Working with GridView Control: Adding Columns. Adding Buttons to a Bound GridView: 1. Drag the WebProduct table from Data connection to a page 2. Demo.
Database Systems Microsoft Access Practical #2 Making Forms and Reports Nos 215.
IC 3 BASICS, Internet and Computing Core Certification Key Applications Lesson 11 Organizing the Worksheet.
Copyright 2006 South-Western/Thomson Learning Chapter 12 Tables.
Chapter 8 Working With Databases in ASP.NET. Listing 8.1 – ShowListControls Uses The SqlDataSource control for estabishing database connectivity and.
FIRST COURSE Word Tutorial 3 Creating a Multiple-Page Report.
ADO.NET Part 2. Slide 2 Overview Slide 3 Introduction to the DataGridView Control It’s a two-dimensional grid containing rows and columns Its use in.
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
© MECHAN 2009 All right reserved. MecGrid W I Z A R D How to be a magician for your MecGrid. Data Visual with W I Z A R D.
1 Lesson 13 Organizing and Enhancing Worksheets Computer Literacy BASICS: A Comprehensive Guide to IC 3, 3 rd Edition Morrison / Wells.
Chapter 5 Working with Tables Principles of Web Design, 4 th Edition.
ASP Chapter 8 1. Active Server Pages Server-side technology dynamicinteractivedata-driven Enables dynamic, interactive, data-driven web pages languages.
Key Applications Module Lesson 14 — Working with Tables Computer Literacy BASICS.
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.
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.
Microsoft Office 2013 Try It! Chapter 4 Storing Data in Access.
DAY 18: ACCESS CHAPTER 3 Tazin Afrin October 22,
Unit 8.2 Learning Objectives Data Warehouses – The Role of Data Warehouses The Role of Data Warehouses – Group Exercise Accessing Data in Views – Accessing.
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.
DATA GRID VIEW objective of lecture:- After completing this lecture, you will be able to: Create a data grid view object on a windows form and use it to.
Visual Basic 2010 How to Program
Microsoft Access 2007 – Level 2
Working with Tables: Module A: Table Basics
HTML Tables.
Unit 8.2 How data can be used Accessing Data in Views
Agenda: 10/05/2011 and 10/10/2011 Review Access tables, queries, and forms. Review sample forms. Define 5-8 guidelines each about effective form and report.
Creating Bindable Grids of Data
Tutorial 3 – Creating a Multiple-Page Report
Lecture Set 10 Windows Controls and Forms
© 2016, Mike Murach & Associates, Inc.
Presentation transcript:

Creating Bindable Grids of Data

Slide 2 Lecture Overview Detailed discussion of using the GridView

Slide 3 Introduction to the GridView Characteristics Data appears in a multicolumn grid Made up of rows and columns Data always appears in a tabular form Don’t try to change this! All output is rendered as an HTML table

Slide 4 Comparing the DataGrid and GridView The two controls work similarly The DataGrid is older The GridView replaces the DataGrid control In this lecture, I will discuss only the GridView control

Slide 5 Complementary GridView Controls ListView uses templates to display data Insert, update, delete supported DetailsView displays a single row from a data source Insert, update delete supported More in the next lecture

Slide 6 Limitations It’s a grid, don’t try to force the control to deal with anything but rows and columns It’s not really designed to add new records We can put the envelope though

Slide 7 GridView (Binding) The GridView can be bound in different ways Via the DataSourceID Via the DataSource and DataMember Programatically to a DataSet or other possible binding

Slide 8 Setting Column Properties (Introduction) Columns can be set using the wizard (see following screen shot) Columns can be managed using the.aspx code Or programmatically In a nutshell, it’s very flexible and powerful

Slide 9 Columns (Introduction) Columns – contains a reference to the control’s columns We work with these declaratively and programmatically We only use these when AutoGenerateColumns is false The data type of each column is DataGridColumn

Slide 10 Setting Column Properties (Illustration)

Slide 11 GridView (Columns) Each GridView is made up of a set of Columns The collection is a child of the GridView Each column is considered a “field”. A column can display bound data (I’ll start here so that we can do something) predefined commands (buttons) Hyperlinks and images Custom templates

Slide 12 Columns ( BoundField ) The simplest type of binding is a BoundField The GridView does most of the work Set the DataField to the corresponding bound field name Set the HeaderText to display a column header

Slide 13 Columns ( BoundField ) (Example) A BoundField should be a child of Columns

Slide 14 GridView (Captions) Caption – appears above the grid headers CaptionAlign – controls the alignment of the caption (NotSet) Captions can appear along the left, top, right, or bottom of the grid ShowHeader (true) and ShowFooter – (false) display the header or footer Note the caption appears in the header

Slide 15 GridView (Table Formatting) CellPadding – the number of pixels between the cell contents and border CellSpacing – the number of pixels between cells GridLines – how the gridlines appear Both, Horizontal, None, Vertical We can also use CSS

Slide 16 GridView ( Row Styles) Rows appearing in the GridView can be formatted by defining a row style Use the CssClass property to format the row using a defined CssClass Or just set the individual style attributes Syntactically, styles are immediate children of the grid itself rather than attributes of the grid

Slide 17 GridView (Row Styles 1) The following set the style of various graphical elements RowStyle – individual items displayed in all rows AlternatingRowStyle – every other item EditRowStyle – the item being edited FooterStyle – the footer appearing at the bottom of the control HeaderStyle – the header appearing at the top of the control SelectedRowStyle – the selected row PagerStyle – the style of the pager area

Slide 18 GridView (Row Styles 2) Styles appear as an immediate child of the GridView

Slide 19 GridView (Adding Commands) Here, we are adding buttons to Select a row Update a row Delete a row (We play clever tricks to add a row) Or something else

Slide 20 GridView (Command Field -1) MSDN describes it as a special field to automatically perform inserting, updating, deleting There is no auto provision to add When using Bound fields, the plumbing to select / change / delete is automatic – no code necessary You could do the work by hand using a ButtonField (discussed next)

Slide 21 GridView (Command Field -2) Enable the default command buttons

Slide 22 GridView (Button Fields) Use to perform special tasks Set the CommandName property identify the command being executed It’s just a string! Handle the RowCommand event to figure out which button was clicked Use e.CommandName to figure out which button was clicked

Slide 23 GridView (Button Fields) (Example) Set the CommandName for a ButtonField, ImageButton, or others Handle the onRowCommand event for the grid

Slide 24 GridView (Template Fields) Use to create custom content Create a TemplateField as a child of the collection So each TemplateField represents a column Like the FormView we display different templates based on the operating mode and current row You have to perform the data binding

Slide 25 GridView (Template Fields) HeaderTemlate: rendered in the first row ItemTemplate: the default rendering EditItemTemplate: the row being edited FooterTemplate: the footer row

Slide 26 GridView (Template Fields)

Slide 27 GridView (Sorting Columns) Simply put, you set the AllowSorting property to true The underlying data source handles the sorting The column header appears as a link button Set the SortDirection property to Ascending or Descending For each bound field, set the SortExpression attribute to the field or expression that will be evaluated

Slide 28 GridView (Paging 1) Paging provides the facility that enables the DataSet to be displayed in pages having a fixed length This keeps the Web page from getting too long Reduces page size thereby improving download times

Slide 29 GridView (Paging) AllowPaging (false) – controls whether data appears on multiple pages PageSize - defines the number of items (rows) per page The above are both members of the grid itself PageIndex – gets the current page being displayed PageCount – gets the number of pages available

Slide 30 GridView (Paging Events) PageIndexChanging fires before the PageIndex property is changed The event argument is of type GridViewPageEventArgs The event can be cancelled And PageIndexChanged fires after the current page index is changed Setting the PageIndex property does not fire these events

Slide 31 GridView ( PagerSettings ) The PagerSettings object allows you to use predefined display modes Modes ( NextPrevious, NextPreviousFirstLast, Numeric, NumericFirstLast ) Non-numeric button customization ( FirstPageText, PreviousPageText, NextPageText, LastPageText Or Images ( FirstPageImageURL, PreviousPageImageURL, NextPageImageURL, LastPageImageURL )

Slide 32 GridView (Custom Paging) Custom paging is supported along with custom pager styles AllowCustomPaging – defines a custom pager

Slide 33 GridView (Programmatically) We can work with The current / selected row Enumerate rows

Slide 34 GridView (Programmatically) SelectedRow – a GridViewRow object representing the selected row SelectedIndex – 0-based index of the selected (visible) row SelectedValue – The value of the primary key for the selected record (row)

Slide 35 GridView (Rows) Rows – returns a collection of the currently displayed items (from the current page) DataKeyNames – An array of primary key fields (It’s an array because multiple fields might comprise a key) SelectedDataKey – Returns the DataKey of the selected record DataKeys – A collection of DataKey objects containing the primary key values

Slide 36 GridView (Events) There are a slew of these

Slide 37 GridView (Events - RowCommand ) The event fires whenever a button is clicked in the GridView If the command name is “Cancel”, “Delete”, “Edit”, “Page”, “Select”, “Sort”, or “Update” default handing is performed Otherwise it’s up to you The event argument has a data type of GridViewCommandEventArgs Read the value of the CommandName property

Slide 38 GridView (Events - RowCommand ) protected void gvExample1_RowCommand(object sender, GridViewCommandEventArgs e) { Response.Write("RowCommand Fired "); Response.Write("e.CommandName " + e.CommandName + " "); }

Slide 39 GridView (Events - RowCommand ) Member of the Row property RowType tells you the type of row DataRow, Footer, Header, EmptyDataRow, Pager,Separator Cells provides a reference to a collection of TableCell objects (cells in the row)

Slide 40 GridView (Events - RowCreated ) RowCreated fires each time a row is created Fires for header and footer rows too Use the change the default generated content of a row The data type of the event argument is GridViewRowEventArgs The Row property provides a reference to the row

Slide 41 GridView (Selecting) SelectedIndexChanging fires when the user clicks the Select button to select a row The new row is not yet selected The data type of the event argument is GridViewSelectEventArgs The event argument’s NewSelectedIndex property contains the index of the row that will be selected Set the Cancel property to true to can this event and subsequent events

Slide 42 GridView (Selecting) SelectedIndexChanged fires when the user selects a different record (when the Select button is clicked) At this point The SelectedIndex property contains the 0- based index of the (Visible) row selected this is important when paging is enabled The SelectedValue property contains the value of the key field for the selected record

Slide 43 Editing Data (Introduction) The GridView is an editable control Make sure that the data source ( SqlDataSource ) is configured to perform editing Set the AutoGenerateEditButton property to true Click Edit to begin editing Click Update or cancel to record or abandon the changes (the process is automatic)

Slide 44 GridView (Editing) RowCancellingEdit – fires when the user clicks the Cancel button to stop editing the current row RowUpdating and RowUpdated fire before and after a row is updated (when the Update button is clicked

Slide 45 Editing Data (Validation) Handle the RowUpdating Validate the current row, as necessary Cancel the event, as necessary e.Cancel=True or RowUpdated events if (e.Exception != null) { Response.Write("Cannot update"); e.ExceptionHandled = true }

Slide 46 Editing Data ( RowUpdating ) The event fires before the data is committed to the database The event argument is GridViewUpdateEventArgs e.NewValues contains a dictionary collection of key / value pairs. See the example on the following slide

Slide 47 Editing Data ( RowUpdating ) Example foreach (DictionaryEntry entry in e.NewValues) { Response.Write(e.NewValues[entry.Key]); Response.Write(e.NewValues[entry.Value]); }

Slide 48 Deleting Data (Introduction) Set the AutoGenerateDeleteButton property to true A Delete button will appear in the grid The data source must be configured to perform deletion Again, the rest of the process is automatic Handle RowDeleted and RowDeleting, as necessary

Slide 49 Inserting Records The GridView does not support record insertion against a data source Typically, we use the FormView or DetailsView controls (discussed in subsequent chapters) We can fix this with a little trick

Slide 50 Empty Grids If the GridView is empty, nothing appears Set the EmptyDataTemplate to display something when the data source contains no rows Example:

Slide 51 Configuring GridView Columns GridView columns appear in the order that they appear in the collection for the grid Programmatically, you reference the grid columns using the Columns collection The data type of each column is DataControlField