<asp:ListView ID="lvSharingList" runat="server" OnItemDataBound="lvSharingList_ItemDataBound">
<LayoutTemplate>
<table id="tblList" runat="server" style="width: 100%;">
<tr runat="server" id="itemPlaceHolder" style="border: 1px solid rgb(208, 208, 208);"></tr>
</table>
</LayoutTemplate>
<ItemTemplate>
<tr runat="server" id="tableRow" class="trShareItem" style="border: 1px solid rgb(208, 208, 208);">
<td runat="server" id="tableCell">
<div style="width: 10%; float: left; padding: 5px 5px; margin: 5px 5px; border: 1px solid rgb(208, 208, 208);">
<asp:Label Visible="false" ID="lblGroupId" Text='<%# Eval("GroupId") %>' runat="server"></asp:Label>
<asp:Label Visible="false" ID="lblShareId" Text='<%# Eval("ShareId") %>' runat="server"></asp:Label>
<asp:Image ID="imageForFriend" runat="server" CssClass="fromUsername" AlternateText='<%# Eval("Username") %>' />
<br />
<a href="#" id="aUsername2" runat="server" title='<%# Eval("Username") %>'></a>
</div>
<div style="width: 45%; float: left; padding: 5px 5px; margin: 5px 5px; border: 1px solid rgb(208, 208, 208);">
<asp:Label ID="lblPost" Text='<%# Eval("Post")%>' runat="server" CssClass="sharedPost"></asp:Label><br />
<abbr id="abbrId" class="timeago" title='<%# DataBinder.Eval(Container.DataItem, "PostedDate", "{0:M/d/yyyy hh:mm:ss tt}") %>' runat="server"></abbr>
<asp:Label runat="server" ID="lblImgFlag" Text='<%# Eval("imgFlag") %>' Visible="false"></asp:Label>
<asp:Image ID="imagePhoto" runat="server" CssClass="sharePhotoFile" />
<asp:Literal ID="literal" runat="server" Text='<%# Eval("video") %>'></asp:Literal>
</div>
<div style="width: 38%; float: left; height: 100%;">
<div>
<fieldset>
<legend>Comments</legend>
<asp:UpdatePanel ID="UpdatePanelToResetComment" runat="server">
<ContentTemplate>
<a href="#" runat="server" id="aUsernameForComment"></a>
<asp:TextBox ID="txtShareComment" runat="server" CssClass="txtShareCommentClass"></asp:TextBox>
<asp:Button ID="btnComment" UseSubmitBehavior="false" runat="server" Text="Comment" CssClass="btn btn-small btn-primary" OnClick="btnComment_Click" />
</ContentTemplate>
</asp:UpdatePanel>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:ListView ID="listViewShareComments" runat="server">
<LayoutTemplate>
<ul id="itemPlaceHolder" runat="server">
</ul>
</LayoutTemplate>
<ItemTemplate>
<asp:Label ID="lblUsernameID" runat="server" Text='<%# Eval("Username") %>' CssClass="txtShareCommentClass"></asp:Label> :
<asp:Label ID="txtShareCommentID" runat="server" Text='<%# Eval("Comment") %>' CssClass="txtShareCommentClass"></asp:Label>
</ItemTemplate>
<ItemSeparatorTemplate>
<br />
</ItemSeparatorTemplate>
</asp:ListView>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="btnComment" EventName="Click" />
</Triggers>
</asp:UpdatePanel>
</fieldset>
</div>
</div>
</td>
</tr>
</ItemTemplate>
</asp:ListView>
I have the above example and I would like to know the best approach to locate a control within a child control. In the above example I have a ListView control that has a tableRow followed by tableCell. I have a listview within the tableCell. Why cant I locate the child listview directly from the page control? Why do I have to locate each runat=server control and then find the child control?
The following way works fine! I would like to know is there a better way to locate the child listview control?
HtmlTableCell tCell = (HtmlTableCell)lblShaId.Parent;
UpdatePanel updatePanel1 = (UpdatePanel)tCell.FindControl("UpdatePanel1");
ListView listViewShareComments1 = (ListView)updatePanel1.FindControl("listViewShareComments");
listViewShareComments1.DataSource = userMethods.GetAdminGroupShareComments(Convert.ToInt32(lblShaId.Text));
listViewShareComments1.DataBind();