• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1466
  • Last Modified:

Find Label in listview control

Hello experts. I have a listview control (code attatched). And would like to find the control "lblNoMatches".

How would I do this?

Thanks in advance.
Tom


<asp:ListView ID="ListView1" runat="server" DataSourceID="SqlDataSource1" >
                <LayoutTemplate>
                    <div style="float: left; width: 100%; border-top: 2px solid #e20a16; padding-top: 20px; margin-top: 20px;">
                        <asp:PlaceHolder ID="itemPlaceholder" runat="server" />
                    </div>
                    <asp:DataPager ID="DataPager1" runat="server" PagedControlID="ListView1" PageSize="10" style="float: left; width: 100%;">
                        <fields>
                            <asp:nextpreviouspagerfield ButtonType="Link" ShowFirstPageButton="False" ShowNextPageButton="False" ShowPreviousPageButton="True" />
                            <asp:numericpagerfield />
                            <asp:nextpreviouspagerfield ButtonType="Link" ShowLastPageButton="False" ShowNextPageButton="True" ShowPreviousPageButton="False" />
                        </fields>
                    </asp:DataPager>
                </LayoutTemplate>
                <ItemTemplate>
                    <asp:HyperLink ID="HyperLinkName" Text='<%# Eval("pagename") %>' NavigateUrl='<%# "page.aspx?id=" + Eval("Page_ID") %>' style="float: left; color: #e20a16; font-weight: bold; margin-bottom: 5px;" runat="server" />
                    <asp:Label ID="LtrlOverview" Text='<%# Eval("pagetext") + "..." %>' style="float: left; width: 100%; color: #605b54; margin-bottom: 15px;" runat="server" />
                </ItemTemplate>
                <EmptyDataTemplate>
                    <div style="float: left; width: 100%; border-top: 2px solid #e20a16; padding-top: 20px; margin-top: 20px;">
                        <asp:Label ID="lblNoMatches" Text="Sorry, no matches were found!" runat="server" />
                    </div>
                </EmptyDataTemplate>
            </asp:ListView>

Open in new window

0
thomasmutton
Asked:
thomasmutton
1 Solution
 
abadimCommented:
you can call  this method

FindControl("lblNoMatches", ListView1.Controls);



private Control FindControl(string controlID, ControlCollection controls)
 
    {
 
        foreach (Control c in controls)
 
        {
 
            if (c.ID == controlID)
 
                return c;
 
 
 
            if (c.HasControls())
 
            {
 
                Control cTmp = this.FindControl(controlID, c.Controls);
 
                if (cTmp != null)
 
                    return cTmp;
 
            }
 
        }
 
        return null;
 
    }

Open in new window

0
 
thomasmuttonAuthor Commented:
that worked great, thanks!
0

Featured Post

Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now