1

私の状況:

ActiveDirectoryからデータを取得するListViewがあります。ユーザーは、テキストボックスに文字列(姓またはこの一部)を入力します。ListViewリストよりも、TextBoxからの同じ文字列を持つすべてのADユーザーを一覧表示します。すべての行には、ユーザーに関する詳細情報を取得するためのボタン「Anzeigen」が表示されます。2番目のWebフォーム「Benutzer.aspx」には、このユーザーに関する情報が表示されます。2番目のWebフォームには、選択したユーザーの値(IDまたは電子メール)が必要だと思います。だから私はセッションが必要です。したがって、「Anzeigen」ボタンをクリックすると、電子メールまたは電気ショック療法の値が必要になります。これは実際にはListViewのLineです。

私の問題:

このListView行の他の情報を取得する方法がわかりません。ある種のインデックスが必要か、セルを制御する必要があると思います。

私のコード:

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");

            }
    }

タラソフ

4

1 に答える 1

1

正しく理解できない場合は、リストビューに電子メールを表示するラベルへの参照が必要です。これについては、最初にリファレンスを入手してください。以下のコードを参照してください。

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");

        }
}
于 2012-07-21T18:49:44.947 に答える