Click here to Skip to main content
15,886,362 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
XML
<asp:ListBox ID="lboxCategory" runat="server" AutoPostBack="True" align="left"

                    onselectedindexchanged="lboxCategory_SelectedIndexChanged" BackColor="#33CCFF"
                     Height="100%" Width="100%">
                     </asp:ListBox>
Posted

Hello,

You can specify the value for rows attribute (HTML size) same as the number of actual option elements (HTML select_control.length) in the list (ASP.NET Iterms.Count). You can also do it in Javascript. Following snippet shows how it can be done on client side using JavaScript.
HTML
<!DOCTYPE html>
<html>
<script>
window.onload = function() {
   var lst = document.getElementById('mylist');
   lst.size = lst.length;
  alert(lst.length);
}
</script>
<body>
<form>
<select id="mylist">
  <option value="volvo">Volvo</option>
  <option value="saab">Saab</option>
  <option value="opel">Opel</option>
  <option value="audi">Audi</option>
  <option value="ferrari">Ferrari</option>
  <option value="swift">Swift</option>
  <option value="etios">Etios</option>
</select>
</form>  
</body>
</html>

Regards
 
Share this answer
 
Comments
Amirsalgar1 16-Apr-13 8:12am    
thanks for reply sir i got a property
ScrollViewer.HorizontalScrollBarVisibility="Hidden" ScrollViewer.VerticalScrollBarVisibility="Hidden"

but dont know how to implement it in my code
Prasad Khandekar 16-Apr-13 8:24am    
No need of this property use Rows property and set it's value to Items.Count. For HTML select the default value of size attribute is 1 which results in a combobox being rendered. Setting it to a value greater than 1 results in ListBox being rendered. In your case since you don;t want to display the vertical scrollbar the value of size attribute should be equal to the number of items being displayed in the select which is nothing but the select_control.length.

Regards,
Prasad Khandekar 16-Apr-13 8:38am    
Scrollviewer is a windows control.
Amirsalgar1 16-Apr-13 8:42am    
okay
Amirsalgar1 16-Apr-13 8:26am    
i have add your code in my project but the scroll bar property is still there
with below small css trick hope u can do that
XML
<style type="text/css">
        .css-lb {
            width:100px;
            overflow:hidden; 
            color:gray;
        }
            .css-lb select {
                border:none;
                height:500px;
            }
            .css-lb option {
                width:100px;
            }
    </style>
XML
<div class="css-lb">
           <asp:listbox id="ListBox1" runat="server">
                <asp:listitem text="text1" />
                <asp:listitem text="text2" />
                <asp:listitem text="text1" />
                <asp:listitem text="text2" />
               <asp:listitem text="text1" />
                <asp:listitem text="text2" />
               <asp:listitem text="text1" />
                <asp:listitem text="text2" />
               <asp:listitem text="text1" />
                <asp:listitem text="text2" />
            </asp:listbox>
        </div>


worked for me hope it will help u out
 
Share this answer
 
v2
Comments
Amirsalgar1 16-Apr-13 13:37pm    
yup it works for me too..thanks a lot sir ..
Prasad Khandekar 16-Apr-13 15:10pm    
This solution will work as long as sum of height of all the items in a list does not exceeds 500px and width of an option is less tah 100px . After that div will partially hide the listbox (height/width)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900