0

我的程序:

我有一个 ListView,它从 Active Directory 中获取数据。用户在文本框中输入一个字符串(姓氏或其中的一部分)。比 ListView 列出 TextBox 中具有相同字符串的所有 AD 用户。每行(行)都有一个按钮“Anzeigen”以获取有关用户的更多信息。

ASPX:

<asp:ListView runat="server" ID="myListView">

        <LayoutTemplate>
            <table id="UserTable" runat="server" border="0" cellspacing="10" cellpadding="2">
                <tr runat="server" id="Tr1" style="background-color:#E5E5FE">
                    <th runat="server"><asp:LinkButton ID="lnkBenutzer" runat="server" CommandName="Sort" CommandArgument="Benutzer" onsorting="ListView1_Sorting">Benutzer</asp:LinkButton></th>
                    <th runat="server"><asp:LinkButton ID="lnkemail" runat="server" CommandName="Sort" CommandArgument="eMail" onsorting="ListView1_Sorting" >eMail</asp:LinkButton></th>
                    <th runat="server"><asp:LinkButton ID="lnkVorname" runat="server" CommandName="Sort" CommandArgument="Vorname" onsorting="ListView1_Sorting" >Vorname</asp:LinkButton></th>
                    <th runat="server"><asp:LinkButton ID="lnkNachname" runat="server" CommandName="Sort" CommandArgument="Nachname" onsorting="ListView1_Sorting" >Nachname</asp:LinkButton></th>
                    <th runat="server"><asp:LinkButton ID="lnkTelefon" runat="server" CommandName="Sort" CommandArgument="Telefon" onsorting="ListView1_Sorting"  >Telefon</asp:LinkButton></th>
                </tr>
                <tr runat="server" id="ItemPlaceholder">
                </tr>
            </table>
        </LayoutTemplate>

        <ItemTemplate>

            <tr runat="server"> 

                <td align="left" ><asp:Label ID="Label1" Text='<%# Eval("Benutzer") %>' runat="server" /></td>
                <td align="left"><asp:Label ID="Label2" Text='<%# Eval("eMail") %>' runat="server" /></td>
                <td align="left"><asp:Label ID="Label3" Text='<%# Eval("Vorname") %>' runat="server" /></td>
                <td align="left"><asp:Label ID="Label4" Text='<%# Eval("Nachname") %>' runat="server" /></td>
                <td align="left"><asp:Label ID="Label5" Text='<%# Eval("Telefon") %>' runat="server" /></td>

             <td align="left"><asp:Button ID="Button1" Text="Anzeigen" OnCommand="Button1_Command" CommandName="Anzeigen" CommandArgument="MyArgument" runat="server" /></td>

            </tr>

        </ItemTemplate>

        <AlternatingItemTemplate>

            <tr style="background-color:#EFEFEF"> 

                <td align="left" ><asp:Label ID="Label1" Text='<%# Eval("Benutzer") %>' runat="server" /></td>
                <td align="left"><asp:Label ID="Label2" Text='<%# Eval("eMail") %>' runat="server" /></td>
                <td align="left"><asp:Label ID="Label3" Text='<%# Eval("Vorname") %>' runat="server" /></td>
                <td align="left"><asp:Label ID="Label4" Text='<%# Eval("Nachname") %>' runat="server" /></td>
                <td align="left"><asp:Label ID="Label5" Text='<%# Eval("Telefon") %>' runat="server" /></td>

             <td align="left"><asp:Button ID="Button1" Text="Anzeigen" OnCommand="Button1_Command" CommandName="Anzeigen" CommandArgument="MyArgument" runat="server" /></td> 

            </tr>

        </AlternatingItemTemplate>

CS文件:

...

protected void ListView1_Sorting(object sender, ListViewSortEventArgs e)
        {
            //here???
        }

...

我想要的是:

如果用户单击链接按钮“Benutzer”,则列表必须按字母排序:PI 查看网站http://www.codeproject.com/Articles/24570/Complete-ListView-in-ASP-NET-3-5但在示例和下载文件中不存在这种排序方法:(

现在我不知道如何对列表进行排序。

所以我用数据填充我的列表:

protected void btnBenutzerSuchen_Click(object sender, EventArgs e)
        {
            DirectoryEntry Entry = new DirectoryEntry("LDAP://" + "Domain");

            string filter = "(&(objectClass=user)(objectCategory=person)(cn=" + txtBenutzer.Text + "*))";

            DirectorySearcher Searcher = new DirectorySearcher(Entry, filter);

            var q = from s in Searcher.FindAll().OfType<SearchResult>()
                    select new
                    {
                        Benutzer = GetProperty(s, "sAMAccountName"),
                        eMail = GetProperty(s, "mail"),
                        Vorname = GetProperty(s, "givenName"),
                        Nachname = GetProperty(s, "sn"),
                        Telefon = GetProperty(s, "telephoneNumber")
                    };

            this.myListView.DataSource = q;
            this.myListView.DataBind();

        }

塔拉索夫

4

1 回答 1

0

在这里,您要根据 dataname 对数据进行排序。为此,您必须将 datakey 传递给 rowdataBound 事件。

喜欢' :

protected void gvEmployeeList_RowCommand(object sender, GridViewCommandEventArgs e)
{
    if (e.CommandName == "name")
    {
        int index = Convert.ToInt32(e.CommandArgument);
        GridViewRow selectedRow = gvEmployeeList.Rows[index];
        string deptID = gridview1.DataKeys[index].Value.ToString().Trim();
         DataTable dtEmplist = new DataTable();
        dtEmplist = getFilterEmployeeList(deptID);
        if (dtEmplist.Rows.Count > 0)
        {
            gridview1.DataSource = dtEmplist;
            gridview1.DataBind();
        }
        else
        {
            lblMsg.Text = "No Data Available";
        }
    }
}

获取数据密钥后

按 (GridViewSortEventArgs e) 排序

e.sortExpression 属性。

它会帮助你我的朋友......

于 2012-07-23T09:58:17.663 回答