Interview Tips Interview Tips, Interview Questions and Answers

18Sep/110

Strongly Typed Data Controls in asp.net 5

Strongly Typed Data Controls

The next release of ASP.NET provides the ability to enable strongly-typed data templates.  Specifically, we’ve added the ability to declare what type of data a control is going to be bound to, by way of a new “ModelType” property on data controls.  Setting this property will cause two new typed variables to be generated in the scope of the data-bound template expressions: Item and BindItem.

Developers can use these variables in data-binding expressions and get full Intellisense and compile-time checking support.  For example, below we’ve set the ModelType on an <asp:repeater> control to be a “Customer” object.  Once we do this we can switch from using Eval(“FirstName”) to instead use Item.FirstName to reference the property.

We get full Visual Studio code intellisense when we do so:

 

For 2-way data-binding expressions, we can also now use the BindItem variable and get the same strongly-typed benefits:

<asp:FormView ID="editCustomer" runat="server">

    <EditItemTemplate>

        <div>

            First Name:

            <asp:TextBox ID="firstName" Text='<%# BindItem.FirstName %>' runat="server" />

        </div>

        <div>

            Last Name:

            <asp:TextBox ID="lastName" Text='<%# BindItem.LastName %>' runat="server" />

        </div>

        <asp:Button runat="server" CommandName="Update" />

    </EditItemTemplate>

</asp:FormView>

22Jun/110

ASP.Net Listview Databinding

ASP. Net ListView DataBinding

For presenting data like a list, we have tons of options in Asp.Net like ListView, DataList, Repeater, GridView, DropDownList, etc... Since we have a array of controls to choose from, the control can be selected based on specific requirements. For e.g. there is a need of selecting a single column then DropDownList is the perfect choice. If paging, sorting, edit is required then GridView will be the ideal choice. If just need to repeat some html code, then Repeater will work out to be better. This article is mainly focused on VB.Net ListView DataBinding.
DataBinding is quiet similar to GridView

DataBinding in ListView is almost similar to GridView. There is not much noticeable difference. There should be atleast one ItemPlaceHolder present in the template. By default the name of that is itemPlaceholder. Asp.Net allows us to custom name (id) also for easy reading.
Flexibility in rendering

This ListView is one of the best controls while flexibility is taken into consideration. With the concept of Item Place Holder, we can specify/ configure where the items have to be placed (rotated). In this example, I have made a two column liquid layout . The number of horizontal cells can be adjusted based on the resolution while resizing the browser.
Templates in ListView

There are few templates that will ease the development effort using ListView. If you have worked in GridView earlier, then basic templates in ListView are similar to GridView Templates. There are few special templates. I am highlighting the templates in the following list. These templates can be used customize rendering.

LayoutTemplate
GroupTemplate
ItemTemplate
AlternatingItemTemplate
EditItemTemplate
InsertItemTemplate
ItemSeparatorTemplate
GroupSeparatorTemplate
EmptyItemTemplate
EmptyDataTemplate
SelectedItemTemplate