ListViewを並べ替えたいのですが、コードで機能しません:(
aspx:
<asp:ListView runat="server" ID="myListView" OnItemCommand="myListView_ItemCommand" OnSelectedIndexChanging="myListView_SelectedIndexChanging" OnSorting="myListView_Sorting">
<LayoutTemplate>
<table id="UserTable" runat="server" border="0" width="800" cellpadding="0" cellspacing="0">
<tr style="background-color:#E5E5FE" class="TableClass">
<th align="left" id="th4" runat="server"><asp:LinkButton ID="lnkNachname" CommandArgument="Nachname" CommandName="Sort" runat="server" >id_Nachname</asp:LinkButton></th>
<th align="left" id="th3" runat="server"><asp:LinkButton ID="lnkVorname" CommandArgument="Vorname" CommandName="Sort" runat="server" >id_Vorname</asp:LinkButton></th>
<th align="left" id="th5" runat="server"><asp:Label ID="lnkTelefon" runat="server" >id_Telefon</asp:Label></th>
<th align="left" id="th6" runat="server"><asp:Label ID="lnkAbteilung" runat="server">id_Abteilung</asp:Label></th>
<th align="left" id="th2" runat="server"><asp:Label ID="lnkemail" runat="server" >id_Email</asp:Label></th>
</tr>
<tr runat="server" id="ItemPlaceholder">
</tr>
</table>
</LayoutTemplate>
<ItemTemplate>
<tr class="TableClass">
<td align="left"><asp:LinkButton CssClass="MyLink" CommandName="Select" CommandArgument='<%# Container.DataItemIndex %>' ID="Label4" Text='<%# Eval("Nachname") %>' runat="server" /></td>
<td align="left"><asp:LinkButton CssClass="MyLink" CommandName="Select" CommandArgument='<%# Container.DataItemIndex %>' ID="Label3" Text='<%# Eval("Vorname") %>' runat="server" /></td>
<td align="left"><asp:LinkButton CssClass="MyLink" CommandName="Select" CommandArgument='<%# Container.DataItemIndex %>' ID="Label5" Text='<%# Eval("Telefonnummer") %>' runat="server" /></td>
<td align="left"><asp:LinkButton CssClass="MyLink" CommandName="Select" CommandArgument='<%# Container.DataItemIndex %>' ID="Label7" Text='<%# Eval("Abteilung") %>' runat="server" /></td>
<td align="left"><asp:LinkButton CssClass="MyLink" CommandName="Select" CommandArgument='<%# Container.DataItemIndex %>' ID="Label2" Text='<%# Eval("eMail") %>' runat="server" /></td>
<td align="left"><asp:Label ID="Label6" Text='<%# Eval("GUID") %>' runat="server" Visible="False" /></td>
</tr>
</ItemTemplate>
<AlternatingItemTemplate>
<tr class="TableClass">
<td align="left"><asp:LinkButton CssClass="MyLink" CommandName="Select" CommandArgument='<%# Container.DataItemIndex %>' ID="Label4" Text='<%# Eval("Nachname") %>' runat="server" /></td>
<td align="left"><asp:LinkButton CssClass="MyLink" CommandName="Select" CommandArgument='<%# Container.DataItemIndex %>' ID="Label3" Text='<%# Eval("Vorname") %>' runat="server" /></td>
<td align="left"><asp:LinkButton CssClass="MyLink" CommandName="Select" CommandArgument='<%# Container.DataItemIndex %>' ID="Label5" Text='<%# Eval("Telefonnummer") %>' runat="server" /></td>
<td align="left"><asp:LinkButton CssClass="MyLink" CommandName="Select" CommandArgument='<%# Container.DataItemIndex %>' ID="Label7" Text='<%# Eval("Abteilung") %>' runat="server" /></td>
<td align="left"><asp:LinkButton CssClass="MyLink" CommandName="Select" CommandArgument='<%# Container.DataItemIndex %>' ID="Label2" Text='<%# Eval("eMail") %>' runat="server" /></td>
<td align="left"><asp:Label ID="Label6" Text='<%# Eval("GUID") %>' runat="server" Visible="False" /></td>
</tr>
</AlternatingItemTemplate>
</asp:ListView>
私のcsコード:
protected void myListView_Sorting(object sender, ListViewSortEventArgs e)
{
if (e.SortDirection == System.Web.UI.WebControls.SortDirection.Ascending)
{
System.Web.UI.WebControls.SortDirection sortdir = System.Web.UI.WebControls.SortDirection.Descending;
myListView.Sort(e.SortExpression, sortdir);
}
else
{
System.Web.UI.WebControls.SortDirection sortdir = System.Web.UI.WebControls.SortDirection.Ascending;
myListView.Sort(e.SortExpression, sortdir);
}
}
ヘッダーのリンクボタンをクリックすると、上下の画像を含む並べ替えリストビューが表示されますが、待機できます。まず、LinkButtonClickで動作する必要があります。