Using List Controls with SQL Server

Slides:



Advertisements
Similar presentations
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Slide STARTING OUT WITH Visual Basic 2008 FOURTH EDITION Tony Gaddis.
Advertisements

Developing Web Applications
1.NET Web Forms DataGrid © 2002 by Jerry Post. 2 Data Grid Has Many Uses  The grid uses HTML tables to display multiple rows of data. It is flexible.
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.
IT533 Lecture ASP.NET Controls. Installations Microsoft® SQL Server® 2008 Express.
ASP.NET Data Binding. Slide 2 Lecture Overview Understanding the ASP.NET data binding model.
Introduction to Database Processing with ADO.NET.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Slide
Copyright © 2014 Pearson Education, Inc. Chapter 11 Developing Web Applications.
Chapter 8 Binding Data to Web Controls. ASP.NET 2.0, Third Edition2.
Chapter 11 Introduction to Database Processing. Class 11: Database Processing Use a Visual Studio Wizard to establish a database connection used to load.
Programming with Visual Basic.NET An Object-Oriented Approach  Chapter 8 Introduction to Database Processing.
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 71 Building Data-Driven ASP.NET Applications Introduction to ASP.NET By Kathleen Kalata.
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.
1 Web-Enabled Decision Support Systems Database Connectivity in Web Applications Don McLaughlin IE 423 (304) West.
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.
CSCI 6962: Server-side Design and Programming Database Manipulation in ASP.
1 Chapter 12 – Web Applications 12.1 Programming for the Web, Part I 12.2 Programming for the Web, Part II 12.3 Using Databases in Web Programs.
Chapter 8 Working With Databases in ASP.NET. Listing 8.1 – ShowListControls Uses The SqlDataSource control for estabishing database connectivity and.
ASP.NET More on searching databases 1ASP.NET, More on searching databases.
CSCI 3327 Visual Basic Chapter 13: Databases and LINQ UTPA – Fall 2011.
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
Week Developing Web Applications 12. Programming for the Web A Web Application Runs on a Web Server and Presents Its Content to the User Across a Network,
Review ASP Server controls: Labels, Buttons, Textboxes HTML tables Images and Hyperlinks Validator controls DropDownList ViewState variables Session variables.
1 Database Design and Development: A Visual Approach © 2006 Prentice Hall Chapter 12 DATABASE DESIGN AND DEVELOPMENT: A VISUAL APPROACH Chapter 12 Accessing.
ADO.NET FUNDAMENTALS BEGINNING ASP.NET 3.5 IN C#.
1 Database Programming with ADO.NET Kashef Mughal.
Data Listing Web Controls MacDonald Ch MIS 324 MIS 324 Professor Sandvig Professor Sandvig.
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.
ADO.NET Objects Data Adapters Dr. Ron Eaglin. Agenda Builds on Information in Part I Should have working knowledge of creating a database connection Continuation.
DataGridView. Displaying data in a tabular format is a task you are likely to perform frequently. The DataGridView control is designed to be a complete.
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.
SQL-TABLES-DATA GRIDS Tables of Pictures, URL’s Binding data to pages Using the Data Source Configuration Wizard Using the GridView and DetailsView controls.
Chapter 10, Slide 1Starting Out with Visual Basic 3 rd Edition Chapter 11 Developing Web Applications.
Common SQL keywords. Building and using CASE Tools Data Base with Microsoft SQL-Server and C#
Introduction to Database Processing with ADO.NET
Database, SQL and ADO.NET
Microsoft Visual Basic 2010: Reloaded Fourth Edition
Creating Data Base & Sql Data Source
Introduction to Database Processing with ADO.NET
Visual Basic 2010 How to Program
Unit 9.1 Learning Objectives Data Access in Code
Creating Oracle Business Intelligence Interactive Dashboards
Unit 8.1: Introducing Databases
PROG Advanced Web Apps 5/23/2018 Notes on ADO.NET (1) Wendi Jollymore, ACES.
Lecture 6 VB.Net SQL Server.
ASP.NET Web Controls.
Unit 8.2 How data can be used Accessing Data in Views
Listing 9.1 ShowLocalConnection.aspx
Part 1 of 2 Creating SQL Database and Binding to GridView
ASP.NET and ADO.NET.
test slide
VB.NET Using Database.
Developing Web Applications
Brief description on how to navigate within this presentation (ppt)
Database Applications
Creating Data Base & Sql Data Source
Module 05: Building ASP .NET Applications
Web Development Using ASP .NET
Chapter 10 Accessing Database Files
ASP.NET and ADO.NET.
Button Web Server Controls
Presentation transcript:

