如何在链接按钮单击中获取父转发器内的值?

时间:2016-12-27 13:29:19

标签: c# asp.net

在链接按钮上单击,我想获取包含在转发器中的隐藏字段的值。以下是我的代码

aspx页面:

<asp:Repeater ID="rpt1" runat="server">
      <ItemTemplate>
              <asp:LinkButton ID="lnkBtn1" runat="server" OnClick="btnClick"/>
              <asp:HiddenField ID="hdn1" runat="server" Value="true"/>
      </ItemTemplate>
</asp:Repeater>


CodeBehind:

protected void btnClick(object sender, EventArgs e)
{
   //How to get the value of the hidden field hdn1 over here
}

1 个答案:

答案 0 :(得分:3)

试试这个

从Button中查找转发器行作为发件人,然后在(RepeaterItem)转发器行中找到隐藏字段

protected void btnClick(object sender, EventArgs e)
{
   LinkButton   lnkBtn1= sender as LinkButton;
   RepeaterItem Rptitem = (RepeaterItem)lnkBtn1.NamingContainer;
   HiddenField  hdn1 =  (HiddenField  ) Rptitem.FindControl("hdn1");
   string hiddenvalue=hdn1.Value;

}