2012-07-21 84 views
1

我的情況:我如何獲得一個ListView項目的會話信息

我有一個ListView,從Active Directory獲取數據。用戶在TextBox中輸入一個字符串(姓氏或這個的一部分)。與ListView相比,列出了TextBox中具有相同字符串的所有AD用戶。每行都會得到一個按鈕「Anzeigen」以獲取有關用戶的更多信息。第二個WebForm「Benutzer.aspx」顯示有關此用戶的信息。我想我需要爲第二個WebForm選定的用戶的值(ID或電子郵件)。所以我需要一個會話。所以如果我點擊按鈕「Anzeigen」,我需要電子郵件的價值或ect。這實際上在ListView中的Line。

我的問題:

我不知道我怎麼能得到這個的ListView行的其他信息。我想我需要一種索引或者我必須控制一個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

如果我unerstand正確的,你需要一個參考標籤,該標籤顯示的電子郵件列表視圖。對於第一次獲得參考,請參閱下面的代碼:

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

     } 
} 
+0

Label l =(Label)myListView.Items [1] .FindControl(「Label2」); – Tarasov 2012-07-21 18:57:58

+0

Label lb =(Label)myListView.Items(1).FindControl(「Label2」); //我的代碼(1)在我的代碼中是錯誤的... [1]是正確的...爲什麼? ^^ – Tarasov 2012-07-21 18:58:43

+0

@Tarasov你正在使用C#或VB?如果C#那麼它應該是Items [1]如果VB然後Items(1) – 2012-07-21 19:03:19

相關問題