ASP.Net 2.0 - PowerPoint PPT Presentation

1 / 48
About This Presentation
Title:

ASP.Net 2.0

Description:

... includes two user tables: one for Photo Albums and one for individual Photos ... we have two databases one for personal data such as photos and albums and ... – PowerPoint PPT presentation

Number of Views:43
Avg rating:3.0/5.0
Slides: 49
Provided by: donba5
Category:
Tags: asp | net

less

Transcript and Presenter's Notes

Title: ASP.Net 2.0


1
ASP.Net 2.0
  • A First Look at Databases and Data Sources

2
Databases
  • Visual Studio 2005 provides support for most
    common modern database management systems
    including SQL Server, Oracle, etc.
  • This support is provided through a set of tools
    and technologies Microsoft calls ADO.NET.
  • It uses a Data Provider model in which the user
    is mostly isolated from the details and nuances
    specific to each DBMS system.

3
Data Provider Model
  • While one is able to work at the detailed level
    using features specific to the individual DBMS,
    one may also avoid many of the details and let
    ADO.NET and VS2005 take care of them.
  • Using the Data Provider model, it is possible to
    create a simple but useful database-connected web
    site that involves writing no code at all.
  • Using the power of this model, one may focus on
    designing and building the unique features of the
    website without spending a lot of time coding
    details of data access.

4
SQL Server
  • Microsoft provides a version of SQL Server
    database management software as a part of Visual
    Studio 2005.
  • Called SQL Server Express
  • Compatible with other SQL Server 2005 versions.
  • Has SP1 available.
  • MSDN AA provides SQL Server 2005 Developers
    Edition as well.
  • The primary differences between editions of SQL
    Server 2005 is of scale and platform.
  • Both Express and Developers Edition will run on
    XP Pro.
  • More advanced editions only run on server systems.

5
SQL Server Express
  • SQL Server Express comes in a standard edition
    and an edition with Advanced Services (to
    download these, go to http//msdn.microsoft.com/v
    studio/express/sql/download/)
  • There is a SQL Server Management Studio Express
    version available to help manage SQL Server
    Express databases.

6
SQL Server Management Studio
7
SQL Server Management Studio
  • SQL Server Mgmt Studio can be used to
  • add new databases or delete existing ones
  • add new tables or delete existing tables
  • modify existing table definitions
  • view (or edit) the data in an existing table
  • Many other things

8
SQL Server Express an Example
  • The Personal Website Starter Kit comes initially
    with one SQL Server Express database.
  • Named Personal.mdf.
  • The .mdf extension is used for SQL Server
    database files.
  • A log file (.ldf) goes with it, and it must be
    part of any copy/move of the file.

9
Server Explorer
  • Visual Studio has a Server Explorer that may be
    used from within Visual Studio to view current
    database connections and other things.
  • If it is not already visible, you may open it
    under the View menu item.
  • Note that the Personal.mdf database includes two
    user tables one for Photo Albums and one for
    individual Photos

10
Server Explorer
  • Another thing Server Explorer may be used for is
    to view the data in a database table as in

11
Server Explorer
  • The Photos table shows a total of 4 photos
    currently in the table. Most of the columns of
    data are binary data such as .jpg in this
    example. All are associated with Album 1.

12
After One Run
  • After building the starter kit and running it
    once (without doing anything during the run),
    note that a second SQL Server Express database
    has been added.
  • It is named ASPNETDB.mdf.
  • It is used to maintain a database of registered
    users and their roles with the application.

Databases in the App_Data subdirectory of the
project by default PWS Starter Kit
Two SQL Server Express databases in the PWS
Starter Kit
13
VS 2005 Configuration Tool
  • VS 2005 has a website configuration tool that
    allows us to create, modify, delete users in the
    aspnetdb database, and to assign them roles or
    modify their roles.

Website Configuration Tool
14
Website Configuration Tool
Use Security to set up users and roles
15
Website Configuration Tool
  • The figure below shows no current users and 2
    defined roles.
  • Click on Create Users to add a user.

To create a new User
16
Adding a User
  • Fill in the following form and select 0, 1, or 2
    roles.
  • By default, the password is required to be at
    least 7 characters and include at least one
    special character (non-letter and non-digit) such
    as these _at_.,

17
The ASPNETDB Database
  • After adding a second user, the aspnet_users
    database table contains
  • Note that the USERID and Application ID are
    encrypted.
  • The aspnet_UsersInRoles table contains this data.

18
The ASPNETDB Database
  • The membership table contains the following
    (split over several lines).

19
The PWS Starter Kit
  • To this point, we have two databases one for
    personal data such as photos and albums and
    another for managing administrative data such as
    users, passwords, user roles, and so forth.
  • The sensitive data in one of these databases is
    encrypted.
  • We have written no code at all.

20
A No-Code Example
  • Create a new web site.
  • From the Server Explorer, select a database table
    to display. Drag it and drop it on default.aspx.
  • Visual Studio turns this into two controls on the
    web page
  • A GridView control to display the data
  • A DataSource control that provides the data from
    the data base to the GridView.

21
After the Drag/Drop
GridView showing all the Fields from the Table in
the Database as Column Headings
DataSource control
22
The DataSource Control
  • The DataSource control is a hidden control (it
    does not appear on the rendered form).
  • It is a helper control in that it provides the
    plumbing to connect the GridView control with
    its source of data in this case, a table from
    SQL Server database.
  • It may also be used to connect certain controls
    to other types of data sources such as an XML
    file, a business object that provides the data,
    or a web service.

