I have a common problem in an ASP.NET web form. I’m just surprised that I haven’t found a common solution 🙂
I have a list of results being returned from a SQL Server database. I want to show those results in my web page with number to the left of them. For instance, my result set may look like the following:
New York | NY
Chicago | IL
Los Angeles | CA
In my web page, I would like to show them as:
1. New York, NY
2. Chicago, IL
3. Los Angeles, CA
I was surprised that I can’t find a way to make the numbers automatically appear. Am I doing something wrong?
Since you are using WebForms, consider using the BulletedList control. You can bind the BulletedList control to a data source control (like the SqlDataSource or LinqDataSource controls) or you can populate its value programmatically through the DataSource property.
To get the BulletedList to render numbers, set the BulletStyle property to Numbers.
Here’s an example of using the BulletedList and a SqlDataSource control: http://aspalliance.com/247_ASPNET_v20_Introducing_BulletedList_Control.4