ASP.NET
--
Questions
--
Followers
Top Experts
How to sort a listbox once the item is added to the list. If a new item is added it's added to the buttom of the list. What is the techic to sort the list? Thank you
Zero AI Policy
We believe in human intelligence. Our moderation policy strictly prohibits the use of LLM content in our Q&A threads.
--Michael
listbox.Items.Insert(0, "Select an Option")
Or you can do this:
Dim li As New ListItem("X", "Select and Option")
listbox.Items.Insert(0, li)
Of course, you could insert the item at any valid index. If you have 10 items, you would not use index 15, of course (I have not tried that, so I do not know if it would throw an exception or just stick the item at the bottom of the list).
John
I have a table in the database called Lists. It has these fields: ListName, ValueMember, DisplayMember, SortOrder. Let's say I want a list of delivery methods including UPS, FexEx, and US Mail, in that order. I would have three entries, each with the ListName column having "Delivery Methods", and the SortOrder field specifying how they should appear sort-wise.
I have a dataset with the Lists table as a DataTable. But when I want to use a list, I add a DataView to the page and specify its table as the Lists table, the RowFilter="ListName = 'Delivery Methods'" and SortOrder in the Sort property. I then bind the list to the DataView rather than the DataTable. This sorts the list exactly as I want it.
John






EARN REWARDS FOR ASKING, ANSWERING, AND MORE.
Earn free swag for participating on the platform.
foreach(ListItem li in this.ListBox1.Items)
{
al.Add(li.Text);
}
al.Sort();
this.ListBox1.DataSource=a
this.DataBind();

Get a FREE t-shirt when you ask your first question.
We believe in human intelligence. Our moderation policy strictly prohibits the use of LLM content in our Q&A threads.
ASP.NET
--
Questions
--
Followers
Top Experts
The successor to Active Server Pages, ASP.NET websites utilize the .NET framework to produce dynamic, data and content-driven web applications and services. ASP.NET code can be written using any .NET supported language. As of 2009, ASP.NET can also apply the Model-View-Controller (MVC) pattern to web applications