Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

How do you call a control with it's name defined with a number..

 

 

For example

 

I have a control link3 but I don't know 3, but only have the value hold in a variable 'row'

 

so.. i tried this:

 

CType("link" & row, LinkControl).Text = ...

 

 

But he gives error, can't convert that string to a linkcontrol!!!

 

How to do this??

 

Nico

Visit http://www.nico.gotdns.com

 

Now ONLINE!

  • *Experts*
Posted
You cant do it that way, the next best thing would be to go through all controls with the for each loop and check if the control has a name of link3.
Posted

In ASP.NET, the System.Web.UI.Control class has a FindControl method w/c you can use like this:

 

CType(Page.FindControl("link" & row), LinkControl).Text = ...

Posted

Hmmm, it seems that a form in Windows app has not such a method. ... What to do now??

 

mutant >>> I think i have allready so much code in the project that I think it is not a very good way to do this. Maybe it will take a bit too much time.

Visit http://www.nico.gotdns.com

 

Now ONLINE!

Posted

Yeah, I wonder why no FindControl in Windows controls. Closest you get is Controls.Item but it accepts an integer index and not a control name. Creating your own FindControl shouldn't be difficult though.

 

Public Function FindControl(ByVal parentControl As Control, ByVal vstrCtrlName As String) As Control

Dim ctrl As Control

For Each ctrl In parentControl.Controls

If ctrl.Name = vstrCtrlName Then

Return ctrl

End If

Next

Return Nothing

End Function

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...