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!

Posting a second time...asp:label and hash keys

Status
Not open for further replies.

motte

Programmer
May 31, 2001
155
US
Hi all,

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:

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 .text 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.

Please, any help would be appreciated. keep in mind I am just using notepad. My vs.net copy should arrive shortly.

Mike

if you need to see all the code, look below:

<script runat=&quot;server&quot; language=&quot;vb&quot;>
public a as New ArrayList()
public b as New ArrayList()
public c as New ArrayList()
public h as New HashTable()

Sub Page_Load(Source As Object, E As EventArgs)

a.add(&quot; a.add(&quot; a.add(&quot;
b.add(&quot; b.add(&quot; b.add(&quot;
c.add(&quot; c.add(&quot; c.add(&quot;
h.add(&quot;AA&quot;, a)
h.add(&quot;BB&quot;, b)
h.add(&quot;CC&quot;, c)


if page.ispostback then
lBLRPT.visible = true
Formie.visible = false
'response.write(&quot;page posted back&quot;)

dim mykey2 as string
dim match as new ArrayList()

for each mykey2 in h.keys
if mykey2 = RBL.selecteditem.text then
match = h(mykey2)
if mykey2 = &quot;CC&quot; then
Summary.text = CC.text
elseif mykey2 = &quot;BB&quot; then
Summary.text = BB.text
elseif mykey2 = &quot;AA&quot; then
Summary.text = AA.text
end if
end if
next
RPT.DataSource = match
RPT.DataBind()


else
lBLRPT.visible = false
CC.visible = false
BB.visible = false
AA.visible = false

dim mykey as string
for each mykey in h.keys
response.write(&quot;<b>Key: &quot; & mykey & &quot;</b><br>&quot;)

dim elem as string
for each elem in h(mykey)
response.write(&quot;Value:_____&quot; & elem & &quot;<br>&quot;)
next
next

RBL.DataSource = h
RBL.DataTextField = &quot;Key&quot;
RBL.DataValueField = &quot;Key&quot;
RBL.DataBind()
end if


End Sub

</script>

<html>
<head>
<title></title>
</head>
<body bgcolor=&quot;#FFFFFF&quot; topmargin=&quot;0&quot; marginheight=&quot;0&quot;>
hi
<form method=&quot;post&quot; runat=&quot;server&quot; id=&quot;Formie&quot;>

<asp:radiobuttonlist id=&quot;RBL&quot; runat=&quot;server&quot;>
</asp:radiobuttonlist><br />

<asp:button id=&quot;btn1&quot; runat=&quot;server&quot; />
</form>

<asp:label id=&quot;LBLRPT&quot; runat=&quot;server&quot;>
<asp:repeater id=&quot;RPT&quot; runat=&quot;server&quot;>
<itemtemplate>
<br />
<asp:hyperlink id=&quot;myLink&quot; runat=&quot;server&quot;
text='<%# Container.DataItem() %>' NavigateUrl='<%# Container.DataItem() %>' /></b>
</itemtemplate>
</asp:repeater>
</asp:label>

<asp:label id=&quot;Summary&quot; runat=&quot;server&quot; text=&quot;hi&quot;/>
<asp:label id=&quot;CC&quot; runat=&quot;server&quot; text=&quot;I am CC label&quot;/>
<asp:label id=&quot;BB&quot; runat=&quot;server&quot; text=&quot;I am BB label&quot;/>
<asp:label id=&quot;AA&quot; runat=&quot;server&quot; text=&quot;I am AA label&quot;/>
</body>
</html>
 
Hey Motte

dim mykey2 as string

If mykey2 is a string, why not just say
asplabel.text = mykey2
?

Jack
 
Jack,

Thanks for your suggestion, but that's not what I was trying to get at. The key has the same name as the asplabel. So if it is the correct key, then I want to show the label that has the same name as the key. If one key is AA and there is a label with an id of AA, then I want to show label AA. It has nothing to do with the text.

If I did it your way, the text that would appear is &quot;AA&quot;. I need to take the correct key, match it to the id of an asp label and use that asplabel.

Mike
 
AHHHHH, ok. So just so I'm clear, you're trying to do this:

If ID of Label = Key Value Then
Label.visible = True
End If

correct? (heh, wouldn't it be swell if you could just put that code in and make it work? ;) )

Jack
 
Thats pretty much what I'm trying to do.

I also found something else out. And I may make this a seperate post: How do I take a radio button list and make it a part of an asp:datalist? Doesn't work. I can do radio buttons, but they all get different names (and ids...id is ok), resulting in being able to click all of them. I wanted to move radio buttons horizontally and I can't. I also wanted to make the text next to the radio button be a hyperlink. Can't do that if I try using a datalist with radiobutton/radiobuttonlist.

Asp.net has some cool things, and some problems...or maybe I'm just not good enough yet to figure out what to do.

Mike
 
Another thought on the first problem:
If you're going to be hardcoding the links in, why not do a select case?

Select key
Case &quot;AA&quot;
Label1.visible = True
Case &quot;BB&quot;
Label2.visible = True
Case &quot;CC&quot;
Label3.visible = True
etc. etc.
?

To your second question:
You could create a datagrid, and put as many columns in as you want the grid to be wide (lets say 6). In the first, third, and fifth columns, you make them button columns, with a style of link. In code, you dynamically change their display value to whatever you want. In your code, when the Item_Event is called when a link is clicked, all you have to do is check the text value of the link (I'm sure hte e paramter has something like that) and response.redirect to that page.

In the second, fourth, and sixth columns, dynamically create and add a radio button (assign it whatever values you want in the code). Keep making new rows and adding as many controls/links as you want.

In my head it works.
;)

Jack
 
Jack,

Thanks for the thoughts. I haven't made it that far with my studies to hit datagrids....funny, its the next thing on my list.

As for select/case statements, some people love them, some don't. I just prefer not to use them. I know this guy in a programming class of mine that suggested, as the prof went over nearly every code example that involved a decision, the use of a select/case. It could be yes vs. no and he was still hardcore select/case.

I posted somewhere else looking for the answer too, but haven't gotten one. I just find it funny that I can't use the name of the key to also be the label's id. I'm sure there has to be some kind of conversion out there that, being new as I am to .net, I don't know of yet.

Mike
 
Data grid's are a huge pain to figure out at first, but once you get the hang of them they're SUPER powerful. I've been able to re-create a UI from an Access application almost perfectly to an asp.NET app using them. Very cool.

I'll be honest with you, you're the first person to suggest using keys in this way that I've seen, although I'm sure there must be someone out there who has done this sort of thing before.
:)

Where are you taking your schooling at?

Jack
 
Jack,

Schooling at Oakton Community College in Des Plaines, IL. The 2-yr school has one of the best web programming programs in the land. Its funny when the big universities want the little schools to teach them.

Mike
 
Sweet!I graduated from a community college too. Heh, University Degrees mean ZILCH if you can't actually apply the theory.
:)

of course, they do help with bigger paychecks.
:(

I'm impressed that your school is teaching .net. Mind you, where I'm at its mostly maintaining legacy systems instead of creating new ones.
:mad:

Jack
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top