sort dropdownlist by date, after it is populated from datasource
I want to sort the dropdownlist by date, but i cant figure out how.
ddate.DataSource = myTable
ddate.DataTextField = "ddate7"
ddate.DataValueField = "ddate7"
ddate.DataBind()
If myTable is a DataTable
then you could put it into a Dataview and sort it there like this:
Dim dv As New DataView(myTable)
dv.Sort = "ddate7"
ddate.DataSource = dv
ddate.DataTextField = "ddate7"
ddate.DataValueField = "ddate7"
ddate.DataBind()
You can use a DataView to sort and filter the DataTable you may try the following code,
DataView dv = new DataView(myTable);
dv.Sort = "ddate7 ASC";
ddate.DataSource = dv;
ddate.DataTextField = "ddate7";
ddate.DataValueField = "ddate7";
ddate.DataBind();
Good luck.
精彩评论