23
The GridView Control
  • The GridView control provides a convenient and
    powerful control for displaying the contents of a
    table (or multiple tables) in a database.
  • The display is in tabular form.
  • It is very configurable, giving the developer a
    lot of flexibility in how the displayed table is
    formatted and what it contains.

24
The GridView is Configurable
  • Some of the most common items that can be
    configured are shown on this menu.

25
GridView - AutoFormat
26
GridView Edit Columns
  • One can accept the view of all columns.
  • Alternatively, one can select columns to display.
  • One may also edit things such as the column
    headings, formats of the fields, alignment of the
    output, and so forth.

27
GridView - Customizing
  • In the menu, there are several choices that
    permit Enabling certain features (or not).
  • Paging the ability to page between sets of
    records in the table if all wont fit in the grid
    at once.
  • Sorting sort on a column by clicking its
    header. Click again to reverse direction.
  • Editing edit the contents of one or more fields
    in a row.
  • Deleting a row from the table.
  • Selection selecting a row from the table.
  • Editing, deletion, and selection add columns to
    the table.

28
GridView Customization
  • In the above, the Edit, Delete, and Select
    columns were added.
  • The column titles are underlined indicating they
    are clickable for sorting.
  • At the bottom of the grid, the 1 2 indicates
    the means of selecting a page if the data is
    larger than the grid can show at one time.

29
GridView Properties
  • The properties at right are a list of the first
    page of properties for the GridView control.
  • These properties may be set here if not already
    set, or they may be set programmatically in code
    if you prefer.

30
Some Other Controls That Use DataSources
  • The GridView is not the only control that may use
    a DataSource to supply its data.
  • Two other controls that use a DataSource to
    supply its data, usually from a database, are
  • Details View display the details for a row in
    the database in a tabular style.
  • FormView display the details for a row in the
    data base in a form.

31
GridView
32
DetailsView
33
DetailsView
  • The DetailsView control has properties that may
    be set much like similar properties are set for
    the GridView control.

34
FormView
35
FormView
  • The FormView is somewhat less flexible than the
    GridView and DetailsView controls. It has a
    smaller set of properties that may be set easily
    - it takes some programming skills.

36
More DataSources
  • In addition, there are several Type of
    DataSources.

37
Navigation Controls
  • Creating a site map that reflects the structure
    of your site is part of ASP.NET site-navigation.
  • The other part is to display the navigation
    structure so that users can move around your
    site.

38
Site Map
  • A site map is an XML file with a particular
    format.
  • The site map file has the following
    characteristics
  • It is in the project folder
  • Its extension is .sitemap
  • It may have a filename of your choice
  • In the solution explorer, add a new item to the
    web project folder in the usual way

39
Adding A SiteMap File
Select SiteMap as type
Choose a name
40
Adding A SiteMap
  • This gives a skeleton sitemap file (see below).
  • The url is the relative path to a page in your
    site.
  • The title is the text to display in a Navigation
    control on any of your pages.
  • The description will be displayed in a tooltip if
    the user hovers the mouse over a link in the
    Navigation control.

41
Adding a SiteMap
  • After filling in the information in the SiteMap,
    it may look like this
  • Note that a siteMapNode may be embedded in
    another siteMapNode to give levels to the
    hierarchy of pages.

42
Navigation Controls
  • You can easily build navigation into your pages
    by using the following site-navigation controls
  • SiteMapPath   Displays navigation path, known as
    breadcrumbs, that shows the current page location
    and displays the links as a path from the current
    page back to the home page.
  • TreeView   Displays a tree structure that users
    can traverse to navigate the site. A node that
    contains child nodes can be expanded or collapsed
    by clicking it.
  • Menu   Displays an expandable menu that users can
    traverse to navigate your site. A node that
    contains child nodes is expanded when the cursor
    hovers over the menu.
  • Simply drag and drop any of these controls on a
    page, set its properties making sure to point its
    DataSource to the SiteMap.

43
Navigation Controls
  • A SiteMapPath control will display something like
    the following, with Home and Services rendered as
    hyperlinks if the current page is the Training
    page
  • Home gt Services gt Training
  • Use the SiteMapPath control to create site
    navigation without code and without explicit data
    binding.
  • It can read and render the SiteMap information
    automatically.
  • You can also customize the SiteMapPath control
    with code if you prefer or need to modify it
    during execution.

44
Navigation Controls
  • The SiteMapPath control allows users to navigate
    backward from the current page to pages higher in
    the site hierarchy.
  • The SiteMapPath control does not allow you to
    navigate forward from the current page to another
    page deeper in the hierarchy.
  • The SiteMapPath control is useful in newsgroup or
    message-board applications when users want to see
    the path to the article that they are browsing.

45
Navigation Controls
  • With the TreeView or Menu controls, users can
    open nodes and navigate directly to a specific
    page.
  • These controls do not directly read the site map,
    as the SiteMapPath control does. Instead, you add
    a SiteMapDataSource control to a page that can
    read the site map. You then bind the TreeView or
    Menu control to the SiteMapDataSource control,
    resulting in the site map being rendered on the
    page.
  • The TreeView control will display something like
    the following
  • - Home
  •    - Services
  •        Training

46
Menu Control
  • Set the properties you want for the Menu control.
  • If you have a SiteMapDataSource on the page
    already (say for a breadcrumbs control) that
    will do, use it.
  • If you do not already have a SiteMapDataSource
    you can use on the page, select New data source

47
New SiteMapDataSource
48
Example
Menu control.
Master Page for the site.
SiteMapDataSource Used by all Navigation controls
on this MasterPage.
SiteMapPath control.
Another Menu control.
Write a Comment
User Comments (0)
About PowerShow.com