I'm completely new to using LINQ to SQL (but familiar with LINQ to objects) and I'm curious why the following piece of code throws no exception or errors, but does not create a GridView and bind data to it.
This is in the Page_Load event of a webform:
ContactsDataContext db = new ContactsDataContext();
db.Contacts.Where(x => x.Phone.Length > 0);
GridView gv = new GridView();
gv.DataSource = db.Contacts;
gv.DataBind();
If I drag and drop and GridView in the designer and set the DataSource as LINQ to SQL it works as expected. Markup for LinqDataSource
<asp:LinqDataSource ID="LinqDataSource1" runat="server"
ContextTypeName="LinqExample.ContactsDataContext" EntityTypeName=""
TableName="Contacts">
</asp:LinqDataSource>
Contacts is the only table in the .dbml file. What am I missing?
asp:LinqDataSource? - RudyResponse. So you want it to be both in the cs file? But if so, where in the html do you want the table with the data? - Rudy