简体   繁体   中英

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. there is a database with a table which contains ques-description,date,sub. by and 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:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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