DropDownList Quantity Items

4

Good morning, I'm using dropdownlist in asp.net to load some data coming from the bank, however I do not know the amount that will be shown, because it depends on the fill in the bank.

I'd like to show only a certain amount of items.

For example, if you have 29 records, I want to show only the first 5 and after that, show the scroll bar, always with 5 records.

But every way I try I can not, is there any way I can limit the amount of dropdownlist items that is populated by the database?

Dropdownlist:

 <asp:DropDownList ID="cbfuncionario" runat="server" style = "overflow-y: scroll"></asp:DropDownList>

and here I load the dropdownlist:

  public void CarregaFuncionario()
        {
            SqlCommand comando = new SqlCommand();
            comando.Connection = clsdb.AbreBanco();
            comando.CommandType = CommandType.Text;
            comando.CommandText = "select pessoa.id,nome FROM [pessoa] inner join classificacoes on classificacoes.id = pessoa.classificacao_id where estado <> 'Inativo' and estado <> 'Excluido' and classificacoes.tipo = '1' order by pessoa.nome ASC";

            SqlDataAdapter da = new SqlDataAdapter();
            da.SelectCommand = comando;
            DataSet ds = new DataSet();
            da.Fill(ds);


            cbfuncionario.DataSource = ds.Tables[0];
            cbfuncionario.DataTextField = "nome";
            cbfuncionario.DataValueField = "id";
            cbfuncionario.DataBind();
           
        }
    
asked by anonymous 12.04.2017 / 15:18

2 answers

2

Using position: absolute; and this.size, it is possible to choose the quantity of items (10 in the example)

<asp:DropDownList ID="cbfuncionario" onclick="this.size=1;" onMouseOver="this.size=10;" onMouseOut="this.size=1;" runat="server" style = "position:absolute;"></asp:DropDownList>

Credits

    
12.04.2017 / 15:38
1

I think this will solve your problem, if you want to show more items, change the height of your HEIGHT item

<style type="text/css">
 .scrollable{
   overflow: auto;
   width: 70px; 
   height: 80px; /
   border: 1px silver solid;
 }
 .scrollable select{
   border: none;
 }
</style>

And your HTML code looks like this

<div class="scrollable">
 <asp:DropDownList ID="cbfuncionario" runat="server" style = "overflow-y: scroll"></asp:DropDownList>
</div>
    
12.04.2017 / 15:30