NicoVB Posted June 25, 2003 Posted June 25, 2003 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 Quote Visit http://www.nico.gotdns.com Now ONLINE!
*Experts* mutant Posted June 25, 2003 *Experts* Posted June 25, 2003 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. Quote
JABE Posted June 25, 2003 Posted June 25, 2003 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 = ... Quote
NicoVB Posted June 25, 2003 Author Posted June 25, 2003 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. Quote Visit http://www.nico.gotdns.com Now ONLINE!
JABE Posted June 25, 2003 Posted June 25, 2003 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 Quote
*Experts* mutant Posted June 25, 2003 *Experts* Posted June 25, 2003 It wont take much time :), I suggested what JABE just showed you. :) Quote
NicoVB Posted June 25, 2003 Author Posted June 25, 2003 Okay, have allready find another way , by setting earlier a reference to it. But thanks for the help Quote Visit http://www.nico.gotdns.com Now ONLINE!
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.