Dynamically add rows to listbox
Posted
by
Ivan S
on Stack Overflow
See other posts from Stack Overflow
or by Ivan S
Published on 2013-06-26T16:09:17Z
Indexed on
2013/06/26
16:21 UTC
Read the original article
Hit count: 189
I have a list box that displays information off of a column of a dataset. I would like the number of rows displayed to be all the rows that are in the dataset (the number of datasets in the rows vary). I'm figuring it has something to do with
ListBox.Rows = Dataset.Tables[0].Rows.Count;
But it seems to just always default to 4 even when it is only 2.
This is what I have in my aspx.cs file.
pirateBox.DataTextField = Pirateship.Tables[0].Columns["displayName"].ToString();
pirateBox.DataValueField = pirateship.Tables[0].Columns["PKID"].ToString();
pirateBox.DataSource = pirateship.Tables[0];
pirateBox.DataBind();
pirateBox.Rows = pirateship.Tables[0].Rows.Count;
I've been trying a few things and this is what I have so far in .aspx
<asp:ListBox ID="pirateBox" runat="server" Rows="1"></asp:ListBox>
© Stack Overflow or respective owner