473,387 Members | 1,844 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

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=false;

}

but i am not getting how to do that pls help
Nov 19 '05 #1
8 1679
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*********@gmail.com> wrote in message
news:11**********************@g47g2000cwa.googlegr oups.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*********@gmail.com> wrote in message
news:11**********************@g47g2000cwa.googlegr oups.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.Control 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.FindControl("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*****@newsgroups.nospam>
| References: <un*************@TK2MSFTNGP12.phx.gbl>
<11*********************@f14g2000cwb.googlegroups. com>
<#N**************@TK2MSFTNGP10.phx.gbl>
<11**********************@g47g2000cwa.googlegroups .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.public.dotnet.framework.aspnet
| NNTP-Posting-Host: dsl-del-dynamic-032.76.246.61.touchtelindia.net
61.246.76.32
| Path: TK2MSFTNGXA01.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFT NGP15.phx.gbl
| Xref: TK2MSFTNGXA01.phx.gbl
microsoft.public.dotnet.framework.aspnet:132025
| X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
|
| thanks
| "Kalpesh" <sh*********@gmail.com> wrote in message
| news:11**********************@g47g2000cwa.googlegr oups.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*********@gmail.com> wrote in message
news:11**********************@o13g2000cwo.googlegr oups.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
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...
7
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...
5
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...
6
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...
4
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...
10
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: ________...
4
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...
2
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...
1
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# ......
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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,...
0
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...

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.