Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 563
  • Last Modified:

find <li> control in listview

Hi.

I have a problem.

I want to find the li control from codebehind (to set a activate cssclass)

<asp:ListView ID="lvTopMenu" runat="server" DataSourceID="dsKategorier">
<LayoutTemplate>
<ul runat="server">
      <asp:PlaceHolder ID="itemPlaceholder" runat="server"></asp:PlaceHolder>
</ul>
</LayoutTemplate>
<ItemTemplate>
      <li id="<%# Eval("url") %>"><a href="/kategori/<%# Eval("url") %>" title="<%# Eval("Navn") %>"><%# Eval("Navn") %></a></li>
</ItemTemplate>
</asp:ListView>
<asp:SqlDataSource ID="dsKategorier" runat="server"
ConnectionString="<%$ ConnectionStrings:ShopConnectionString %>"
SelectCommand="SELECT * FROM [table]">
</asp:SqlDataSource>

From my codebehind I try something like:
this works:
ListView lvTopMenu = (ListView)Master.FindControl("lvTopMenu");

this dosent work:
HtmlGenericControl hp = (HtmlGenericControl)lvTopMenu.FindControl("name")

this dosent work
foreach (ListViewItem itemRow in lvTopMenu.Items)
{
    HtmlGenericControl hp = (HtmlGenericControl)itemRow.FindControl("name");
}

Can somebody help me?
0
Jesper Christensen
Asked:
Jesper Christensen
  • 3
  • 2
1 Solution
 
Bill NolanOwner, Lead Technology ProgrammerCommented:
a) Verify that you are searching for the right ID (check the control).
b) Maybe you want Page.FindControl()?
0
 
Jesper ChristensenProgrammerAuthor Commented:
Thanks for the reply. I´m pretty sure that I search with the right name.

It´s the li control i want to find
0
 
Bill NolanOwner, Lead Technology ProgrammerCommented:
Be sure.  Check the IDs in the debugger.
0
 
Jesper ChristensenProgrammerAuthor Commented:
I´m sure :)

I found the listwiew: ListView lvTopMenu = (ListView)Master.FindControl("lvTopMenu");

In my listview i have
<LayoutTemplate>
                    <ul runat="server">
                        <asp:PlaceHolder ID="itemPlaceholder" runat="server"></asp:PlaceHolder>
                    </ul>
                    </LayoutTemplate>
                    <ItemTemplate>
                        <li id="<%# Eval("ID") %>"><a href="/kategori/<%# Eval("url") %>" title="<%# Eval("Navn") %>"><%# Eval("Navn") %></a></li>
                    </ItemTemplate>

I cant find the li elements in the ul
0
 
Bill NolanOwner, Lead Technology ProgrammerCommented:
If you can't find the elements, how are you sure what there ID's are set to?
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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