tailieunhanh - ASP.NET 4 Unleased - p 40
Trong phiên bản , bạn phải sử dụng () khi dữ liệu hiển thị các mục trong mẫu. Tuy nhiên, Microsoft đã tiếc về lập trình sau khi và cung cấp cho chúng tôi với cú pháp ngắn hơn. | 364 CHAPTER 8 Overview of Data Access FIGURE Using databinding expressions. In version you had to use when displaying data items in a template. However Microsoft took pity on programmers after and provided us with the shorter syntax. NOTE Technically the Eval method uses reflection when evaluating the data item to find a property with a certain name. You do pay a performance penalty when you use reflection. As an alternative you can improve the performance of your DataBinding expressions by casting the data items to a particular type like this Title The second DataBinding expression in Listing includes a second parameter. The Eval method optionally accepts a format string. You can use the format string to format values such as dates and currency amounts. In Listing the format string formats the DateReleased column as a long date. From the Library of Wow eBook Understanding Templates and DataBinding Expressions 365 NOTE Format strings use format specifiers such as the D format specifier when formatting strings. You can find a list of format specifiers by looking up Formatting Types in the index of the Microsoft .NET Framework SDK documentation. You can call other methods than the Eval method in a DataBinding expression. For example the DataBinding expression in Listing calls a method named FormatTitle to format the movie titles. LISTING @ Page Language C DOCTYPE html PUBLIC - W3C DTD XHTML EN http TR xhtml11 DTD script runat server public string FormatTitle Object title return b .ToUpper b script html xmlns http 1999 xhtml head id Head1 runat server title Format Movie Titles title head body form id form1 runat server div 8 asp Repeater id Repeater1 DataSourceId srcMovies Runat server ItemTemplate FormatTitle Eval Title hr ItemTemplate asp Repeater asp SqlDataSource id srcMovies .
đang nạp các trang xem trước