クリックするとラベルにデータが表示されるリピーターでリンクボタンを使用しました。同じリンクボタンをもう一度クリックすると、そのデータが非表示になり、データを表示および非表示にするための同じボタンが表示されます。ques-description,date,sub を含むテーブルを持つデータベースがあります。と 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>
しかし、同じリンクボタンをクリックしてデータを再度非表示にする方法がわかりません。ボタン一つで出来ますか?