Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7446743
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T12:23:49+00:00 2026-05-29T12:23:49+00:00

I have List view – ( name: ListViewName ), with some labels inside it,

  • 0

I have List view – (

name: ListViewName

), with some labels inside it, the ID (name) of the label:

Biglbl

.. big because its include some links and titles.

there is one more label in name:

lblCatName

which return the category name.

I want to check each list view item – what is name (let’s say – “TEST”) and hide or display some labels or change HyperLink navigateUrl.

aspx:

 <asp:ListView ID="ListViewName" OnItemDataBound="ContactsListView_ItemDataBound" runat="server">
        <ItemTemplate>

        <asp:Label Visible="true"  ID="lblCName" Text='<%# Eval("CatName") %>' runat="server" > </asp:Label>

  <asp:Label runat="server" id="lblCName" Visible="false" />
              <div style=".....">

       ...............


         <asp:HyperLink ID="HyperLink4" runat="server" 
      NavigateUrl='<%# "bla.aspx?Id=" + Eval("id").ToString() %>'> 


                  </asp:HyperLink>

         <asp:HyperLink ID="HyperLink7" runat="server" 
      NavigateUrl='<%# "bla.aspx?Id=" + Eval("CatId").ToString() %>'>  <img src="images/btblue.png" /> </asp:HyperLink>

    </asp:Label>  

    </div>


        </ItemTemplate>
        </asp:ListView>

I have the C# code behind:

protected void ContactsListView_ItemDataBound(object sender,ListViewItemEventArgs e)
{
            foreach (ListViewItem item in ListViewName.Items)
        {

            Biglbl = (Label)e.Item.FindControl("Biglbl");
            Label lblCName = (Label)e.Item.FindControl("lblCatName");

            HyperLink Link = (HyperLink)e.Item.FindControl("HyperLink4");
            HyperLink Link2 = (HyperLink)e.Item.FindControl("HyperLink7");

            if (lblCatName.ToString() == "TEST")
            {
                Biglbl.Visible = true;
                Link.NavigateUrl = "blabla";
                Link2.NavigateUrl = "blabla";
            }
            else
            {
                Biglbl.Visible = false;
                Link.NavigateUrl = "aaaa";
                Link2.NavigateUrl = "aaaa";
            }

        }
}

I don’t know how to use the foreache for my needs here.

What i need to do (i think the if and the findcontrol’s are fine.. i need to do what to change in the foreac.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T12:23:50+00:00Added an answer on May 29, 2026 at 12:23 pm
    foreach (ListViewItem item in ListViewName.Items)
    {
      // Code goes here.
    }
    

    EDIT: I see the question now shows you using ItemDataBound. This will pass you each ListViewItem as it is bound so there is no need to do a for each loop.

    You can simply cast the sender to that type

    ListViewItem item = (ListViewItem)sender;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a simple list view with some check boxes in an alert dialog.
i have list view inside list view a button when i click button list
I have a list view that looks like this and that's its code ..
I have a list view with a label that shows Step #x, another label
I have a list view with several columns; things such as name, date, etc.
I have a list view control which at the moment only allows one item
I have a list view that is periodically updated (every 60 seconds). It was
I have a list view filled with data. I set up a context menu
I currently have a list view which has several rows of data and I
Hello i have a list view control, While the form is being loaded i

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.