I have a listbox on a page that is bound to a linqdatasource. In the ondatabound event I am trying to make the size of the listbox on screen fit the items, to avoid having to scroll and to avoid excessive white space.
How can I do this?
protected void ListBox1_DataBound(object sender, EventArgs e)
{
ListBox1.FitToItems();
}
protected void FitToItems() {
...?
}
Try:
Listbox.rows = Listbox.Items.count
Try setting the size attribute on the generated tag. Something like...
$(document).ready(function() {
$('#<%=this.ListBox1.ClientID%>').attr('size', $('#<%=this.ListBox1.ClientID%> option').length);
});
using jQuery.
Or set it using ListBox.Rows = ListBox.Items.Count server side (not tried this myself, but I think that's what it does).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With