0

我想对我的 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);

            }

        }

我想如果我单击标题中的链接按钮,我会得到一个带有上下图像的排序列表视图,但这可以等待。首先它必须与 LinkBut​​tonClick 一起使用。

4

0 回答 0