Read Build Your Own ASP.NET 3.5 Website Using C# & VB Online

Authors: Cristian Darie,Zak Ruvalcaba,Wyatt Barnett

Tags: #C♯ (Computer program language), #Active server pages, #Programming Languages, #C#, #Web Page Design, #Computers, #Web site development, #internet programming, #General, #C? (Computer program language), #Internet, #Visual BASIC, #Microsoft Visual BASIC, #Application Development, #Microsoft .NET Framework

Build Your Own ASP.NET 3.5 Website Using C# & VB (3 page)

BOOK: Build Your Own ASP.NET 3.5 Website Using C# & VB
12.6Mb size Format: txt, pdf, ePub
ads

Building the Master Page
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
202

Using the Master Page . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 205

Extending Dorknozzle . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 209

Debugging and Error Handling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 212

Debugging with Visual Web Developer
. . . . . . . . . . . . . . . . . . . . . .
212

Other Kinds of Errors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 218

Custom Errors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 220

Handling Exceptions Locally . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 221

Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 226

Chapter 6

Using the Validation Controls
. . . . . . 227

Client-side Validation and Server-side Validation
. . . . . . . . . . . . . . . . .
228

Introducing the ASP.NET Validation Controls
. . . . . . . . . . . . . . . . . . . . .
228

Enforcing Validation on the Server
. . . . . . . . . . . . . . . . . . . . . . . . .
232

Using Validation Controls . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 238

RequiredFieldValidator
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
239

CompareValidator
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
240

RangeValidator
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
243

ValidationSummary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 244

RegularExpressionValidator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 246

CustomValidator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 249

Licensed to [email protected]

xiii

Validation Groups
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
252

Updating Dorknozzle
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
256

Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 261

Chapter 7

Database Design and

Development
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 263

What Is a Database?
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
264

Creating Your First Database . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 266

Creating a New Database Using Visual Web Developer . . . . . . . . . 267

Creating a New Database Using SQL Server Management

Studio . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 268

Creating Database Tables
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
269

Data Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 275

Column Properties . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 276

Primary Keys . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 278

Creating the Employees Table
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
280

Creating the Remaining Tables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 283

Populating the Data Tables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 286

Relational Database Design Concepts . . . . . . . . . . . . . . . . . . . . . . . . . . . 289

Foreign Keys . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 291

Using Database Diagrams . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 294

Implementing Relationships in the Dorknozzle Database . . . . . . . 297

Diagrams and Table Relationships . . . . . . . . . . . . . . . . . . . . . . . . . . 301

Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 305

Chapter 8

Speaking SQL
. . . . . . . . . . . . . . . . . . . . . . . . . . . .
307

Reading Data from a Single Table
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
308

Using the SELECT Statement
. . . . . . . . . . . . . . . . . . . . . . . . . . . . .
310

Selecting Certain Fields . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 313

Licensed to [email protected]

xiv

Selecting Unique Data with DISTINCT
. . . . . . . . . . . . . . . . . . . . .
314

Row Filtering with WHERE
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
316

Selecting Ranges of Values with BETWEEN
. . . . . . . . . . . . . . . . . . .
317

Matching Patterns with LIKE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 318

Using the IN Operator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 319

Sorting Results Using ORDER BY . . . . . . . . . . . . . . . . . . . . . . . . . . . 320

Limiting the Number of Results with TOP . . . . . . . . . . . . . . . . . . . 321

Reading Data from Multiple Tables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 322

Subqueries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 323

Table Joins . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 323

Expressions and Operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 325

Transact-SQL Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 328

Arithmetic Functions
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
329

String Functions
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
330

Date and Time Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 332

Working with Groups of Values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 333

The COUNT Function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 334

Grouping Records Using GROUP BY . . . . . . . . . . . . . . . . . . . . . . . . 334

Filtering Groups Using HAVING
. . . . . . . . . . . . . . . . . . . . . . . . . . . .
336

The SUM, AVG, MIN, and MAX Functions
. . . . . . . . . . . . . . . . . . . . . .
337

Updating Existing Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 338

The INSERT Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 338

The UPDATE Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 339

The DELETE Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 340

Stored Procedures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 341

Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 346

Chapter 9

ADO.NET
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
347

Introducing ADO.NET
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
348

Importing the SqlClient Namespace . . . . . . . . . . . . . . . . . . . . . 350

Licensed to [email protected]

xv

Defining the Database Connection . . . . . . . . . . . . . . . . . . . . . . . . . 351

Preparing the Command
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
352

Executing the Command . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 353

Setting Up Database Authentication
. . . . . . . . . . . . . . . . . . . . . . . .
356

Reading the Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 359

Using Parameters with Queries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 360

Bulletproofing Data Access Code . . . . . . . . . . . . . . . . . . . . . . . . . . . 368

Using the Repeater Control
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
370

Creating the Dorknozzle Employee Directory . . . . . . . . . . . . . . . . . . . . . 376

More Data Binding . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 381

Inserting Records
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
388

Updating Records
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
395

Deleting Records
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
410

Using Stored Procedures
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
414

Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 416

Chapter 10 Displaying Content Using Data

Lists
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 417

DataList Basics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 418

Handling DataList Events . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 422

Editing DataList Items and Using Templates . . . . . . . . . . . . . . . . . . . . 430

DataList and Visual Web Developer
. . . . . . . . . . . . . . . . . . . . . . . . . . .
439

Styling the DataList
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
441

Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 443

Chapter 11 Managing Content Using Grid

View and Details View
. . . . . . . . . . . . . . . .
445

Using the GridView Control
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
446

Customizing the GridView Columns . . . . . . . . . . . . . . . . . . . . . . . 453

Licensed to [email protected]

xvi

Styling the GridView with Templates, Skins, and CSS . . . . . . . . . . 454

Selecting Grid Records
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
458

Using the DetailsView Control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 463

Styling the DetailsView
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
467

GridView and DetailsView Events . . . . . . . . . . . . . . . . . . . . . . . . . . 469

Entering Edit Mode
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
473

Using Templates . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 477

Updating DetailsView Records
. . . . . . . . . . . . . . . . . . . . . . . . . .
481

Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 485

Chapter 12 Advanced Data Access
. . . . . . . . . . . . . . . . 487

Using Data Source Controls
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
488

Binding the GridView to a SqlDataSource
. . . . . . . . . . . . . . . . . .
490

Binding the DetailsView to a SqlDataSource
. . . . . . . . . . . . . .
499

Displaying Lists in DetailsView . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 511

More on SqlDataSource . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 514

Working with Data Sets and Data Tables . . . . . . . . . . . . . . . . . . . . . . . . . 515

What Is a Data Set Made From? . . . . . . . . . . . . . . . . . . . . . . . . . . . . 518

Binding DataSets to Controls . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 519

Implementing Paging
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
525

Storing Data Sets in View State . . . . . . . . . . . . . . . . . . . . . . . . . . . . 528

Implementing Sorting
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
530

Filtering Data
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
542

BOOK: Build Your Own ASP.NET 3.5 Website Using C# & VB
12.6Mb size Format: txt, pdf, ePub
ads

Other books

Paris, He Said by Christine Sneed
Souls of Fire by Vanessa Black
Blood Family by Anne Fine
Roxanne's Redemption by Keegan, Aisling
A Forever Kind of Love by Shiloh Walker
Most Wanted by Turner, Nikki, Swinson, Kiki
Faces by E.C. Blake