13.4. Using Server Controls with LINQ Queries

So far you have seen one way to bind the results of a LINQ query to a control in your ASPX page: assign the data to the control's DataSource property and then call DataBind. This way of getting data into the controls has a few shortcomings. First of all, this method does not support the editing, updating, and deleting of data directly. Secondly, since you define the data source in the Code Behind, the GridView doesn't know what data you're feeding it until run time, so you get no tool support to set up its columns. These shortcomings are easy to overcome by using the new server controls, including the ListView and the LinqDataSource control.

13.4.1. New Controls Introduced in ASP.NET 3.5

Together with LINQ, Microsoft introduced three new controls in ASP.NET 3.5 that enable you to build rich web interfaces with little to no code in no time. Two of them provide a visual interface in your ASP.NET pages, while the third one works as a bridge between your data-bound controls and your underlying data sources. The following table briefly introduces you to these new controls.

ControlDescription
LinqDataSourceAs with the SqlDataSource that you saw in previous chapters, the LinqDataSource works as a bridge between your data-bound controls and your underlying data sources. This data source can be any of the types that LINQ supports, including SQL Server databases, XML documents, and even arrays and collections. This chapter looks at the LinqDataSource ...

Get Beginning ASP.NET 3.5: In C# and VB now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.