Đang chuẩn bị nút TẢI XUỐNG, xin hãy chờ
Tải xuống
Professional ASP.NET 3.5 in C# and Visual Basic Part 51. Building on the revolutionary ASP.NET 2.0 release, ASP.NET 3.5 adds several key new developer features including AJAX, LINQ, and a new CSS designer in Visual Web Developer 2008. The dramatic reduction in code that developers realized from the more than 50 new server controls in ASP.NET 2.0 now allows developers the time to make their applications more interactive with AJAX, to work with data in their preferred language with LINQ, and to build visually attractive and consistent standards-based sites with CSS. . | Chapter 9 Querying with LINQ Listing 9-1 A basic Movie class VB Imports Microsoft.VisualBasic Public Class Movie Private _title As String Private _director As String Private _genre As Integer Private _runtime As Integer Private _releasedate As DateTime Public Property Title As String Get Return _title End Get Set ByVal value As String _title value End Set End Property Public Property Director As String Get Return _director End Get Set ByVal value As String _director value End Set End Property Public Property Genre As Integer Get Return _genre End Get Set ByVal value As Integer _genre value End Set End Property Public Property Runtime As Integer Get Return _runtime End Get Set ByVal value As Integer _runtime value End Set End Property Public Property ReleaseDate As DateTime Get Return _releasedate End Get Set ByVal value As DateTime 456 Chapter 9 Querying with LINQ _releasedate value End Set End Property End Class C using System public class Movie public string Title get set public string Director get set public int Genre get set public int RunTime get set public DateTime ReleaseDate get set This is the basic class that is used throughout this section and the following LINQ to Object section. Now that you have a basic class to work with let s look at how you would normally use the class. Listing 9-2 demonstrates how to create a simple generic List of the Movie objects in an ASP.NET page and then binding that list to a GridView control. The GridView displays the values of all public properties exposed by the Movie class. Listing 9-2 Generating a list of Movie objects and binding to a GridView VB @ Page Language VB @ Import Namespace System.Collections.Generic script runat server Protected Sub Page_Load ByVal sender As Object ByVal e As System.EventArgs Dim movies GetMovies Me.GridViewl.DataSource movies Me.GridView1.DataBind End Sub Public Function GetMovies As List Of Movie Dim movies As Movie _ New Movie With .Title Shrek .Director Andrew Adamson _ .Genre 0 .