I have a listbox that I am dynamicly filling from a table in my SQL DB and I would like to dynamicly set the rows for the listbox to the amount of records from the table so no scrolling is needed. Is there an easy way to do this besides adding that table info into a local datatable and counting the rows in that? Here is the code for my binding of the listbox:
List<ParameterList> Parameters = new List<ParameterList>();
Parameters.Add(new ParameterList() { Name = "CategoryName", Value = CategoryName });
lbCategory.DataSource = SQLHelper.GetDataByQuery("SELECT SectionID, SectionTitle FROM dbo.vwNavigationMenuItems WHERE CategoryName = @CategoryName ORDER BY MenuPosition ASC", Parameters);
lbCategory.DataTextField = "SectionTitle";
lbCategory.DataValueField = "SectionID";
lbCategory.DataBind();
Try this
Or after binding the data you can try
I don’t know of any other simpler way