C# 如何编程中继器内的按钮单击事件
我是ASP.NET新手。我在中继器里加了一个按钮。当用户单击按钮时,中继器外的标签上应显示特定的行值。这就是我想要实现的设计 中继器:C# 如何编程中继器内的按钮单击事件,c#,html,asp.net,C#,Html,Asp.net,我是ASP.NET新手。我在中继器里加了一个按钮。当用户单击按钮时,中继器外的标签上应显示特定的行值。这就是我想要实现的设计 中继器: <asp:Repeater ID="rpt3" runat="server"> <ItemTemplate> <h3> <%#Eval("name") %> </h3> <asp:Button ID="Button1" runat="server" Text="Show Det
<asp:Repeater ID="rpt3" runat="server">
<ItemTemplate>
<h3> <%#Eval("name") %> </h3>
<asp:Button ID="Button1" runat="server" Text="Show Details"/>
</ItemTemplate>
</asp:Repeater>
<asp:Label ID="Label1" runat="server" ></asp:Label>
有很多方法,可以在页面加载时添加单击事件。只需检查repeater内的项目,并将按钮单击事件设置为:
foreach (RepeaterItem rptItem in rpt3.Items)
{
Button btn = rptItem .FindControl("btnShowLabel") as Button;
btn.Click += new EventHandler(btn_Click);
}
void btn_Click(object sender, EventArgs e)
{
Button btn = (Button)sender;
RepeaterItem rptItem = (RepeaterItem)btn.NamingContainer;
Label lb = (Label)rptItem.FindControl("lbShowing");
lb.Text = "Showing you text here";
}
然后,您可以在单击事件时执行任务,如:
foreach (RepeaterItem rptItem in rpt3.Items)
{
Button btn = rptItem .FindControl("btnShowLabel") as Button;
btn.Click += new EventHandler(btn_Click);
}
void btn_Click(object sender, EventArgs e)
{
Button btn = (Button)sender;
RepeaterItem rptItem = (RepeaterItem)btn.NamingContainer;
Label lb = (Label)rptItem.FindControl("lbShowing");
lb.Text = "Showing you text here";
}
protected void rp3_ItemCommand(object source, RepeaterCommandEventArgs e)
{
if (e.CommandName == "show")
{
}
}
正面
好的,但我想显示与行按钮单击相关的数据库表行值。就像我们单击按钮一样,它将在与该行相关的标签上显示用户详细信息。是,您可以将按钮上的datatabase id设置为命令参数,然后只需将该commandargument值传递给数据库逻辑,数据库逻辑将只返回该用户信息。您在按钮CommandArgument=“121”的属性上设置的命令参数您能给我一些示例吗?先生,我正在选择第一个