Dim a dynamic name

M

Mark

I want to create textboxes dynamically but with dynamic names also.

i am retrieveing a load of values from a table in SQL into a DataReader.
Then i want to create textboxes from those variables. I want to dim various
textboxes with different names depending on what I retrieve from SQL. I
tried the following:

dim dtrcondet.item("contact_detail_description") as new textbox()

but this does not work

Can anyone help?
 
J

Jevon

Is this a .net app? E.g. .ASPX? If so, this should really be posted in
microsoft.public.dotnet.framework.aspnet, or
microsoft.public.dotnet.languages.vb if it's a general thing - your post
isn't clear.

What you want to do isn't possible. However, a work around would be to have
a hashtable that you add the items to. When you make a new textbox, you set
the TAG property to the value of
dtrcondet.item("contact_detail_description"), then you can look in the
hashtable for the corresponding value. However, you might not even need the
hashtable, you could just use the TAG value.

Sorry if that's a bit unclear, but I can't figure out why you'd want dynamic
text boxes in that manner anyway, or what you're trying to do with them :)

Jevon
 
B

Bob Barrows [MVP]

Mark said:
I want to create textboxes dynamically but with dynamic names also.

i am retrieveing a load of values from a table in SQL into a
DataReader.

There was no way for you to know it, but this is a classic asp newsgroup.
While you may be lucky enough to find a dotnet-knowledgeable person here who
can answer your question, you can eliminate the luck factor by posting your
question to a group where those dotnet-knowledgeable people hang out. I
suggest microsoft.public.dotnet.framework.aspnet.
Then i want to create textboxes from those variables. I
want to dim various textboxes with different names depending on what
I retrieve from SQL. I tried the following:

dim dtrcondet.item("contact_detail_description") as new textbox()

but this does not work

Can anyone help?

I don't think it's possible*, and even if it was, I don't think it's a good
idea. I would use a hash table. something like this:

dim htInputs as hashtable
htInputs.Add(dtrcondet.item("contact_detail_description"), _
new textbox)

Later, you can access the textbox via:

dim mytextbox as textbox =
htInput(dtrcondet.item("contact_detail_description"))

*If you are bound and determined, see if there is a method in VB.Net that
corresponds to the vbscript Execute method, ie, a method that accepts a
string and executes it. Maybe Eval()?

Bob Barrows
 
J

Jevon

Slight change...

This is untested but it might be possible to make a new text box, set the
name, and then access with that name. Something like:
Dim curBox as TextBox
While dtrcondet.Read
curBox = new TextBox()
curBox.Name = dtrcondet.item("contact_detail_description")
Me.Controls.Add(curBox)
WEnd

You might then be able to access it by saying something like:
Me.Controls(dtrcondet.item("contact_detail_description"))

However:
You need to decide how to handle duplicate [name] values, and you'll need to
check for invalid characters - I can't remember if there are characters that
can't be used for names. It would still probably be best to use the .tag
property as previously discussed. How are you reading the values back in?
There are slightly differing options depending on whether it's a Win or Web
form.

Jevon
 
M

Mark

Sorry for posting this in the wrong section, this is an ASP.NET 2.0 query, i
just saw web development and thought this would be the right section! :)

Jevon, your suggestion that you havent tested was what i was going to try
next! So i will give that a go in a bit. Instead of adding it to the page
controls, im going to add it to a placeholder, but it should still work.

If this works, im going to be so happy! Its being annoying me all day

Cheers

----
Mark


Jevon said:
Slight change...

This is untested but it might be possible to make a new text box, set the
name, and then access with that name. Something like:
Dim curBox as TextBox
While dtrcondet.Read
curBox = new TextBox()
curBox.Name = dtrcondet.item("contact_detail_description")
Me.Controls.Add(curBox)
WEnd

You might then be able to access it by saying something like:
Me.Controls(dtrcondet.item("contact_detail_description"))

However:
You need to decide how to handle duplicate [name] values, and you'll need to
check for invalid characters - I can't remember if there are characters that
can't be used for names. It would still probably be best to use the .tag
property as previously discussed. How are you reading the values back in?
There are slightly differing options depending on whether it's a Win or Web
form.

Jevon


Jevon said:
Is this a .net app? E.g. .ASPX? If so, this should really be posted in
microsoft.public.dotnet.framework.aspnet, or
microsoft.public.dotnet.languages.vb if it's a general thing - your post
isn't clear.

What you want to do isn't possible. However, a work around would be to
have a hashtable that you add the items to. When you make a new textbox,
you set the TAG property to the value of
dtrcondet.item("contact_detail_description"), then you can look in the
hashtable for the corresponding value. However, you might not even need
the hashtable, you could just use the TAG value.

Sorry if that's a bit unclear, but I can't figure out why you'd want
dynamic text boxes in that manner anyway, or what you're trying to do with
them :)

Jevon
 
M

Mark

Jevon, your a genious!

Got it using this code, which is basically yours anyway!

Dim temptxt As TextBox
While dtrConDet.Read()
temptxt = New TextBox()
temptxt.ID = dtrConDet.Item("detail_type_description")
plaContDet.Controls.Add(temptxt)
End While

Now ive just gotta mess around with literals and formatting, but thats just
something messy to play with :)

Thank you so much, now my stress can be relieved! :)
--
Mark


Jevon said:
Slight change...

This is untested but it might be possible to make a new text box, set the
name, and then access with that name. Something like:
Dim curBox as TextBox
While dtrcondet.Read
curBox = new TextBox()
curBox.Name = dtrcondet.item("contact_detail_description")
Me.Controls.Add(curBox)
WEnd

You might then be able to access it by saying something like:
Me.Controls(dtrcondet.item("contact_detail_description"))

