Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. dynamically setting MaxLength property of a Textbox

dynamically setting MaxLength property of a Textbox

Scheduled Pinned Locked Moved Visual Basic
csharpdatabasequestion
6 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    Gulfraz Khan
    wrote on last edited by
    #1

    Hi! i have many textboxes on a form in a vb .net 2005 application these textboxes are databound. Is there any way i can set the MaxLength property of these textboxes (which are bound to varchar fields in the database) to the size of the field in the database. Or how do i access the field (i.e. DataColumn of the table) to which a textbox is bound. Thank You

    N 1 Reply Last reply
    0
    • G Gulfraz Khan

      Hi! i have many textboxes on a form in a vb .net 2005 application these textboxes are databound. Is there any way i can set the MaxLength property of these textboxes (which are bound to varchar fields in the database) to the size of the field in the database. Or how do i access the field (i.e. DataColumn of the table) to which a textbox is bound. Thank You

      N Offline
      N Offline
      nishkarsh_k
      wrote on last edited by
      #2

      may be you should try textbox1.mexlength = 20 'Length Good Luck

      G 1 Reply Last reply
      0
      • N nishkarsh_k

        may be you should try textbox1.mexlength = 20 'Length Good Luck

        G Offline
        G Offline
        Gulfraz Khan
        wrote on last edited by
        #3

        but, the problem remains. what length should i set as i don't know the lenght of the field in the database?

        D N 2 Replies Last reply
        0
        • G Gulfraz Khan

          but, the problem remains. what length should i set as i don't know the lenght of the field in the database?

          D Offline
          D Offline
          darkelv
          wrote on last edited by
          #4

          You can query the database for the length, assuming you are using SQL server. Not sure about other DBs.

          1 Reply Last reply
          0
          • G Gulfraz Khan

            but, the problem remains. what length should i set as i don't know the lenght of the field in the database?

            N Offline
            N Offline
            nishkarsh_k
            wrote on last edited by
            #5

            for that issue u have to keep track of which field u are accessing There is another way to do it but this will introduce a real big overload on the system and application will become slow... What you can do is just before you set the size of textbox do a query and to get the field size(I am not sure how to do it... but for sure there will be a query for sure)... and then assign the max size of textbox Good Luck

            G 1 Reply Last reply
            0
            • N nishkarsh_k

              for that issue u have to keep track of which field u are accessing There is another way to do it but this will introduce a real big overload on the system and application will become slow... What you can do is just before you set the size of textbox do a query and to get the field size(I am not sure how to do it... but for sure there will be a query for sure)... and then assign the max size of textbox Good Luck

              G Offline
              G Offline
              Gulfraz Khan
              wrote on last edited by
              #6

              why do i need to query the database for the length of the field since my textboxes are databound (using drag & drop from the data sources window) and the properties of the the datatables show the mapped fields (i.e. varchar(6) to system.string with length 6). Is there any way I can access these properties of the datatables.

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups