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!

Help with using "For...Next" 2

Status
Not open for further replies.

jkl

Programmer
May 16, 2001
83
US
I want to create a set of HyperLinks which call a function, i.e.

<asp:HyperLink onClick=&quot;myFunction('A')&quot;>A</asp:HyperLink>

But I want to do this for the entire alphabet. Is there some way I can iterate through the letters using a &quot;For...Next&quot; statement to generate these links?
 
What you need is ASCII conversion:

Dim i As Integer
Dim c As Char
For i = 65 To 90
c = Chr(i)
Next

65-90 are upper case -- 97-122 are lower case. Here's a reference for you:

:)
paul
penny1.gif
penny1.gif
 
paul,

thanks. yeah i have the ascii/iteration issue figured out just fine.

what I can't figure out is how to get the server to generate the links. i don't know where to instantiate the looping and how to tell the server to make the links. i tried creating a Sub which loops through, but don't know what to do with the result.
 
Whoops. Sorry.

Ok, then. Add a label to your page. Call it lblButtons.

Then, in the codebehind, make sure you have:

Imports System.Text 'obviously up top

Protected WithEvents lblButtons As System.Web.UI.WebControls.Label 'obviously in class

Then, call a procedure that might would look like this:

private sub makeButtons()
dim hl as system.web.ui.webcontrols.hyperlink
dim i as integer
dim sb as stringbuilder
for i = 65 to 90
sb = new stringbuilder()
sb.append(&quot;myFunction('&quot;)
sb.append(chr(i))
sb.append(&quot;')&quot;)
hl = new hyperlink()
hl.text = chr(i)
hl.navigateURL = sb.toString()
lblButtons.controls.add(hl)
next
end sub

Something along those lines oughta get it for you.

:)
paul
penny1.gif
penny1.gif
 
Thanks for this Paul. I'm still not getting exactly what I want, but it is helping a lot.

How do I add an onClick event to the hyperlink object?

I don't need the page to navigate anywhere, I just need to postback to the same page, passing the letter variable.


Basically, this is a directory listing, the function I'm trying to make work, is to show only those in the directory whose last name begins with... 'A' .
 
What you need, then, is a link button. Just employ the same type of logic, except using a link button.

Use the commandEventArgs to do your work... I'll post up an example later if you still need it. Till then, search google on 'commandEventArgs' and 'linkButton'

lots of examples.

*back to work*

;-)
penny1.gif
penny1.gif
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top