排序一个DropDownList? - C#,ASP.NET [英] Sorting a DropDownList? - C#, ASP.NET

查看:154
本文介绍了排序一个DropDownList? - C#,ASP.NET的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很好奇,以最佳路线(更多望着简单,没有速度和效率)进行排序在C#/ ASP.NET一个DropDownList - 我已经看了一些建议,但它们不与点击好我的。

I'm curious as to the best route (more looking towards simplicity, not speed or efficiency) to sort a DropDownList in C#/ASP.NET - I've looked at a few recommendations but they aren't clicking well with me.

编辑:伙计们,我没有控制数据如何进入DropDownList的 - 我不能修改SQL

Folks, I do not have control over how the data comes into the DropDownList - I cannot modify the SQL.

推荐答案

如果你得到的数据的数据表,您可以创建一个DataView过这个,然后绑定下拉列表来表示。您code看起来像...

If you get a DataTable with the data, you can create a DataView off of this and then bind the drop down list to that. Your code would look something like...

DataView dvOptions = new DataView(DataTableWithOptions);
dvOptions.Sort = "Description";

ddlOptions.DataSource = dvOptions;
ddlOptions.DataTextField = "Description";
ddlOptions.DataValueField = "Id";
ddlOptions.DataBind();

您文本字段和值字段选择映射到数据表您收到相应的columnns。

Your text field and value field options are mapped to the appropriate columnns in the data table you are receiving.

这篇关于排序一个DropDownList? - C#,ASP.NET的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