'______________________________________________________________ ' G E T T I N G T O K N O W L I N Q Step 3 ' C# VERSION ' Ron Kessler ' 2/5/09 ' _____________________________________________________________ ' This time lets limit the number of records to the category they choose from the drop down. ' BE SURE TO SET THIS AS THE STARTUP PAGE IN THE SOLUTION EXPLORER Option Explicit On Imports System.Linq Partial Class Step3 Inherits System.Web.UI.Page Dim dc As New AdventureworksDataContext Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load If (Not Page.IsPostBack) Then '---create the LINQ SQL to fill the list box Dim categories = From cat In dc.ProductCategories _ Select cat ddlCategory.DataSource = categories ddlCategory.DataValueField = "ProductCategoryID" 'data table column name ddlCategory.DataTextField = "Name" 'data table column name '---now link up the grid to display our data ddlCategory.DataBind() 'make it so! End If End Sub Protected Sub ddlCategory_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddlCategory.SelectedIndexChanged '---in the select statement where I want to format $, make sure to use ' an alias for the Grid column...I used "Price". You cannot use eachProduct.ListPrice ' or it will blow up! Dim products = From eachproduct In dc.Products _ Where (eachproduct.ProductCategoryID = Integer.Parse(ddlCategory.SelectedValue)) _ Order By eachproduct.Color _ Select eachproduct.ProductNumber, _ eachproduct.Name, eachproduct.Color, _ Price = String.Format("{0:n2}", eachproduct.ListPrice) GridView1.DataSource = products GridView1.DataBind() 'make it so! End Sub End Class