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="~/EEMainMa ster.maste r" AutoEventWireup="false" CodeFile="testrepeator.asp x.vb" Inherits="testrepeator" %>
<asp:Content ID="Content1" ContentPlaceHolderID="Cont entPlaceHo lder1" 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").afte r("<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="OnItemDat aBound">
<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-weig ht:bold" >
<asp:Image ID="Image2" runat="server" ImageUrl="~/imgs/Gear.jpg" Width ="23px" Height="23px" /><%# Eval("Activityshortname")% ></span>
<span style="width:33%" ><%# Eval("ActivityfullDescript ion") %></span>
<span style="width:33%;font-weig ht: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:44 px" 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-col or: white;color: Black;border: 5px solid white;">
Comments
</th>
</th>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td style ="background-clip: padding-box;background-col or: lightgrey;color: Black;border: 5px solid white;" >
<asp:Image ID="Image1" runat="server" ImageUrl="~/imgs/Avatar.jp g" Width ="25px" Height="25px" />
<span style="font-weight:bold">< %# Eval("Title")%> <%# Eval("FirstName")%> <%# Eval("LastName")%></span> <br /> <span style="font-weight:bold;co lor:#A4A4A 4">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-col or: 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-col or: 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-col or: 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.Conne ctionStrin gs("Strate gicPlanCon nectionStr ing").Conn ectionStri ng
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.AlternatingIt em Then
Dim customerId As String = TryCast(e.Item.FindControl ("hfActivi tyId"), HiddenField).Value
Dim rptOrders As Repeater = TryCast(e.Item.FindControl ("rptOrder s"), 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( "lblCustom erId"), Label)).Text
Dim message As String = " Id and comment : " & (TryCast(item.FindControl( "TextBox2" ), TextBox)).Text
message += "\nCountry: " & (TryCast(item.FindControl( "HiddenFie ld1"), Label)).Text
ClientScript.RegisterStart upScript(M e.GetType( ), "alert", "alert('" & message & "');", True)
End Sub
End Class
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="~/EEMainMa
<asp:Content ID="Content1" ContentPlaceHolderID="Cont
<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").afte
$(this).attr("src", "images/minus.png");
});
$("body").on("click", "[src*=minus]", function () {
$(this).attr("src", "images/plus.png");
$(this).closest("tr").next
});
</script>
<H1 style="text-align:center" >Communications Committee Activities</H1>
<asp:Repeater ID="rptCustomers" runat="server" OnItemDataBound="OnItemDat
<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-weig
<asp:Image ID="Image2" runat="server" ImageUrl="~/imgs/Gear.jpg"
<span style="width:33%" ><%# Eval("ActivityfullDescript
<span style="width:33%;font-weig
<%--<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").
</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-col
Comments
</th>
</th>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td style ="background-clip: padding-box;background-col
<asp:Image ID="Image1" runat="server" ImageUrl="~/imgs/Avatar.jp
<span style="font-weight:bold"><
<asp:Label ID="lblOrderDate" runat="server" Text='<%# Eval("[RecNote]")%>' /> <span style="font-weight:bold">
</td>
<td style ="width:5%;background-clip
<asp:Button ID="button2" class="button button4" runat="server" Text="Approve" OnClick="GetValue" />
</td>
<td style ="width:5%;background-clip
<asp:Button ID="button3" class="partApprovebutton button4" runat="server" Text="Part APP" OnClick="GetValue" />
</td>
<td style ="width:5%;background-clip
<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.Conne
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.AlternatingIt
Dim customerId As String = TryCast(e.Item.FindControl
Dim rptOrders As Repeater = TryCast(e.Item.FindControl
'rptOrders.DataSource = GetData(String.Format("SQL
rptOrders.DataSource = GetData(String.Format("SQL
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(
Dim message As String = " Id and comment : " & (TryCast(item.FindControl(
message += "\nCountry: " & (TryCast(item.FindControl(
ClientScript.RegisterStart
End Sub
End Class
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.