简体   繁体   中英

Set Height of a listbx fit to content

I have to set a list box which shows data from database column . Each time different length of data will come to list-box. so according to this I have to change its height fit to content . How is it ?

 <asp:ListBox ID="ListBox1" runat="server" BackColor="White" Height="14000px" 
        Width="1312px"></asp:ListBox>

while (dr.Read())
    {

        string poem = dr[0].ToString();
        byte[] newFileData = Encoding.ASCII.GetBytes(poem);

        string fileString = System.Text.Encoding.UTF8.GetString(newFileData);
        string[] poem_details = fileString.Split(new string[] { "  ", "\n" }, StringSplitOptions.None);

        foreach (var line in score_details)
        {

            ListBox1.Items.Add(line);
        }
    } 

Try this-

Listbox.rows = Listbox.Items.count

OR

you can also set size attribute as follows-

$(document).ready(function() {
  $('#<%=this.ListBox1.ClientID%>').attr('size', $('#<%=this.ListBox1.ClientID%> option').length);
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM