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

Stats

65.1K views
24 bookmarked

Find child controls inside a MultiView control in asp.net

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

Overview:

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="http://www.w3.org/1999/xhtml" >

<head runat="server">

    <title>Untitled Page</title>

</head>

<body>

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

<div>

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

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

    Content Here (View 1)...

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

         DataSourceID="SqlDataSource1">

         <ItemTemplate>

            Field1:

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

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

            Field2:

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

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

         </ItemTemplate>

       </asp:FormView>

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

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

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

     </asp:SqlDataSource>

   </asp:View>

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

           Content Here (View 2)...

   </asp:View>

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

           Content Here (View 3)...

   </asp:View>

 </asp:MultiView>

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

</div>

</form>

</body>

</html>

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)

Response.Write(Field1_Label.Text.ToString)

  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.

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

Conclusion

Hope you can find some use for this article.

License

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

Share

About the Author

Bindu Shajudeen
Web Developer
United Arab Emirates United Arab Emirates
MCP

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.