Dropdownlist quantity Items

Asked

Viewed 700 times

5

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

I would 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 scrollbar, always with 5 records.

But any way I try I can’t, there is some way to limit the amount of dropdownlist which is completed 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();
           
        }

  • You can put the code?

  • I changed the question including the code. Thank you.

2 answers

2


Using position:Absolute; and this.size, it is possible to choose the amount 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

  • Also not Leo, it gets the normal size, and does not open in quantity, you go straight down in one line, does not expand.

  • Leo, it actually did work, because there was a css behind it, and I pulled it out, and it worked perfectly, thank you very much!

1

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

<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>
  • I tried this way, but still showing the number of items on the page, not changed to show only a few items, changed only the design of the dropdown, but when opening to show, still showing all at once.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.