【问题标题】:How to make button visible inside repeater?如何使按钮在中继器内可见?
【发布时间】:2016-07-04 15:34:28
【问题描述】:

在这里,我在repeater 中保留了两个按钮(btnhidebtnunhide)和一个label,并且我最初使按钮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")
    {


    }
}

【问题讨论】:

    标签: c# asp.net


    【解决方案1】:

    您可以通过将Text 更改为隐藏/取消隐藏并通过检查buttonText 属性来执行所需的功能,只需一个按钮即可实现此目的。

    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.
            }
    
        }
    }
    

    我希望,这会有所帮助。谢谢

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-05-28
      • 2013-11-25
      • 1970-01-01
      • 2011-06-04
      • 2012-08-12
      • 1970-01-01
      相关资源
      最近更新 更多