Link to home
Start Free TrialLog in
Avatar of Rhondal Starks
Rhondal Starks

asked on

Access a nested repeaters controls propeties

Hi,
 I Have two repeaters one nested inside the other. During the page load in vb code behind I need to be able to access the button1,button2, and button3 visible property inside the child repeater . I want to be able to make these buttons visible or invisible based on users variables. Right now I can't figure out how to access those properties I the page load, Please help.  I pasted the Page and its code behind below.

<%@ Page Title="" Language="VB" MasterPageFile="~/EEMainMaster.master" AutoEventWireup="false" CodeFile="testrepeator.aspx.vb" Inherits="testrepeator" %>

<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>

<script type="text/javascript">

    $("body").on("click", "[src*=plus]", function () {

        $(this).closest("tr").after("<tr><td></td><td colspan = '999'>" + $(this).next().html() + "</td></tr>")

        $(this).attr("src", "images/minus.png");

    });

    $("body").on("click", "[src*=minus]", function () {

        $(this).attr("src", "images/plus.png");

        $(this).closest("tr").next().remove();

    });

</script>
    <H1 style="text-align:center" >Communications Committee Activities</H1>
    <asp:Repeater ID="rptCustomers" runat="server" OnItemDataBound="OnItemDataBound">

    <HeaderTemplate>

        <table style="width: 100%"class="Grid" cellspacing="0" rules="all" border="0">

         

    </HeaderTemplate>

    <ItemTemplate>
        <tr>
             <td align="bottom" colspan=" 4">

                 <span  style="width:33%;font-weight:bold" >
                     <asp:Image ID="Image2" runat="server" ImageUrl="~/imgs/Gear.jpg" Width ="23px" Height="23px" /><%# Eval("Activityshortname")%></span>
                 <span  style="width:33%" ><%# Eval("ActivityfullDescription") %></span>
                 <span  style="width:33%;font-weight:bold" > This has been assigned to the <%# Eval("[Committee Asigned to]") %></span>
                 <%--<asp:label  ID="HiddenField1" runat="server" text='<%# Eval("ActivityID")%>' BorderWidth="1" />--%>
                 <%--<asp:Label ID="lblContactName"     runat="server" Text='<%# Eval("Activityshortname")%>' />--%>
                 <asp:label visible="false" ID="HiddenField1" runat="server" text='<%# Eval("ActivityID")%>' /> <br />
                 
                 
                                       
                       
                             <br />
                 <asp:TextBox ID="TextBox2" placeholder='<%# "Add a comments here for [" + Eval("Activityshortname").toupper + "]"%>'  style="width:50%;height:44px" runat="server" MaxLength="0" TextMode="MultiLine">
                 </asp:TextBox><asp:Button ID="button2" class="button button4" runat="server" Text="Post it"  OnClick="GetValue"  /><br />  
            </td>

           

        </tr>
        <tr>

            <td colspan ="4" >

               

                    <asp:Repeater ID="rptOrders" runat="server" >

                        <HeaderTemplate>
                            <Center>
                            <table style="width: 85%" cellspacing="0" rules="all" border="0">

                                <tr>
                                   
                                    <th scope="col" style ="width: 150px;background-clip: padding-box;background-color: white;color: Black;border: 5px solid white;">
                                        Comments

                                    </th>
                                     
                                 
                                       

                                    </th>

                                </tr>

                        </HeaderTemplate>

                        <ItemTemplate>

                            <tr>
                               
                                <td style ="background-clip: padding-box;background-color: lightgrey;color: Black;border: 5px solid white;" >

                                   
                                    <asp:Image ID="Image1" runat="server" ImageUrl="~/imgs/Avatar.jpg" Width ="25px" Height="25px" />
                                    <span style="font-weight:bold"><%# Eval("Title")%> <%# Eval("FirstName")%> <%# Eval("LastName")%></span> <br /> <span style="font-weight:bold;color:#A4A4A4">Comment <%# Eval("Status")%></span><br />
                                    <asp:Label ID="lblOrderDate" runat="server" Text='<%# Eval("[RecNote]")%>' /> <span style="font-weight:bold">
                                   
                                       
                                </td>
                               
                                <td style ="width:5%;background-clip: padding-box;background-color: white;color: Black;border: 5px solid white;" >

                                    <asp:Button ID="button2" class="button button4" runat="server" Text="Approve"  OnClick="GetValue"  />
                                 
                                   
                                </td>
                                <td style ="width:5%;background-clip: padding-box;background-color: white;color: Black;border: 5px solid white;" >
                                    <asp:Button ID="button3" class="partApprovebutton button4" runat="server" Text="Part APP"  OnClick="GetValue"  />
                                </td>
                                <td style ="width:5%;background-clip: padding-box;background-color: white;color: Black;border: 5px solid white;" >
                                    <asp:Button ID="button1" class="Denybutton button4" runat="server" Text="Deny"  OnClick="GetValue"  />
                                </td>
                            </tr>

                        </ItemTemplate>

                        <FooterTemplate>

                            </table></Center>

                        </FooterTemplate>

                    </asp:Repeater>

                </asp:Panel>

                <asp:HiddenField ID="hfActivityId" runat="server" Value='<%# Eval("ActivityID")%>' />
               

            </td>

           
        </tr>

    </ItemTemplate>

    <FooterTemplate>

        </table>

    </FooterTemplate>