However:
You need to decide how to handle duplicate [name] values, and you'll need to
check for invalid characters - I can't remember if there are characters that
can't be used for names. It would still probably be best to use the .tag
property as previously discussed. How are you reading the values back in?
There are slightly differing options depending on whether it's a Win or Web
form.

Jevon


Jevon said:
Is this a .net app? E.g. .ASPX? If so, this should really be posted in
microsoft.public.dotnet.framework.aspnet, or
microsoft.public.dotnet.languages.vb if it's a general thing - your post
isn't clear.

What you want to do isn't possible. However, a work around would be to
have a hashtable that you add the items to. When you make a new textbox,
you set the TAG property to the value of
dtrcondet.item("contact_detail_description"), then you can look in the
hashtable for the corresponding value. However, you might not even need
the hashtable, you could just use the TAG value.

Sorry if that's a bit unclear, but I can't figure out why you'd want
dynamic text boxes in that manner anyway, or what you're trying to do with
them :)

Jevon
 
J

Jevon

Glad I could help. Just remember you'll run into problems if there are any
duplicate descriptions :)

Jevon


Mark said:
Jevon, your a genious!

Got it using this code, which is basically yours anyway!

Dim temptxt As TextBox
While dtrConDet.Read()
temptxt = New TextBox()
temptxt.ID = dtrConDet.Item("detail_type_description")
plaContDet.Controls.Add(temptxt)
End While

Now ive just gotta mess around with literals and formatting, but thats
just
something messy to play with :)

Thank you so much, now my stress can be relieved! :)
--
Mark


Jevon said:
Slight change...

This is untested but it might be possible to make a new text box, set the
name, and then access with that name. Something like:
Dim curBox as TextBox
While dtrcondet.Read
curBox = new TextBox()
curBox.Name = dtrcondet.item("contact_detail_description")
Me.Controls.Add(curBox)
WEnd

You might then be able to access it by saying something like:
Me.Controls(dtrcondet.item("contact_detail_description"))

However:
You need to decide how to handle duplicate [name] values, and you'll need
to
check for invalid characters - I can't remember if there are characters
that
can't be used for names. It would still probably be best to use the .tag
property as previously discussed. How are you reading the values back in?
There are slightly differing options depending on whether it's a Win or
Web
form.

Jevon


Jevon said:
Is this a .net app? E.g. .ASPX? If so, this should really be posted in
microsoft.public.dotnet.framework.aspnet, or
microsoft.public.dotnet.languages.vb if it's a general thing - your
post
isn't clear.

What you want to do isn't possible. However, a work around would be to
have a hashtable that you add the items to. When you make a new
textbox,
you set the TAG property to the value of
dtrcondet.item("contact_detail_description"), then you can look in the
hashtable for the corresponding value. However, you might not even need
the hashtable, you could just use the TAG value.

Sorry if that's a bit unclear, but I can't figure out why you'd want
dynamic text boxes in that manner anyway, or what you're trying to do
with
them :)

Jevon


I want to create textboxes dynamically but with dynamic names also.

i am retrieveing a load of values from a table in SQL into a
DataReader.
Then i want to create textboxes from those variables. I want to dim
various
textboxes with different names depending on what I retrieve from SQL.
I
tried the following:

dim dtrcondet.item("contact_detail_description") as new textbox()

but this does not work

Can anyone help?
 
M

Mark

Yea thats why i have now used the contact_type_id instead of the description,
so it should be fine now.

Thanks

--
Mark


Jevon said:
Glad I could help. Just remember you'll run into problems if there are any
duplicate descriptions :)

Jevon


Mark said:
Jevon, your a genious!

Got it using this code, which is basically yours anyway!

Dim temptxt As TextBox
While dtrConDet.Read()
temptxt = New TextBox()
temptxt.ID = dtrConDet.Item("detail_type_description")
plaContDet.Controls.Add(temptxt)
End While

Now ive just gotta mess around with literals and formatting, but thats
just
something messy to play with :)

Thank you so much, now my stress can be relieved! :)
--
Mark


Jevon said:
Slight change...

This is untested but it might be possible to make a new text box, set the
name, and then access with that name. Something like:
Dim curBox as TextBox
While dtrcondet.Read
curBox = new TextBox()
curBox.Name = dtrcondet.item("contact_detail_description")
Me.Controls.Add(curBox)
WEnd

You might then be able to access it by saying something like:
Me.Controls(dtrcondet.item("contact_detail_description"))

However:
You need to decide how to handle duplicate [name] values, and you'll need
to
check for invalid characters - I can't remember if there are characters
that
can't be used for names. It would still probably be best to use the .tag
property as previously discussed. How are you reading the values back in?
There are slightly differing options depending on whether it's a Win or
Web
form.

Jevon


Is this a .net app? E.g. .ASPX? If so, this should really be posted in
microsoft.public.dotnet.framework.aspnet, or
microsoft.public.dotnet.languages.vb if it's a general thing - your
post
isn't clear.

What you want to do isn't possible. However, a work around would be to
have a hashtable that you add the items to. When you make a new
textbox,
you set the TAG property to the value of
dtrcondet.item("contact_detail_description"), then you can look in the
hashtable for the corresponding value. However, you might not even need
the hashtable, you could just use the TAG value.

Sorry if that's a bit unclear, but I can't figure out why you'd want
dynamic text boxes in that manner anyway, or what you're trying to do
with
them :)

Jevon


I want to create textboxes dynamically but with dynamic names also.

i am retrieveing a load of values from a table in SQL into a
DataReader.
Then i want to create textboxes from those variables. I want to dim
various
textboxes with different names depending on what I retrieve from SQL.
I
tried the following:

dim dtrcondet.item("contact_detail_description") as new textbox()

but this does not work

Can anyone help?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,534
Members
45,008
Latest member
Rahul737

Latest Threads

Top