列を持つ ASP.Net アプリケーションで ListView を使用します
[Lastname] [Firstname] [telephonenumber][Department][eMail]
と
LayoutTemplate、ItemTemplate、および AlternatingItemTemplate に組み込まれた私の ListView。
ここで、ヘッダーテキストの姓または名をクリックすると、ソートリストが表示されるようにしたいと考えています。どうすればこれを行うことができますか?
ここに私のリストビューがあります:
<asp:ListView runat="server" ID="myListView" OnItemCommand="myListView_ItemCommand" OnSelectedIndexChanging="myListView_SelectedIndexChanging">
<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 CommandName="Sort" CommandArgument="Nachname" ID="lnkNachname" runat="server" >id_Nachname</asp:LinkButton></th>
<th align="left" id="th3" runat="server"><asp:LinkButton CommandName="Sort" CommandArgument="Vorname" ID="lnkVorname" 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.SortExpression == "Vorname")
{
e.SortDirection = System.Web.UI.WebControls.SortDirection.Ascending;
}
else
{
e.SortDirection = System.Web.UI.WebControls.SortDirection.Ascending;
}
}