Dim a dynamic name

Discussion in 'ASP General' started by Mark, Oct 31, 2005.

  1. Mark

    Mark Guest

    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?

    ----
    Mark
     
    Mark, Oct 31, 2005
    #1
    1. Advertising

  2. Mark

    Jevon Guest

    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


    "Mark" <> wrote in message
    news:...
    >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?
    >
    > ----
    > Mark
     
    Jevon, Oct 31, 2005
    #2
    1. Advertising

  3. Mark wrote:
    > 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
    --
    Microsoft MVP - ASP/ASP.NET
    Please reply to the newsgroup. This email account is my spam trap so I
    don't check it very often. If you must reply off-line, then remove the
    "NO SPAM"
     
    Bob Barrows [MVP], Oct 31, 2005
    #3
  4. Mark

    Jevon Guest

    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" <> wrote in message
    news:...
    > 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
    >
    >
    > "Mark" <> wrote in message
    > news:...
    >>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?
    >>
    >> ----
    >> Mark

    >
    >
     
    Jevon, Oct 31, 2005
    #4
  5. Mark

    Mark Guest

    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" wrote:

    > 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" <> wrote in message
    > news:...
    > > 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
    > >
    > >
    > > "Mark" <> wrote in message
    > > news:...
    > >>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?
    > >>
    > >> ----
    > >> Mark

    > >
    > >

    >
    >
    >
     
    Mark, Oct 31, 2005
    #5
  6. Mark

    Mark Guest

    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" wrote:

    > 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" <> wrote in message
    > news:...
    > > 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
    > >
    > >
    > > "Mark" <> wrote in message
    > > news:...
    > >>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?
    > >>
    > >> ----
    > >> Mark

    > >
    > >

    >
    >
    >
     
    Mark, Oct 31, 2005
    #6
  7. Mark

    Jevon Guest

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

    Jevon


    "Mark" <> wrote in message
    news:...
    > 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" wrote:
    >
    >> 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" <> wrote in message
    >> news:...
    >> > 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
    >> >
    >> >
    >> > "Mark" <> wrote in message
    >> > news:...
    >> >>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?
    >> >>
    >> >> ----
    >> >> Mark
    >> >
    >> >

    >>
    >>
    >>
     
    Jevon, Nov 1, 2005
    #7
  8. Mark

    Mark Guest

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

    Thanks

    --
    Mark


    "Jevon" wrote:

    > Glad I could help. Just remember you'll run into problems if there are any
    > duplicate descriptions :)
    >
    > Jevon
    >
    >
    > "Mark" <> wrote in message
    > news:...
    > > 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" wrote:
    > >
    > >> 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" <> wrote in message
    > >> news:...
    > >> > 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
    > >> >
    > >> >
    > >> > "Mark" <> wrote in message
    > >> > news:...
    > >> >>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?
    > >> >>
    > >> >> ----
    > >> >> Mark
    > >> >
    > >> >
    > >>
    > >>
    > >>

    >
    >
    >
     
    Mark, Nov 1, 2005
    #8
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. VB Programmer
    Replies:
    3
    Views:
    411
    Chris Mahoney
    Jul 13, 2003
  2. Andreas Klemt
    Replies:
    1
    Views:
    461
    Steve C. Orr, MCSD
    Jul 23, 2003
  3. Denis Palas
    Replies:
    1
    Views:
    514
  4. Florian Kaufmann
    Replies:
    1
    Views:
    384
  5. DaveF

    dim Name redefined error

    DaveF, Apr 14, 2004, in forum: ASP General
    Replies:
    8
    Views:
    643
    Aaron Bertrand [MVP]
    Apr 14, 2004
Loading...

Share This Page