Click here to Skip to main content
15,030,781 members
Articles / Web Development / HTML
Posted 18 Apr 2006


24 bookmarked

Find child controls inside a MultiView control in

Rate me:
Please Sign up or sign in to vote.
2.27/5 (4 votes)
18 Apr 20062 min read
Finding a Label control inside a FormView which is a child control of MultiView

Find child controls inside a MultiView

[Finding a Label control inside a FormView which is a child control of MultiView]

Article Contents:

·         Overview

·         Section 1: Using MultiView and View in ASP.NET 2.0

·         Section 2: Finding Child Controls inside MultiView

·         Conclusion


In ASP.NET 1.x, the Panel control was used to segregate controls into groups. Many developers would use a Panel to hide or show controls for a particular purpose. For instance, if the user clicked on a particular button, a DataGrid may appear. However, if the user clicked on a different button, a graph may appear.

In ASP.NET 2.0, the MultiView and View controls were introduced. The MultiView control acts as a stand-alone Panel-like control, or can be a container for multiple Panel-like controls called Views. Using the new MultiView control with the View control allows developers an even easier way to toggle between "Panels".

Section 1: Using MultiView and View in ASP.NET 2.0

Here is an example of using FormView inside the MultiView and View controls within ASP.NET 2.0:

<html xmlns="" >

<head runat="server">

    <title>Untitled Page</title>



<form id="form1" runat="server">


    <asp:MultiView id="MultiView1" runat="server" ActiveViewIndex=0>

     <asp:View id="View1" runat="server">

    Content Here (View 1)...

       <asp:FormView ID="FormView1" runat="server"




            <asp:Label ID="Field1Label" runat="server"

         Text='<%# Bind("Field1") %>'></asp:Label><br />


            <asp:Label ID="Field2Label" runat="server"

         Text='<%# Bind("Field2") %>'></asp:Label><br />



        <asp:SqlDataSource ID="SqlDataSource1" runat="server"

     ConnectionString="<%$ ConnectionStrings:ConnectionString %>"

        SelectCommand="SELECT [Field1], [Field2] FROM [TestTable]">



   <asp:View id="View2" runat="server">      

           Content Here (View 2)...


   <asp:View id="View3" runat="server">

           Content Here (View 3)...



 <asp:Button ID="Button1" runat="server" Text="Button" />





Section 2: Finding Child Controls inside MultiView

In the above HTML content we have a label control with ID="Field1Label". We are going to find value in this particular label as follows. Following code executes in the button click event of button with ID="Button1".

Sub GetControlValue()

  Section 1: Finding the first child control i.e. FormView

  Dim FormView As FormView=CType(MultiView1.Views(0).FindControl("FormView1"), FormView)

  Section 2: Finding the second child control i.e. Label

   If FormView.CurrentMode = FormViewMode.ReadOnly Then

     Dim Field1_Label As Label = CType(FormView.Row.FindControl("Field1Label"), Label)


  End If

Note: FormView have 3 different type of Templates.

1.    ReadOnly Mode [ItemTemplate]

2.    Edit Mode [Edit ItemTemplate]

3.    Insert Mode [Insert ItemTemplate]

You should specify template of formview in which the control is embeded with formview property “CurrentMode” as above.

Protected Sub Button1_Click(ByVal sender _
    As Object, ByVal e As System.EventArgs)Handles Button1.Click
End Sub


Hope you can find some use for this article.


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

Bindu Shajudeen
Web Developer
United Arab Emirates United Arab Emirates

Comments and Discussions

GeneralMy vote of 3 Pin
Ahmed k dema12-Mar-12 21:43
MemberAhmed k dema12-Mar-12 21:43 
GeneralMy vote of 1 Pin
Dave Kreskowiak19-Jan-10 6:28
mveDave Kreskowiak19-Jan-10 6:28 
GeneralMy vote of 1 Pin
Guennady Vanin4-Dec-09 6:20
MemberGuennady Vanin4-Dec-09 6:20 
QuestionPlease can someone help with this question... Pin
JackChase31-Mar-07 14:48
MemberJackChase31-Mar-07 14:48 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.