</asp:Repeater>


    </asp:Content>


VBCODEBEHIND__________________________________________________


Imports System.Data
Imports System.Data.SqlClient
Imports System.Configuration
Partial Class testrepeator
    Inherits System.Web.UI.Page


    Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
        Dim SqlSelectString As String

        SqlSelectString = "SQL Statement)"
        If Not Me.IsPostBack Then

            ' rptCustomers.DataSource = GetData("SQL Statement")
            rptCustomers.DataSource = GetData(SqlSelectString)

            rptCustomers.DataBind()

        End If
    End Sub
   


    Private Shared Function GetData(query As String) As DataTable

        Dim constr As String = ConfigurationManager.ConnectionStrings("StrategicPlanConnectionString").ConnectionString

        Using con As New SqlConnection(constr)

            Using cmd As New SqlCommand()

                cmd.CommandText = query

                Using sda As New SqlDataAdapter()

                    cmd.Connection = con

                    sda.SelectCommand = cmd

                    Using ds As New DataSet()

                        Dim dt As New DataTable()

                        sda.Fill(dt)

                        Return dt

                    End Using

                End Using

            End Using

        End Using

    End Function
    Protected Sub OnItemDataBound(sender As Object, e As RepeaterItemEventArgs)

        If e.Item.ItemType = ListItemType.Item OrElse e.Item.ItemType = ListItemType.AlternatingItem Then

            Dim customerId As String = TryCast(e.Item.FindControl("hfActivityId"), HiddenField).Value

            Dim rptOrders As Repeater = TryCast(e.Item.FindControl("rptOrders"), Repeater)

            'rptOrders.DataSource = GetData(String.Format("SQL STatement))

            rptOrders.DataSource = GetData(String.Format("SQL Statement")

            rptOrders.DataBind()

        End If
    End Sub

    Protected Sub GetValue(ByVal sender As Object, ByVal e As EventArgs)

        'Reference the Repeater Item using Button.

        Dim item As RepeaterItem = TryCast((TryCast(sender, Button)).NamingContainer, RepeaterItem)



        'Reference the Label and TextBox.

        ' Dim message As String = "Customer Id: " & (TryCast(item.FindControl("lblCustomerId"), Label)).Text
        Dim message As String = " Id and comment : " & (TryCast(item.FindControl("TextBox2"), TextBox)).Text

       
        message += "\nCountry: " & (TryCast(item.FindControl("HiddenField1"), Label)).Text




        ClientScript.RegisterStartupScript(Me.GetType(), "alert", "alert('" & message & "');", True)

    End Sub

   

End Class
ASKER CERTIFIED SOLUTION
Avatar of Rhondal Starks
Rhondal Starks

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial