473,324 Members | 2,548 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,324 software developers and data experts.

Variable Type?

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
controls, I wanted to know if I could use a variable for the name of these
label controls and set their attributes in a loop.

What type of variable could I use to accomplish this? I've tried object
without success.

Thanks,

Jeff
Nov 16 '05 #1
7 1455
Jeff,

I would use the "as" statement for this. Basically, you would loop
through all of your controls, and in the loop, you do:

// Get the label. pobjControl is the current control in the enumeration.
Label pobjLabel = pobjControl as Label;

// If the control is a label, then pobjLabel will not be null here, and the
Visible property can be set.
if (pobjLabel != null)
// Set the visible property.
pobjLabel.Visible = false;

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Jeff Johnson" <je**********@hotmail.com> wrote in message
news:Oh**************@tk2msftngp13.phx.gbl...
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
controls, I wanted to know if I could use a variable for the name of these
label controls and set their attributes in a loop.

What type of variable could I use to accomplish this? I've tried object
without success.

Thanks,

Jeff

Nov 16 '05 #2
Jeff,

I would use the "as" statement for this. Basically, you would loop
through all of your controls, and in the loop, you do:

// Get the label. pobjControl is the current control in the enumeration.
Label pobjLabel = pobjControl as Label;

// If the control is a label, then pobjLabel will not be null here, and the
Visible property can be set.
if (pobjLabel != null)
// Set the visible property.
pobjLabel.Visible = false;

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Jeff Johnson" <je**********@hotmail.com> wrote in message
news:Oh**************@tk2msftngp13.phx.gbl...
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
controls, I wanted to know if I could use a variable for the name of these
label controls and set their attributes in a loop.

What type of variable could I use to accomplish this? I've tried object
without success.

Thanks,

Jeff

Nov 16 '05 #3
Jeff Johnson <je**********@hotmail.com> wrote:
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
controls, I wanted to know if I could use a variable for the name of these
label controls and set their attributes in a loop.

What type of variable could I use to accomplish this? I've tried object
without success.


The best way of doing this is to have the label controls in an array to
start with, rather than in individual variables.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #4
Jeff Johnson <je**********@hotmail.com> wrote:
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
controls, I wanted to know if I could use a variable for the name of these
label controls and set their attributes in a loop.

What type of variable could I use to accomplish this? I've tried object
without success.


The best way of doing this is to have the label controls in an array to
start with, rather than in individual variables.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #5
Hi Jeff,

Beside Jon's suggestion you can also use the Page.Control collection to
iterate in the controls of the page, this will be better if you do not have
another use of the labels, in such escenario you don;t have to declare them
in the code behind page, hence decreasing the code to write/maintain.

It will be somethig like this:
foreach( Control control in Controls )
{
if ( control is Label )
{
//see if it needs to be processed.
}

}
Now as you probable have more labels in the page you will need to have a
form of identify those that needs to be changed. Maybe using a template name
: DynamicLabel1 , DynamicLabel2 , etc

Cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
"Jeff Johnson" <je**********@hotmail.com> wrote in message
news:Oh**************@tk2msftngp13.phx.gbl...
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
controls, I wanted to know if I could use a variable for the name of these
label controls and set their attributes in a loop.

What type of variable could I use to accomplish this? I've tried object
without success.

Thanks,

Jeff

Nov 16 '05 #6
Hi Jeff,

Beside Jon's suggestion you can also use the Page.Control collection to
iterate in the controls of the page, this will be better if you do not have
another use of the labels, in such escenario you don;t have to declare them
in the code behind page, hence decreasing the code to write/maintain.

It will be somethig like this:
foreach( Control control in Controls )
{
if ( control is Label )
{
//see if it needs to be processed.
}

}
Now as you probable have more labels in the page you will need to have a
form of identify those that needs to be changed. Maybe using a template name
: DynamicLabel1 , DynamicLabel2 , etc

Cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
"Jeff Johnson" <je**********@hotmail.com> wrote in message
news:Oh**************@tk2msftngp13.phx.gbl...
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
controls, I wanted to know if I could use a variable for the name of these
label controls and set their attributes in a loop.

What type of variable could I use to accomplish this? I've tried object
without success.

Thanks,

Jeff

Nov 16 '05 #7
Got it working.

Thank you to all of you!!!

Jeff
Nov 16 '05 #8

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

Similar topics

4
by: Gord | last post by:
Hello, I think that what I'm trying to do is impossible, but before I give up I thought I'd try and pick a few more knowledgeable brains than my own. I have any array of user defined type...
3
by: Mike Conmackie | last post by:
Greetings, I am trying to create a node in the output tree using a variable. Here are some fragments that I hope will explain the problem better. <xsl:stylesheet...
1
by: Scott | last post by:
I have an XML Document in a format like: <Variable name="Bob">ABCDEFG</Variable> <Variable name="Steve">QWERTYUI</Variable> <Variable name="John">POIUYTR</Variable> <Variable...
7
by: bartek | last post by:
Hello, I've been pondering with this for quite some time now, and finally decided to ask here for suggestions. I'm kind of confused, actually... Maybe I'm thinking too much... Brain dump...
134
by: James A. Donald | last post by:
I am contemplating getting into Python, which is used by engineers I admire - google and Bram Cohen, but was horrified to read "no variable or argument declarations are necessary." Surely that...
14
by: sathya_me | last post by:
Dear clc, I have a variable void *a; Since variable "a" can be assigned (point to) any type and also any type can be assigned to "a" (i.e means "a" = any typed variable; any typed variable =...
8
by: Groups User | last post by:
C allows type casting in which a variable is converted from one type to another. Does C (whatever standard) allow the type of a variable to change, within a statement, avoiding the conversion?...
20
by: weston | last post by:
I've got a piece of code where, for all the world, it looks like this fails in IE 6: hometab = document.getElementById('hometab'); but this succeeds: hometabemt =...
13
by: Justcallmedrago | last post by:
How would you declare and assign a variable inside a function THAT HAS THE NAME OF A PARAMETER YOU PASSED example: when you call createvariable("myvariable") it will declare the variable...
112
by: istillshine | last post by:
When I control if I print messages, I usually use a global variable "int silent". When I set "-silent" flag in my command line parameters, I set silent = 1 in my main.c. I have many functions...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.