Using List Controls with SQL Server Working with Data-Bound DropDownLists, RadioButtons, and CheckBoxes

List Web Controls You’ve worked with DropDownList controls Similar to the Visual Basic ComboBox ASP provides two new controls: RadioButtonList – a series of radio buttons CheckBoxList – a series of check boxes These controls share similar properties An Items collection can be accessed in code Can generate a SelectedIndexChanged event Can optionally generate automatic postback Items collection can be set up thru VS, your code, or populated by a data source control

Binding to a List Web Control Binding process uses a Text and Value property similar to a ComboBox control Create a new web page ListControls.aspx Add an SqlDataSource named SqlDsCategory Sql Select access only – no Insert, Update, Delete Select all rows & all columns from Categories table Add DropDown, CheckBox, & RadioButton lists Configure the list controls Choose SqlDsCategory as the data source Choose Description to display and Code as Value Web page shows book category types Value property returns category code (key)

Filtering with a DropDownList Remove RadioButtonList and CheckBoxList Add a 2nd SqlDataSource Select ISBN, Title, Author, YearPublished, and Price columns from the Books table Add a Where clause Set Column to CategoryCode Source to Control Control ID to the DropDownList control Add a GridView using the new SqlDataSource Select the new data source for the GridView View the resulting web page

Filtering and AutoPostBack First category automatically selected Web page shows 1 Book in this category Change Category selected in drop down list No change in books listed Must set AutoPostBack true for drop down list Change drop down list AutoPostBack to true View web page again GridView automatically filters for book category

Filtering with a RadioButtonList Remove DropDownList, add RadioButtonList Set RadioButtonList AutoPostBack true Change Where clause for grid SqlDataSource Remove previous Where clause Set Column to CategoryCode Source to Control Control ID to the RadioButtonList control Resulting web page shows no books initially Click on a radio button GridView automatically filters for book category Note that CheckBoxList won’t work in this case

Formatting a RadioButtonList RadioButtonList shown in one long column Preferable to have several shorter columns Use RepeatColumns property to do this Set RepeatColumns to 4 Increase CellPadding to 10 to provide spacing RepeatDirection determines whether the first items appear in the first column or first row

Selecting Multiple Categories Use CheckBoxList to select multiple categories But this exceeds the abilities of Visual Studio Need a variable number of Where clauses SqlDataSource does not allow for this Time to write some code!

Sql Server Connection String Sql Server connection string in web.config: Web site folder located at B:\WEB250 Books.mdf residing in App_Data folder "Data Source=(LocalDB)\v11.0; AttachDbFilename=B:\WEB250\ListControls\App_Data\Books.mdf; Integrated Security=True;User Instance=False;" Hard coding web site path usually a bad idea Substitute |DataDirectory| for hard coded path AttachDbFilename=|DataDirectory|\Books.mdf;

Using Web.Config Connect String Test database access w/new ConnectionString Remove SqlDataSource controls from page Change data source for CheckBoxList and GridView controls to None Connection strings are accessed in code as a property of the ConfigurationManager conString = ConfigurationManager.ConnectionStrings(“StringName"). ConnectionString Web.config can hold many connection strings StringName must match your connection string

Using Web.Config Connect String Helpful to import namespaces to VB code Imports System.Data Imports System.Data.SqlClient Eliminates need to preface classes with namespaces Connection strings are accessed in code as a property of the ConfigurationManager conString = ConfigurationManager.ConnectionStrings(“StringName"). ConnectionString

Populating the CheckBoxList sqlString = "Select CategoryCode, CategoryDescription from Categories;" Dim dbConnObj As New SqlConnection(conString) Dim cmdObj As New SqlCommand(sqlString, dbConnObj) Dim adapterObj As SqlDataAdapter = New SqlDataAdapter Dim tableObj As New DataTable adapterObj.SelectCommand = cmdObj adapterObj.Fill(tableObj) With chklCategory .DataSource = tableObj .DataTextField = "CategoryDescription" .DataValueField = "CategoryCode" .DataBind() End With

CheckBoxList Properties Each check box is an item in the CheckBoxList Items Collection Number of check boxes chklCategory.Items.Count If check box has been checked chklCategory.Items(i).Selected Check box description displayed to user chklCategory.Items(i).Text Check box value returned to program chklCategory.Items(i).Value.ToString

Populating the GridView Drag a GridView to your web page Do not select a data source for the GridView Edit Columns to set up GridView columns Add a BoundField for each column Set properties for each BoundField DataField must match database column HeaderText displayed to user in column header Build an SQL Where clause dynamically based on which check boxes have been selected Retrieve Books table just like Category table Ignore DataTextField and DataValueField which have no meaning for a GridView