473,569 Members | 2,834 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

variable label control

I'm trying to use a for() loop to go through a set of labels and set their
visibility to false.

I had to do something like

Code:

for(int i=1;i<=10;i++)
{
labeli.visible = false;
}

or
for(int i=1;i<=10;i++)
{
String s;
s=("Label"+i);
Label lab=new Label();
lab.ID=s;
lab.Visible=fal se;

}

but i am not getting how to do that pls help
Nov 19 '05 #1
8 1693
Hi,

Use the page object's controls collection
e.g

int i = 1;
foreach (Control ctl in Page.Controls)
{
if (ctl.name == "label" & i)
{
ctl.visible = false;
}
}

Well, this might not be the cleanest way. But this can be the way to go

HTH
Kalpesh

Nov 19 '05 #2
Kalpesh wrote:
Hi,

Use the page object's controls collection
e.g

int i = 1;
foreach (Control ctl in Page.Controls)
{
if (ctl.name == "label" & i)
{
ctl.visible = false;
}
}

Well, this might not be the cleanest way. But this can be the way to
go

HTH
Kalpesh


Two remarks:
1) the "&" operator is "bitwise AND" in C# (and string-concat in VB).
Use "+" to concatenate strings in C#
2) the Controls collection lists only one level deep. You need to call this
recursively to find "deeper" controls

Hans Kesting
Nov 19 '05 #3
Thanks Hans for correcting :)
I assumed that the label controls are those put by the user explicitly

Kalpesh

Nov 19 '05 #4
thanks
"Kalpesh" <sh*********@gm ail.com> wrote in message
news:11******** **************@ g47g2000cwa.goo glegroups.com.. .
Thanks Hans for correcting :)
I assumed that the label controls are those put by the user explicitly

Kalpesh

Nov 19 '05 #5
i am not able to get ctl.name
when i write ctl.
i doesn't show property named "name"

"Kalpesh" <sh*********@gm ail.com> wrote in message
news:11******** **************@ g47g2000cwa.goo glegroups.com.. .
Thanks Hans for correcting :)
I assumed that the label controls are those put by the user explicitly

Kalpesh

Nov 19 '05 #6
Use the ID property. Thats the name with which you identify a control
on server side execution

HTH
Kalpesh

Nov 19 '05 #7
Hi Ankit,

System.Web.UI.C ontrol only has "ID" property to identify itself, not
"Name". Also, we need to search from the HtmlForm control to loop all the
labels you defined at the top page level( directly under the <form
runat=server>.. .</from> rather than nested in other container controls).
The following code is just a simple example to loop all the top level
labels:

=============== =====
HtmlForm form1 = Page.FindContro l("Form1") as HtmlForm;

foreach(Control ctrl in form1.Controls)
{
if(ctrl is Label)
{
Response.Write( "<br>" + ctrl.ID);
}
}
=============== =====

Hope helps. Thanks,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

--------------------
| From: "Ankit Aneja" <ef*****@newsgr oups.nospam>
| References: <un************ *@TK2MSFTNGP12. phx.gbl>
<11************ *********@f14g2 000cwb.googlegr oups.com>
<#N************ **@TK2MSFTNGP10 .phx.gbl>
<11************ **********@g47g 2000cwa.googleg roups.com>
| Subject: Re: variable label control
| Date: Tue, 18 Oct 2005 15:04:54 +0530
| Lines: 10
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2800.1106
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1106
| Message-ID: <en************ **@TK2MSFTNGP15 .phx.gbl>
| Newsgroups: microsoft.publi c.dotnet.framew ork.aspnet
| NNTP-Posting-Host: dsl-del-dynamic-032.76.246.61.t ouchtelindia.ne t
61.246.76.32
| Path: TK2MSFTNGXA01.p hx.gbl!TK2MSFTN GP08.phx.gbl!TK 2MSFTNGP15.phx. gbl
| Xref: TK2MSFTNGXA01.p hx.gbl
microsoft.publi c.dotnet.framew ork.aspnet:1320 25
| X-Tomcat-NG: microsoft.publi c.dotnet.framew ork.aspnet
|
| thanks
| "Kalpesh" <sh*********@gm ail.com> wrote in message
| news:11******** **************@ g47g2000cwa.goo glegroups.com.. .
| > Thanks Hans for correcting :)
| > I assumed that the label controls are those put by the user explicitly
| >
| > Kalpesh
| >
|
|
|

Nov 19 '05 #8
Solved thanks
"Kalpesh" <sh*********@gm ail.com> wrote in message
news:11******** **************@ o13g2000cwo.goo glegroups.com.. .
Use the ID property. Thats the name with which you identify a control
on server side execution

HTH
Kalpesh

Nov 19 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1824
by: beanweed | last post by:
BACKGROUND ---------- I have an ASP.NET application having two panels. In one panel, an XML document, transformed using xsl, is displayed. In the other panel are some controls that allow a user to change the xml. For example, each "l_item" element appears as a row in a table labelled with a "label"; so if I have <l_item id="1">...
7
1463
by: Jeff Johnson | last post by:
Hi Everyone, I have a page with numerous label controls with the Visible attribute set to false. On page_load I loop through an array and depending on what is returned for each label, I want to set the Visible attribute to true as well as a number of other attributes. Instead of having a lengthy switch statement listing all of the label
5
1980
by: Michelle A. | last post by:
I have a four page form. Pages 1-3 stores there information in a session variables. Page four is reached (a final review page) and then the information will be written to the SQL server. When I tried to enter some code in the HTML table by hand so I could get it to show up in the right place. For example I use this code in the HTML...
6
6923
by: Joe | last post by:
I know that the Literal control will not render a <span> tag so I can not format its text. Other than this, what is the difference betwen the Literal control and the LiteralControl Control? How about a LiteralControl and a Label? Other than the lack of being able to format the Literal control's text, I don't see much of a difference in...
4
2651
by: simon | last post by:
hello. relatively new to vb.net, i'm using VS 2003 and .net 2.0 i have a web app that i'm i have a user control that displays a simple 1 row table as the header of the page. the user control takes one input variable, the string that will be displayed as the title of the page. example call: <uc1:Header runat=server ID="ucHeader"...
10
7098
by: John Salerno | last post by:
If I want to have a list like this: where the first part of each tuple is a variable name and the second part is a label for the user to see, such as a form like this: First Name: ________ Last Name: ________
4
1530
by: Phillip Vong | last post by:
I'm using VS2005 and creating a simple test ASPX page in VB. I have a simple FORMVIEW1 with a label "YTDLabel" databound to a SQL DB. The DB datatype is set to decimal (18,2) and the value of this cell is 16.1. Here is my simple Page_Load code and all I want it to do is see if the decimal figure is greater than 1, if it is, then hide the...
2
3847
by: rn5a | last post by:
Consider the following code: <script runat="server"> Sub ShowData(obj As Object, ea As EventArgs) lblDate.Text = DateTime.Now.ToString("d") lblDate.DataBind() End Sub </script> <form runat="server"> <asp:Label ID="lblDate" OnDataBinding="ShowData" runat="server"/>
1
3675
by: sap0321 | last post by:
This should be kindergarten stuff but for some reason I am having trouble with it. I do 99.9% web programming and this is the first windows app i've done in years - probably the first ever in C# ... anyway ... Here is what I am trying to do .... Windows app - with a main "navigation" form with 4 linkbuttons on it - each of them open a...
0
7693
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7605
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7917
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8118
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7665
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
1
5501
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3651
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3631
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2105
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.