[英]How to get Link button generated text inside repeater control
I am creating a social network site, I cant seem to get the "LinkEmail" in the code behind, I need this to function as I then use it to post to the database. 我正在创建一个社交网站,我似乎无法在后面的代码中获得“ LinkEmail”,我需要此功能,然后再使用它发布到数据库。
The LinkEmail
is being dynamically generated in the first repeater, I need a way to grab that value. LinkEmail
是在第一个转发器中动态生成的,我需要一种方法来获取该值。
at the moment I am getting this error in the browser: 目前,我在浏览器中收到此错误:
Compiler Error Message: CS0103: The name 'LinkEmail' does not exist in the current context
编译器错误消息:
CS0103: The name 'LinkEmail' does not exist in the current context
this is aspx code 这是aspx代码
<asp:Repeater runat="server" ID="Repeater1">
<ItemTemplate>
<div style="border-top: thin none #91ADDD; border-bottom: thin none #91ADDD; padding: 10px; width: 548px; margin-top: 10px; right: 10px; left: 10px; border-left-width: thin; margin-left: 15px; background-color: #F6F6F6; border-left-color: #91ADDD; border-right-color: #91ADDD;">
<br />
<div style="width: 58px; height: 40px">
<asp:Image ID="Image2" runat="server" Height="59px" ImageAlign="Top" ImageUrl="~/Profile/Image/Default.png" Width="55px" />
</div>
<div style="width: 307px; margin-left: 65px; margin-top: -60px">
<asp:Label ID="Label6" runat="server" Font-Bold="True" Font-Names="Arial" ForeColor="#3b5998"><%#Eval("YourName") %> </asp:Label>
</div>
<div id="status" style=" width: 461px; margin-left: 78px; margin-top: 11px;"> <asp:Label ID="Label7" runat="server" Font-Italic="False" ForeColor="Black" Font-Size="Medium"><%#Eval("Birthday") %> </asp:Label>
<asp:LinkButton ID="LinkEmail" runat="server" OnClick="lbl_Click"><%#Eval("Email") %></asp:LinkButton>
<asp:Button ID="Button1" runat="server" Text="Button" />
</div>
</div>
</ItemTemplate>
Actually i want to get Link button generated text as a session like this photo when someone click this link. 实际上,当某人单击此链接时,我想获取“链接”按钮生成的文本作为会话,例如这张照片 。 could you give me a suitable codes for this.
你能给我合适的代码吗
According to this photo amilamunasinha@gmail.com must be LinkEmail.Text ,,, I want like this 根据这张照片amilamunasinha@gmail.com必须是LinkEmail.Text ,,我想要这样
The first thing you have to do, once your Repeater
control is on your Web page, is register for the ItemCommand
event. 一旦将
Repeater
控件放置在网页上,您要做的第一件事就是注册ItemCommand
事件。 I prefer to do this within the OnInit
event of the page instead of placing it as an attribute of the asp:Repeater
tag. 我更喜欢在页面的
OnInit
事件中执行此操作,而不是将其放置为asp:Repeater
标记的属性。
In .cs file: 在.cs文件中:
override protected void OnInit(EventArgs e)
{
base.OnInit(e);
Repeater1.ItemCommand += new RepeaterCommandEventHandler(Repeater1_ItemCommand);
}
private void Repeater1_ItemCommand(object source, RepeaterCommandEventArgs e)
{
switch (e.CommandName)
{
case "mail":
string emailId = e.CommandArgument.ToString();
break;
}
}
In aspx: 在aspx中:
<asp:LinkButton ID="LinkEmail" runat="server" CommandName="mail" CommandArgument='<%# Eval("Email") %>'><%#Eval("Email") %></asp:LinkButton>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.