Unit 8.2 How data can be used Accessing Data in Views

Slides:



Advertisements
Similar presentations
Chapter 9 Customizing Data with Web Controls. ASP.NET 2.0, Third Edition2.
Advertisements

MIS 3200 – Unit 4 Complex Conditional Statements – else if – switch.
Customizing Forms and Writing QuickBooks Letters Lesson 15.
® IBM Software Group © 2006 IBM Corporation The Eclipse Data Perspective and Database Explorer This section describes how to use the Eclipse Data Perspective,
Customizing forms and writing QuickBooks Letters Lesson 15.
Advanced Forms Lesson 10.
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.
Chapter 1 Databases and Database Objects: An Introduction
Creating a Web Site to Gather Data and Conduct Research.
Microsoft Expression Web-Illustrated Unit I: Working with Tables.
UNIT 9.2 Learning Objectives A Real world Application of Databases – The Money Ball Example The Money Ball Example Data Warehouses – The Role of Data Warehouses.
UNIT 9.2: Learning Objectives Agile Development – Bruce Feiler on Agile Programming Database access from code – Database Cycle Review – SQL Command Types.
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.
Unit 8.3 Learning Objectives Insert users into the ASP.NET Membership system from code Capture data being sent to the database Capture Exceptions that.
CIS 338: Using Queries in Access as a RecordSource Dr. Ralph D. Westfall May, 2011.
CSCI 6962: Server-side Design and Programming Database Manipulation in ASP.
Reference: “ASP.NET 2.0 Illustrated” by Alex Homer and Dave Sussman. -ch3 illustrated book
1 Database Design and Development: A Visual Approach © 2006 Prentice Hall Chapter 12 DATABASE DESIGN AND DEVELOPMENT: A VISUAL APPROACH Chapter 12 Accessing.
® IBM Software Group © 2006 IBM Corporation JSF Rich Text Area Component This Learning Module describes the use of the JSF Rich Text Area component – for.
MIS 3200 – Unit 5.1 Iteration (looping) – while loops – for loops Working with List Items.
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.
Unit 8.2 Learning Objectives Data Warehouses – The Role of Data Warehouses The Role of Data Warehouses – Group Exercise Accessing Data in Views – Accessing.
Mail Merge Introduction to Word Processing ITSW 1401 Instructor: Glenda H. Easter Introduction to Word Processing ITSW 1401 Instructor: Glenda H. Easter.
1 Customizing Forms and Writing QuickBooks Letters Lesson 15.
Visual Basic.NET Comprehensive Concepts and Techniques Chapter 11 Creating Web Applications and Writing Data to a Database.
MIS 3200 – C# (C Sharp)
June 17, 2009 Office 2007 Tips & Tricks.
Access Tutorial 2 Building a Database and Defining Table Relationships
Creating a Presentation
Microsoft Visual Basic 2010: Reloaded Fourth Edition
Unit 7 Learning Objectives
Unit 9.1 Learning Objectives Data Access in Code
Creating Oracle Business Intelligence Interactive Dashboards
Maintaining a Database Using the Design and Update Features of Access
Unit 8.1: Introducing Databases
With Microsoft FrontPage 2000
Practical Office 2007 Chapter 10
Introduction to Microsoft Access
3.01 Apply Controls Associated With Visual Studio Form
Incorporating Databases with ADO.NET
3.01 Apply Controls Associated With Visual Studio Form
Microsoft Access 2003 Illustrated Complete
Unit 9.2 Database access from code Database Cycle Review
Incorporating Databases with ADO.NET
Unit I: Collecting Data with Forms
Chapter 7 Advanced Form Techniques
MIS 3200 – Unit 4 Complex Conditional Statements else if switch.
MIS 201 Web Design.
MODULE 7 Microsoft Access 2010
Creating and Modifying Queries
Modifying Tables and Fields
Unit 9.3 Learning Objectives Review database access in code
MIS 3200 – Unit 5.2 ListItem controls and accumulation
Benchmark Series Microsoft Word 2016 Level 2
Microsoft Official Academic Course, Access 2016
CIS16 Application Programming with Visual Basic
Excel: Excel Basics Participation Project
Access: Access Basics Participation Project
Microsoft Office Access 2003
Practice Activity – Part 1
Guidelines for Microsoft® Office 2013
MIS 3200 – Unit 5.1 Iteration (looping) Working with List Items
MIS 3200 – Unit 6.1 Moving between pages by redirecting
Query-by-Example Transparencies
Unit J: Creating a Database
New Perspectives on Microsoft
Presentation transcript:

Unit 8.2 How data can be used Accessing Data in Views Learning Objectives How data can be used The Money Ball Example Accessing Data in Views Accessing data in Graphical Web Controls Working with Templated Data Working with Hidden Cells Group Exercise

How Data can be used Example: Moneyball Batting average Stolen bases Runs batted in On-base % Slugging % On-base + Slugging (OPS) How Data can be used

Databases Database creation and use Database and Query Development MS Visual Web Developer Database and Query Development MS SQL Server Business Intelligence Microsoft BI, IBM Cognos Real world Application Money Ball

Collections of Rows GridViews and DetailsViews contain a “collection” of Rows Each Row contains a collection of Cells Cells Data bound controls are complex structures that contain/hold other controls, controls that are not visible from page level code Before we can extract data from these internal controls we must locate them inside the control that is visible from the page Rows gvFees dvFee

