Tuesday 30 October 2012

Visual Studio 2012 - New - Strongly-typed data bindings with intelliSense

New things in Visual Studio 2012
- Example how to utilize intellisense with strongly typed data bindings (ASP.NET C# Entity Framework).

In previous versions of Visual Studio you could execute the following code in your aspx pages to bind data
<%# Eval("columnName") %>
It works perfectly - just it is lacking intelliSense
In Visual Studio 2012 you can take advantage of IntelliSense while binding data.

Watch this video which shows how to take advantage of IntelliSense while binding data
Or follow these instructions to see the difference between old and new versions of visual studio:

1. Create Empty Web Application

2. Add New WebForm to it, make it start up page
3. Add ADO.NET Entity Framework Model to the project, follow the instructions in order to connect to the database.  In my case I am getting data from DPT table - please watch video above to see step by step instructions.
4. Add repeater to your web form.
        <asp:Repeater ID="Repeater1" runat="server" ItemType="WebApplication4.Dpt">
            <ItemTemplate>

                <ul><%# Eval("DepartmentName") %></ul>
                <ul><%# Item.DepartmentName %></ul>
            </ItemTemplate>
        </asp:Repeater>
- specify ItemType
- old way to do it was with Eval option - it is perfect but lacks IntelliSense
- new way - as soon as you type Item. you will be presented with all your options



In my case table has 2 columns DepartmentId and DepartmentName - both I can select from the list.