Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/278.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何获取ListView的右行索引_C#_Asp.net_Listview_Active Directory_Indexing - Fatal编程技术网

C# 如何获取ListView的右行索引

C# 如何获取ListView的右行索引,c#,asp.net,listview,active-directory,indexing,C#,Asp.net,Listview,Active Directory,Indexing,我编写了一个ASP.NET应用程序,可以从Active Directory获取数据。我使用ListView来显示这些数据。用户在文本框中输入字符串(Lastname或其一部分)。而不是ListView从文本框中列出具有相同字符串的所有广告用户。每行都有一个按钮“ANZEGEN”,以获取更多关于用户的信息。此ListView有六列,每行显示一个用户。第六列是按钮“ANZEGEN”。如果用户点击此按钮,打开一个新的网络表单“benutzer.aspx”,其中包含该用户的更多信息,并从该行获取会话值“

我编写了一个ASP.NET应用程序,可以从Active Directory获取数据。我使用ListView来显示这些数据。用户在文本框中输入字符串(Lastname或其一部分)。而不是ListView从文本框中列出具有相同字符串的所有广告用户。每行都有一个按钮“ANZEGEN”,以获取更多关于用户的信息。此ListView有六列,每行显示一个用户。第六列是按钮“ANZEGEN”。如果用户点击此按钮,打开一个新的网络表单“benutzer.aspx”,其中包含该用户的更多信息,并从该行获取会话值“email”

我的问题是:

我不知道如何获得会话值所需的ListView行的索引

我的代码:

cs文件:

 protected void Button1_Command(object sender, CommandEventArgs e)
        {
            if (e.CommandName == "Anzeigen")
            {

                //This give me everyone the Value -1 back 
                int selectedLine = myListView.SelectedIndex; 

                //I need the Line Index for the right Value
                Label lb = (Label)myListView.Items[selectedLine].FindControl("Label2"); 

                   string email = lb.Text;

                   Session["email"] = email; 

                Response.Redirect("Benutzer.aspx");

            }

        }
ASPX文件:

...
        <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>
...
。。。
...
我搜索并找到了listview SelectedDices,但它不起作用:(而且我不能在我的应用程序中使用它)


tarasov使用ListView的ItemCommand而不是Button的on命令

看 更多细节。 从示例中还可以看到,作者已从e.Item中提取了值。您可以将密钥(电子邮件、用户名或任何内容)作为CommandArgument传递,并可以直接从command argument访问该值。 如何通过它

<asp:LinkButton ID="myLink" runat="server" CommandName="Anzeigen" CommandArgument='<%#Eval("KeyColumn")%>'>Anzeigen</asp:LinkButton>
anzegen
也可以使用Linkbutton而不是Asp:Button

<td align="left"><asp:Button ID="Button1" Text="Anzeigen" OnCommand="Button1_Command" CommandName="Select" CommandArgument='<%# Container.DataItemIndex %>'  runat="server" /></td>

它没有提供获取行索引的其他方法?:/如果可以获取完整的行和键列值,为什么需要行索引?
protected void Button1_Command(object sender, CommandEventArgs e)
        {
            if (e.CommandName == "Select")
            {
               int index = Convert.ToInt32(e.CommandArgument);

                Label lb = (Label)myListView.Items[index].FindControl("Label2");

                string email = lb.Text;

                Session["email"] = email;

                Response.Redirect("Benutzer.aspx");

            }

        }