Locations of Cells DetailsView dvFee 0 1 DetailsView dvFee The Fee amount (i.e. 7.5000) dvFee.Rows[2].Cells[1] GridView: gvFees ( “Select” is Column 0) The FID of (i.e. 1) is in gvFees.Rows[0].Cells[1] The Weight Fee (i.e. 12.5) is in gvFees.Rows[2].Cells[3] 1 2 0 1 2 3 1 2

Types of Cells: Standard and Templated Standard cells Templates Come from Database Yes, always sometimes Created manually Never Always in ItemTemplates Data type String web control (e.g. DDL) Used for Display, edit Insert, display, edit, validation Accessed by Cell Location Cell Location + FindControl

Accessing Data in Standard Cells If The cell does NOT contain a CheckBox, AND It has NOT been converted to a Template Then Your data is in the Text property of the Cell Example: Otherwise Use the FindControl utility Label lblFees = new Label(); lblFee.Text = gvFees.Rows[3].Cells[2].Text; Label lblFees = gvFee.Rows[3].Cells[2].FindControl(“lblFee”) as Label;

Basic Templates Guidelines To create/use templates, remember three things Web control type (e.g. Label) Its name (e.g. “lblFeeDescription”), Its location (e.g. in ItemTemplates ). Why use to Templates To add validators To insert new values into the database To access the contents of a control in a template you first have to find it All .NET controls that can hold other controls have a method called FindControl that allows you to locate the inner control If FindControl locates the control it provides a link (sometimes called a pointer) to the control which we can capture in a variable If you are looking in the wrong place, or misspell the control’s name FindControl won’t find it and will return a null value. You should ALWAYS test for this.

Template Example: DetailsView To use templated data, convert them directly into labels. Label lblDesc = dvFee.Rows[1].Cells[1].FindControl(lblDescription”) as Label

Hiding data in DetailViews

The Data is NOT where you think it is 0 1 1 2 dvFee.Rows[2].Cells[1] 0 1 1 2 Invisible field is still here What is the location of the fee?

How to tell Examine at the “SelectedFields” window Fee Description is still the second field (it is row 1) And the Fee is still the third field (row 2) 1 2

Finding Data in GridViews All Data is located in the row selected by the user The SelectedIndex is used to index the row and is -1 if no row is selected The basic idea is similar, except all the data for one record is in the same row and you have to know which row to use If you only want data from the selected row, you can use the GridView’s SelectedIndex property – it tells you the number of the selected row (see next slide)

All rows of a GridView Use a special loop called “foreach” Loops through a collection of rows One row at a time The type of object being extracted from the collection The collection being looped through

Unit 8 L2 For this exercise we are going to modify your Unit 5 L2 assignment, replacing the fees ListBox with a fees GridView Start by Opening your ASPPub and copying your yournameU5L2.aspx files into the Unit8 folder. Rename the files to yournameU8L2 Change the page heading from UNIT 5 L2… to UNIT 8 L2 WORKING GRIDVIEW

Unit 8 L2 - 2 Delete the fees ListBox and put a GridView in its place. Give the GridView the (ID) of gvFees Click on the GridView’s SmartMenu, click the dropdown next to Choose Data Source and select <New data source> Select SQL Database and change its ID to sdsFees Click OK and select the connection you created in U8L1

Unit 8 L2 - 3 Click Next, select the Fees table and select all the fields individually Click Next and click Text Query to see the records in the table, then click Finish Apply an Auto Format to the Gridview and change its width to 300px. Select Edit Columns from the GridViews SmartMenu Select TemplateField from Available Fields and press Add

Unit 8 L2 – 4 Click the Up Arrow key to move the TemplateField to the top of the Selected fields list Select FID from Selected fields and change its Visible property to false Select the FeeDescription field change its HeaderText property to Description Change its Styles, HeaderStyle, HorizontalAlign to Left Select the Fee field and change its DataFormatString to {0:f2}

Unit 8 L2 - 5 Click OK and then EditTemplates, you should be looking at your new ItemTemplate Add a CheckBox to the ItemTemplate Change its (ID) to ckbSelect Change its Text to Select End Template Editing You should have something that looks something like this

Unit 8 L2 - 6 Delete the WHILE loop button and all its associate code (the easiest way to do this may be do double-click the button to get to the code, select all the click method code and delete it, switch back to design view and delete the button) Delete the FOR loop button and all its associate code Double-click the sales tax button and locate and delete the code used in Unit 5 to process the ListBox (leave the lines that calculate the tax and those that write to the Label)

Unit 8 L2 - 7 In place of the ListBox code write a foreach loop to process the GridView rows: Code: Find the CheckBox. Remember the data type & cast it (below) Code: Is it Checked? Code: Locate the Fee (remember, the invisible FID field still takes up a Cell!) Code: add it to decFees Wrap up Sales tax and Switch statement is not critical for this Other than that, please make it look like the sample page … Try A sales with no fees Try A sales with one or more fees foreach (GridViewRow gvRow in gvFees.Rows) { }

Unit 8 L2 - 8 Once you are sure that your calculations work Add code to reset the checkboxes This should be a foreach loop that Locates the CheckBox in the GrideViewRow and Sets its Checked property to false Test the page with the same data as before to be sure you get the same answers and that the checkboxes are reset Once you are sure the page works, link it to your MIS3200 profile page and save your complete ASPPub to ASPNET as you have done before Post a link to your MIS3200 portfolio page in the dropbox

Think About It! A DetailsView and a GridView always look like tables. Think of some applications where you might want to display data in a different way. A FormView shows one record at a time, like the DetailsView, but it isn’t divided into Rows and Cells. How do you think you would access data in a FormView.