Đang chuẩn bị liên kết để tải về tài liệu:
ASP.NET 4 Unleased - p 169

Đang chuẩn bị nút TẢI XUỐNG, xin hãy chờ

Building Templated Databound Controls container.Controls.Add(lblTitle); container.Controls.Add(new LiteralControl(“”)); container.Controls.Add(lblAuthor); container.Controls.Add(new LiteralControl(“”)); container.Controls.Add(lblContents); } void lblTitle_DataBinding(object sender, EventArgs e) { Label lblTitle = (Label)sender; ArticleWithDefault container = ➥(ArticleWithDefault)lblTitle.NamingContainer; lblTitle.Text = container.Title; } void lblAuthor_DataBinding(object sender, EventArgs e) { Label lblAuthor = (Label)sender; ArticleWithDefault container = ➥(ArticleWithDefault)lblAuthor.NamingContainer; lblAuthor.Text = container.Author; } void lblContents_DataBinding(object sender, EventArgs e) { Label lblContents = (Label)sender; ArticleWithDefault container = ➥(ArticleWithDefault)lblContents.NamingContainer; lblContents.Text = container.Contents; } } } The control in Listing 37.3 is similar to the control created in the previous. | 1654 CHAPTER 37 Building Templated Databound Controls container.Controls.Add lblTitle container.Controls.Add new LiteralControl br container.Controls.Add lblAuthor container.Controls.Add new LiteralControl br container.Controls.Add lblContents void lblTitle_DataBinding object sender EventArgs e Label lblTitle Label sender ArticleWithDefault container ArticleWithDefault lblTitle.NamingContainer lblTitle.Text container.Title void lblAuthor_DataBinding object sender EventArgs e Label lblAuthor Label sender ArticleWithDefault container ArticleWithDefault lblAuthor.NamingContainer lblAuthor.Text container.Author void lblContents_DataBinding object sender EventArgs e Label lblContents Label sender ArticleWithDefault container ArticleWithDefault lblContents.NamingContainer lblContents.Text container.Contents The control in Listing 37.3 is similar to the control created in the previous section however the CreateChildControls method has been modified. The new version of the CreateChildControls method tests whether there is an ItemTemplate. If no ItemTemplate exists an instance of the ArticleDefaultTemplate class is created. The ArticleDefaultTemplate class which is also included in Listing 37.3 implements the ITemplate interface. In particular the class implements the InstantiateIn method which creates all the controls that appear in the template. In Listing 37.3 three Label controls are created that correspond to the Title Author and Contents properties. The DataBinding event is handled for all three of these Label From the Library of Wow eBook Creating Templated Controls 1655 controls. When the DataBind method is called the DataBinding event is raised for each child control in the Article control. At that time the values of the Title Author and Contents properties are assigned to the Text properties of the Label controls. The page in Listing 37.4 illustrates how you can use the modified Article control. LISTING 37.4 ShowArticleWithDefault.aspx @ Page Language C @ Register

TÀI LIỆU LIÊN QUAN
TAILIEUCHUNG - Chia sẻ tài liệu không giới hạn
Địa chỉ : 444 Hoang Hoa Tham, Hanoi, Viet Nam
Website : tailieuchung.com
Email : tailieuchung20@gmail.com
Tailieuchung.com là thư viện tài liệu trực tuyến, nơi chia sẽ trao đổi hàng triệu tài liệu như luận văn đồ án, sách, giáo trình, đề thi.
Chúng tôi không chịu trách nhiệm liên quan đến các vấn đề bản quyền nội dung tài liệu được thành viên tự nguyện đăng tải lên, nếu phát hiện thấy tài liệu xấu hoặc tài liệu có bản quyền xin hãy email cho chúng tôi.
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.