我如何获取会话的ListView项目的信息

时间:2012-07-21 15:29:31

标签: c# asp.net session listview webforms

我的情况:

我有一个ListView,它从Active Directory获取数据。用户在TextBox中输入字符串(姓氏或其中的一部分)。比ListView列出所有AD用户与TextBox中的相同字符串。每一行都有一个按钮“Anzeigen”以获得更多关于用户的信息。第二个WebForm“Benutzer.aspx”显示有关此用户的信息。我想我需要第二个WebForm的所选用户的值(ID或电子邮件)。所以我需要一个会议。因此,如果我点击按钮“Anzeigen”,我需要电子邮件的价值等。这实际上是ListView中的Line。

我的问题:

我不知道如何获取此ListView Line的其他信息。我想我需要一种索引,否则我必须控制一个Cell。

我的代码:

ASPX

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

        <LayoutTemplate>
            <table id="UserTable" runat="server" border="0" cellspacing="10" cellpadding="5">
                <tr id="Tr1" runat="server">
                    <th id="Th1" runat="server">Benutzer</th>
                    <th id="Th2" runat="server">eMail</th>
                    <th id="Th3" runat="server">Vorname</th>
                    <th id="Th4" runat="server">Nachname</th>
                    <th id="Th5" runat="server">Telefon</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>

        </asp:ListView>

CS

protected void Button1_Command(object sender, CommandEventArgs e)
        {
            if (e.CommandName == "Anzeigen")
            {
              //Here I need a Session and the Informations about the Selected User in the Line

                Response.Redirect("Benutzer.aspx");

            }
    }

塔拉索夫

1 个答案:

答案 0 :(得分:1)

如果我理解正确,您需要一个Label标签,在列表视图中显示电子邮件。首先获得参考,请参阅以下代码:

protected void Button1_Command(object sender, CommandEventArgs e)
    {
        if (e.CommandName == "Anzeigen")
        {
          //Here I need a Session and the Informations about the Selected User in the Line
            Label lb = (Label) myListView.Items(1).FindControl("Label2"); // give the right index, Label2 contains the email so give its ID but index should be correct
            string email = lb.Text;
            Response.Redirect("Benutzer.aspx");

        }
}
相关问题