在我的网络应用程序中,我有(FAQ)页面,其中包含使用" FormView"从数据库中检索到的问题和答案。 ,当我点击Show-More Button时,我想要答案显示。
<asp:FormView ID="FormView1" runat="server" AllowPaging="True" DataSourceID="SqlDataSource1" Height="183px" Width="598px" OnPageIndexChanging="FormView1_PageIndexChanging1">
<EditItemTemplate>
Question:
<asp:TextBox ID="QuestionTextBox" runat="server" Text='<%# Bind("Question") %>' />
<br />
Answer:
<asp:TextBox ID="AnswerTextBox" runat="server" Text='<%# Bind("Answer") %>' />
<br />
<asp:LinkButton ID="UpdateButton" runat="server" CausesValidation="True" CommandName="Update" Text="Update" />
<asp:LinkButton ID="UpdateCancelButton" runat="server" CausesValidation="False" CommandName="Cancel" Text="Cancel" />
</EditItemTemplate>
<InsertItemTemplate>
Question:
<asp:TextBox ID="QuestionTextBox" runat="server" Text='<%# Bind("Question") %>' />
<br />
Answer:
<asp:TextBox ID="AnswerTextBox" runat="server" Text='<%# Bind("Answer") %>' />
<br />
<asp:LinkButton ID="InsertButton" runat="server" CausesValidation="True" CommandName="Insert" Text="Insert" />
<asp:LinkButton ID="InsertCancelButton" runat="server" CausesValidation="False" CommandName="Cancel" Text="Cancel" />
</InsertItemTemplate>
<ItemTemplate>
Q:
<asp:Label ID="QuestionLabel" runat="server" Text='<%# Bind("Question") %>' />
<br />
A:
<asp:Button ID="Button2" runat="server" Text="Show-More" onclick="Button2_Click" />
<asp:Label ID="AnswerLabel" runat="server" Text='<%# Bind("Answer") %>' Visible="False" />
<br />
</ItemTemplate>
</asp:FormView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:BiomedicalSampleConnectionString %>" SelectCommand="SELECT [Question], [Answer] FROM [KnowledgeBase]"></asp:SqlDataSource>
代码背后:
protected void Button2_Click(object sender, EventArgs e)
{
AnswerLabel.Visble = "true";
}
我收到了这个错误&#34; AnswerLabel并不存在于当前上下文中#34;