Click here to Skip to main content
15,069,408 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

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
   
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)
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
   
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
Amirsalgar1 16-Apr-13 8:28am
   
sir,
can you join me on team viewer so that you will come to know which problems i am facing
Amirsalgar1 16-Apr-13 8:30am
   
175 735 453
3611
Prasad Khandekar 16-Apr-13 8:31am
   
I am afraid I will not be able to do so from within my office network. Have you tried running the HTML code?
Regards,
Amirsalgar1 16-Apr-13 8:33am
   
ohh okay then please tell me the time when you will free ,i will be there that time
Prasad Khandekar 16-Apr-13 8:40am
   
Ok will post a reply here. Will be late though around 10:30 PM.
Amirsalgar1 16-Apr-13 8:42am
   
okay thank you sir , i ll be here sharp 10.30
Amirsalgar1 16-Apr-13 8:36am
   
you i had tried
Amirsalgar1 16-Apr-13 13:27pm
   
u there sir?

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