Applying sorting on datareader while binding to dropdown in asp
Currently I am facing a problem for sorting datareader
contents alphabetically. The scenario is I have a datareader
that read开发者_JAVA百科s department name from database. Then, in while loop, I am binding each datareader
row to dropdown (<select><option Value=''>Some Text</option></select>
). I want to show contents in alphabetical order.
How can I achieve this?
You can't really do anything with a datareader besides looping through the records. You'll need to apply the sort to your source query.
If you get the data into a DataTable, you can apply the sort before binding.
How are you retrieving the values from the database? Can't you just add an Order By clause to your query?
精彩评论