Controls You Can Use on Web Forms ASP.NET IE WebControls MultiView WebControl
In certain cases, you may need to obtain information from a data source and present the data into multiple views.
The MultiView and View controls by themselves cannot be bound to a data source. But when a MultiView is declared within the ItemTemplate of a data control, such as a FormView or DataList control, the HTML and controls within each of the View objects can be bound to the parent control’s data source, using the same databinding techniques that apply to any other ASP.NET control.
Let us briefly explore how that is done.
- The procedure for adding a MultiView within a data control is basically the same as adding a standalone MultiView, except that the control must be defined within the ItemTemplate of the parent control, in this case a FormView control.
<formview runat="server">
<itemtemplate>
<ie:multiview id="multiview1" runat="server">
... individual views markup goes here ...
</ie:multiview>
</itemtemplate>
</formview>
- In this example, the interface for page navigation is done via <
asp:linkbutton
> controls defined in the SelectedItemTemplate of the DataList control that is used for record selection.
<selecteditemtemplate>
... some code omitted for clarity ...
<asp:linkbutton runat="server"
text="Intro"
commandname="intro"
style="font-size:9pt" />
|
<asp:linkbutton runat="server"
text="Features"
commandname="features"
style="font-size:9pt" />
|
<asp:linkbutton runat="server"
text="Specs"
commandname="specs"
style="font-size:9pt" />
</selecteditemtemplate>
- The code for navigating the MultiView invokes the SetActiveView method of the MultiView control in the ItemCommand event handler of the DataList.
void getPlan ( object src, DataListCommandEventArgs e ) {
... some code omitted for clarity ...
MultiView planInfo = ( MultiView ) fvPlan.FindControl ( "planInfo" );
switch ( e.CommandName ) {
case "intro" :
View intro = ( View ) fvPlan.FindControl ( "intro" );
planInfo.SetActiveView ( intro );
break;
case "features" :
View features = ( View ) fvPlan.FindControl ( "features" );
planInfo.SetActiveView ( features );
break;
case "specs" :
View specs = ( View ) fvPlan.FindControl ( "specs" );
planInfo.SetActiveView ( specs );
break;
}
}
And in case you have not noticed, most of the MultiView examples in this workshop are used within a data control.
Nesting MultiView Controls Navigating Views in the MultiView Control