C# 根据内容设置listbx的高度
我必须设置一个列表框来显示数据库列中的数据。每次列表框中都会出现不同长度的数据。因此,根据这一点,我必须改变它的高度以适应内容。怎么样C# 根据内容设置listbx的高度,c#,html,asp.net,C#,Html,Asp.net,我必须设置一个列表框来显示数据库列中的数据。每次列表框中都会出现不同长度的数据。因此,根据这一点,我必须改变它的高度以适应内容。怎么样 <asp:ListBox ID="ListBox1" runat="server" BackColor="White" Height="14000px" Width="1312px"></asp:ListBox> while (dr.Read()) { string poem = dr[0]
<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);
}
}
试试这个-
Listbox.rows = Listbox.Items.count
或
也可以按如下方式设置“大小”属性-
$(document).ready(function() {
$('#<%=this.ListBox1.ClientID%>').attr('size', $('#<%=this.ListBox1.ClientID%> option').length);
});