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!

Disturbing problem: hash key to asp:label

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:
Code:
<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;[URL unfurl="true"]http://www.hotbot.com&quot;)[/URL]
	a.add(&quot;[URL unfurl="true"]http://www.yahoo.com&quot;)[/URL]
	a.add(&quot;[URL unfurl="true"]http://www.google.com&quot;)[/URL]

	b.add(&quot;[URL unfurl="true"]http://www.cubs.com&quot;)[/URL]
	b.add(&quot;[URL unfurl="true"]http://www.chicagobears.com&quot;)[/URL]
	b.add(&quot;[URL unfurl="true"]http://www.blackhawks.com&quot;)[/URL]

	c.add(&quot;[URL unfurl="true"]http://www.ford.com&quot;)[/URL]
	c.add(&quot;[URL unfurl="true"]http://www.subaru.com&quot;)[/URL]
	c.add(&quot;[URL unfurl="true"]http://www.dodge.com&quot;)[/URL]

	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>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top