在转发器中工作linkbutton

时间:2013-02-14 13:44:37

标签: c# repeater asp.net-4.5

我在转发器中使用了一个链接按钮,点击后会显示标签中的数据。现在我想要再次点击相同的链接按钮隐藏该数据,意味着显示和隐藏数据的相同按钮。 有一个包含问题描述,日期,子的表的数据库。由和ans。
在页面加载时出现问题。

现在这是设计代码:

protected void Repeater1_ItemCommand(object source, RepeaterCommandEventArgs e)
       {  
            if (e.CommandName == "showanswers")  
            {  
                Control control;  
                control = e.Item.FindControl("date");
                if(control!=null)
                control.Visible = true;
                control = e.Item.FindControl("subby");
                if(control!=null)
                control.Visible = true;
                control = e.Item.FindControl("ans");
                if(control!=null)
                control.Visible = true;
            }

这是我使用的HTML代码:

  

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

            <ItemTemplate>
                <table>
                        <b>Question<%#Container.ItemIndex + 1%>:</b><%#Eval("qstdsc") %><br />
                        <asp:linkbutton ID="Button1" Text="Ans." commandname="showanswers" runat ="server" /><br />
                    </table>
                <table>
                        <asp:Label id="date" Text='<%# Eval("qstdat")%>' Visible="false" runat="server"/>
                    </table>
                    <table>    
                    <asp:Label id="subby" runat="server" Text='<%# Eval("qstsubby")%>' Visible="false" />
                       </table>
                <table>
                         <asp:Label id="ans" runat="server" Text='<%# Eval("qstans")%>' Visible="false" />
                </table>

             </ItemTemplate>
        </asp:Repeater>  

但我不知道如何再次点击相同的链接按钮隐藏数据。 用一个按钮可以吗?

1 个答案:

答案 0 :(得分:0)

什么阻碍您检查标签是否可见并相应地隐藏/显示?

protected void lnkBtnShowDataLabel_Click(Object sender, EventArgs e)
{
    lblData.Visible = !lblData.Visible;
}