私はasp:GridView
コントロールを持っています、それは私がAllowSorting="True"
プロパティを設定しました:
<asp:GridView ID="gridUsers" runat="server" PageSize="100" ShowHeaderWhenEmpty="True"
Width="100%" AllowSorting="True" onrowcreated="gridUsers_RowCreated"
onsorting="gridUsers_Sorting">
</asp:GridView>
設計時には、グリッドは並べ替え可能に見えます。
ただし、実行時には、真ん中の列のみが並べ替え可能です。
asp:GridView
ASP.NETで並べ替え可能にするにはどうすればよいですか?
注:asp:GridView
withにAllowSorting
は、Sorting
イベントハンドラーが存在する必要があります。
protected void gridUsers_Sorting(object sender, GridViewSortEventArgs e)
{
//asp:GridView will throw an exception if a Sorting event handler isn't present
}
更新:説明列の何が特別なのかを理解しました。これは、データベースからそのまま表示名が正しい唯一の列です。残りの列は、表示名を表示できるように修正する必要があります。
protected void gridUsers_RowCreated(object sender, GridViewRowEventArgs e)
{
e.Row.Cells[0].Visible = false; //UserGUID
e.Row.Cells[1].Text = "User name";
e.Row.Cells[2].Text = "Full name";
//3=Description
e.Row.Cells[4].Text = "E-mail";
e.Row.Cells[5].Text = "Active";
e.Row.Cells[5].Visible = false;
e.Row.Cells[6].Text = "Account type";
}
今、私はトリッキーな部分を理解する必要があります。列を並べ替え可能にします。