2016-07-04 50 views
0

在这里我已经保存了两个按钮(btnhidebtnunhide)和label里面的repeater和我已经使按钮btnunhide最初不可见。现在我想要的是当我按下按钮btnhide然后btnunhide这是不可见的应该是visible。 解决方案将有很大的帮助。如何让按钮在中继器内可见?

使用HTML

<asp:Repeater ID="Repeater1" runat="server" OnItemCommand="Repeater1_ItemCommand" > 
     <ItemTemplate> 

      <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label> 
      <asp:Button ID="btn" CommandName="h" runat="server" Text="Hide" /> 
      <asp:Button ID="btnhide" Visible="false" runat="server" Text="Unhide" />  

     </ItemTemplate> 
    </asp:Repeater> 

代码背后

protected void Repeater1_ItemCommand(object source, RepeaterCommandEventArgs e) 
{ 
    if (e.CommandName == "h") 
    { 


    } 
} 

回答

0

您可以通过只是一个单一的按钮,通过改变Text隐藏/取消隐藏,然后执行功能所要求的只是检查Text实现这一目标button的财产。

protected void Repeater1_ItemCommand(object source, RepeaterCommandEventArgs e) 
{ 
    if (e.CommandName == "h") 
    { 
     Button btn = (Button)(e.CommandSource); 
     if(btn.Text == "hide") 
     { 
      btn.Text = "unhide"; 
      //Do additional work here, when unhiding. 
     } 
     else 
     { 
      btn.Text = "hide"; 
      //Do additional work here, when hiding. 
     } 

    } 
} 

我希望,这有助于。谢谢