[英]How I create a EventHandler for a Button in ASP.NET
My Problem: 我的问题:
I have a ASP.NET Application and use a ListView. 我有一个ASP.NET应用程序,并使用ListView。 I get Datalines (eMail,Username,Firstname etc..) from the Active Directory and fill this in my ListView.
我从Active Directory获取数据行(电子邮件,用户名,名字等),并将其填写到我的ListView中。 Every Line has a Button "Show", with this Button I want to a other WebForm.
每行都有一个“显示”按钮,我想将该按钮与其他WebForm一起使用。 With a Session I surrender the Data to the other WebForm.
通过会话,我将数据提交到另一个WebForm。 My Code:
我的代码:
<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> //Every Line get a Button <td align="left"><asp:Button ID="Button1" Text ="Anzeigen" runat="server" /></td> </tr> </ItemTemplate> </asp:ListView>
The Button has a onClick= "..." Argument but how I make a Event for this and how I transfer to the other WebForm with the right Session Information. 该按钮具有onClick =“ ...”参数,但是我如何为此创建事件以及如何使用正确的会话信息将其转移到另一个WebForm。 I think I must work with the Index from the Line :/
我想我必须与The Line的Index合作:/
I need help :( 我需要帮助 :(
tarasov 塔拉索夫
Try this in your aspx you do 在您的aspx中尝试此操作
<asp:Button ID="Button1" OnCommand="Button1_Command" CommandArgument='<%# eval("ID") %>' CommandName="Anzeigen" runat="server" Text="Button" />
in code behind you do 用你背后的代码
protected void Button1_Command(object sender, CommandEventArgs e)
{
if (e.CommandName == "Anzeigen")
{
string sID = e.CommandArgument.ToString();
int id = 0;
int.TryParse(sID, out id);
if (id > 0)
{
// do stuff
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.