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. Web Development
  3. ASP.NET
  4. DropDownList width

DropDownList width

Scheduled Pinned Locked Moved ASP.NET
csharpcomwindows-admintoolsquestion
4 Posts 2 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
    Giorgi Dalakishvili
    wrote on last edited by
    #1

    Hello I have a dropdownlist in edititemtemplate of the gridview. However items are long so the dropdownlist becomes too wide. What I would like to do is to have dropdownlist which is small when it is collapsed and becomes wide when the items are visible. Is it possible? If I make its widht fixed then the items are cut when they are displayed. I would like for the dropdown to become wider. Thank you.

    Giorgi Dalakishvili #region signature My Articles Asynchronous Registry Notification Using Strongly-typed WMI Classes in .NET [^] My blog #endregion

    A 1 Reply Last reply
    0
    • G Giorgi Dalakishvili

      Hello I have a dropdownlist in edititemtemplate of the gridview. However items are long so the dropdownlist becomes too wide. What I would like to do is to have dropdownlist which is small when it is collapsed and becomes wide when the items are visible. Is it possible? If I make its widht fixed then the items are cut when they are displayed. I would like for the dropdown to become wider. Thank you.

      Giorgi Dalakishvili #region signature My Articles Asynchronous Registry Notification Using Strongly-typed WMI Classes in .NET [^] My blog #endregion

      A Offline
      A Offline
      Abhishek Sur
      wrote on last edited by
      #2

      you can set the width dynamically using Javascript

      function dynamicWidth(evt,conversionFactor){
      var selection = document.getElementById('test');
      if (!selection.minmax){
      selection.minmax=[parseInt(selection.style.width),0];
      for (var i=0; i<selection.options.length;i++){
      if (selection[i].text.length>selection.minmax[1]){
      selection.minmax[1] = selection[i].text.length*conversionFactor;
      }
      }
      }
      selection.style.width = (evt?selection.minmax[1]:selection.minmax[0]) +'px';
      }

      Option one
      Option two which is long
      Option three which is longer
      Option four which is even more long

      Make your adjustment to render the control html in this manner... :rose::rose:

      Abhishek Sur

      G 1 Reply Last reply
      0
      • A Abhishek Sur

        you can set the width dynamically using Javascript

        function dynamicWidth(evt,conversionFactor){
        var selection = document.getElementById('test');
        if (!selection.minmax){
        selection.minmax=[parseInt(selection.style.width),0];
        for (var i=0; i<selection.options.length;i++){
        if (selection[i].text.length>selection.minmax[1]){
        selection.minmax[1] = selection[i].text.length*conversionFactor;
        }
        }
        }
        selection.style.width = (evt?selection.minmax[1]:selection.minmax[0]) +'px';
        }

        Option one
        Option two which is long
        Option three which is longer
        Option four which is even more long

        Make your adjustment to render the control html in this manner... :rose::rose:

        Abhishek Sur

        G Offline
        G Offline
        Giorgi Dalakishvili
        wrote on last edited by
        #3

        I have a dropdowlist, not select. I not that the resulting HTML will be select but how can I apply your solution to dropdownlist? And the dropdownlist is in a usercontrol.

        Giorgi Dalakishvili #region signature My Articles Asynchronous Registry Notification Using Strongly-typed WMI Classes in .NET [^] My blog #endregion

        A 1 Reply Last reply
        0
        • G Giorgi Dalakishvili

          I have a dropdowlist, not select. I not that the resulting HTML will be select but how can I apply your solution to dropdownlist? And the dropdownlist is in a usercontrol.

          Giorgi Dalakishvili #region signature My Articles Asynchronous Registry Notification Using Strongly-typed WMI Classes in .NET [^] My blog #endregion

          A Offline
          A Offline
          Abhishek Sur
          wrote on last edited by
          #4

          use Attributes.Add["onclick", to invoke your function in client end. Well even if the dropdown is inside the user control, in browser it always renders one select. So get your select control from dropdown.clientID and invoke the function. you can use Server tag inside the javascript function to be replaced with client id. I think you can do that .. If you still unable to do so, I will send you one code for that then. :rose::rose:

          Abhishek Sur

          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