私は少し奇妙な問題を抱えています。以下の方法を使用して、リストビューヘッダーをクリックして ASC/DESC 順にソートする ListView があります。ObjectDataSource を定義してそれを ListView にアタッチすると、完全に機能します。
を使用して手動バインディングを使用するだけの場合
listview.DataSource = GetListViewContent();
listview.DataBind();
ソートが機能しなくなります。sort メソッドで再バインディングを試みましたが、それでも機能しません。何か不足していますか?
protected void lvFullReport_Sorting(object sender, ListViewSortEventArgs e)
{
Control me = (Control)sender,
headerRow = me.FindControl("headerRow");
//Assume that the "header row" control's "control collection" just contains "th"-like control,
//whose type is exactly "HtmlTableCell" . While we just utilize its properties in the "HtmlControl" level
//so we cast them as "HtmlControl".
//What's more , as for these "th" controls , just those who contains an "IButtonControl" ( sorting triggers)
//are really needed.
foreach (System.Web.UI.HtmlControls.HtmlControl sortCell in headerRow.Controls.Cast<System.Web.UI.HtmlControls.HtmlControl>()
.Where(th => th.Controls.OfType<IButtonControl>().Any()))
{
//Get out the "only" sorting-Button Control ,
//for that in a "th" those empty space or literal text area are treated as "Literal Control" ,
//"literal" fills whole space of "th".
IButtonControl btnSortField = sortCell.Controls.OfType<IButtonControl>().Single();
if (btnSortField.CommandArgument == e.SortExpression)
sortCell.Attributes["class"] = e.SortDirection == SortDirection.Ascending ? "up" : "down";
else
if (sortCell.Attributes["class"] != null) sortCell.Attributes.Remove("class");
}
DisplayChart();
}
GetListViewContent() は、手動および自動ソースのソースであり、表示目的で両方ともデータを表示するために機能します。ただし、並べ替えは自動でのみ機能します。