简体   繁体   English

转发器中linkbutton的工作

[英]working of linkbutton in repeater

I used a linkbutton in repeater which on click shows data in a label.Now i want that clicking again the same linkbutton hide that data,means same button for showing and hiding data. 我在转发器中使用了一个linkbutton,它在单击时会显示标签中的数据。现在,我希望再次单击相同的linkbutton隐藏该数据,意味着显示和隐藏数据的相同按钮。 there is a database with a table which contains ques-description,date,sub. 有一个数据库,该数据库的表包含ques-description,date,sub。 by and ans. 通过和ans。
On page load only question appears. 在页面加载中仅出现问题。

Now this is the design code: 现在,这是设计代码:

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

And this is the html code i used: 这是我使用的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>  

But i don't know how to hide data again clicking the same linkbutton. 但是我不知道如何再次单击相同的链接按钮来隐藏数据。 Is it possible with a single button? 一个按钮可以实现吗?

What hinders you to check if the label is visible and hide/show it accordingly? 是什么阻碍您检查标签是否可见并相应地隐藏/显示它?

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM