Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

asp:label and hash keys

Status
Not open for further replies.

motte

Programmer
May 31, 2001
155
US
I can't seem to find an answer to this problem. Please read below.

Hi,

A while back I posted this thread, but never got the answer I was looking for. Now that more people have had experience with asp.net, perhaps someone may be able to solve this problem. Here is my original question:

I have a problem. I have a hash that has its keys bound to an asp:radiobuttonlist. When the form is submitted, the keys are checked. If a certain key matches the checked radio button, I spit out the value at that key. The value is an array full of links.

What I also have are asp:labels, each has an id that is the same as a key in the hash. I want to make that label appear. but i can't get it to work.

Here is a sample:
Code:
for each mykey2 in h.keys 
if mykey2 = RBL.selecteditem.text then 
match = h(mykey2) 'array set to another array 
mykey2.visible = true 
end if 
next

match is an array. I later use it to bind to an asp:repeater for all the links.

The problem is mykey2.visible. Since mykey2 is a key, it really isn't an asp:label; so the .visible property doesn't work. But how do I get it so that I can use the key to be the id of the asp:label? That is my problem.


BTW, this suggestion failed:
Code:
CType(mykey2, Label).Visible = True

Mike
 
hi mike,

let me try to answer your question

well, as you've said, mykey2 wasn't a label at all, eventhough mykey2 is exactly the same as one of your labels id. perhaps you could try it a different way. if your labels were all made on design time, it'll be easy, just check all the labels that you've made on design time like this :
if YOURLABEL.id == mykey2 then
YOURLABEL.Visible = true
end if

well, that's the easiest way... but if your labels are dynamic (it means that they were made on runtime, using repeater or datagrid or datalist, etc). as example, you're using repeater, then you should access the labels by using the repeater object you've made, then you should use the findcontrol method to find your label by using id, if the control it returns is null then it means, at the current row there were no labels with that id ^-^

well, i don't quite sure this is your problem, just trying to help ^-^
 
ja2000,

thanks for the info. I want to try to avoid the hardcoding issue of matching a key to a label.

I'm already doing as you suggested with trying to match for every label. But if I decide to have tons of labels, then I'd be running a long if/else list. I don't want to do that.

My labels are made on design time.

There has to be some way of converting the string to be a different type, an asp:label, but ctype doesn't cut it. Thanks for the tips though.

Mike
 
hei mike,

i found another simple way... if all your labels are created during design time, why don't u simply use the FindControl method? it will return a control if it match the string you give, else, it will return null...

so, just try it
if (FindControl(mykey2)!=null) {
TextBox something = (TextBox)FindControl(mykey2);
something.Visible = true
}

hope this could help ^-^
 
ja2000,

I will try useing FindControl. Is that correct syntax? I don't really follow it though. This is the line in question:

Code:
TextBox something = (TextBox)FindControl(mykey2);

Thanks for the help. I will try.

Mike
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top