Prev | Current Page 427 | Next

Rob Cameron and Dale Michalk

"Pro ASP.NET 3.5 Server Controls and AJAX Components"


Figure 7-9. The Dynamic Templates web form and FileTemplate.ascx
The actual code for the .ascx file is shown in Listing 7-10. Notice that we did not have to
include the container tags.
CHAPTER 7 ?–  SERVER CONTROL DATA B INDING 325
Listing 7-10. The FileTemplate and CustFileTemplate .ascx Files
<%@ Control Language="C#" AutoEventWireup="true"
CodeBehind="FileTemplate.ascx.cs"
Inherits="ControlsBook2Web.Ch07.FileTemplate" %>
Contact:

<%# DataBinder.Eval(Container, "DataItem.ContactName") %>


<%@ Control Language="C#" AutoEventWireup="true"
CodeBehind="CustFileTemplate.ascx.cs"
Inherits="ControlsBook2Web.Ch07.CustFileTemplate" %>
Contact:

" />


Because the DropDownList control has the AutoPostBack property set to true, changing
the template used by the Repeater control is as easy as selecting a different template in the
DropDownList control. This causes a postback to occur and executes the code in LoadRepeater
that is responsible for finding the right template and binding it to the Repeater control:
string templateName = templateList.SelectedItem.Text;
if (templateName.IndexOf(".


Pages:
415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439