Dynamically add rows to listbox
- by Ivan S
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>