在一个 aspx 页面中,我有以下转发器:
<asp:Repeater runat="server" ID="r" OnItemCommand="paper_ItemCommand">
<ItemTemplate>
<div style="padding-bottom:20px">
<asp:HiddenField runat="server" ID="questionID" Value='<%# Eval("ID") %>'/>
<asp:Label runat="server" ID="questionNumber" Text='<%# Eval("Number") %>'/><br />
<asp:Label runat="server" ID="question1" Text='<%# Eval("Question1") %>' /><br />
[ <asp:Label runat="server" ID="questionMark" Text='<%# Eval("Mark") %>'/> ]<br />
<asp:Button ID="View_Conversations" runat="server" Text="View Conversations" CommandName="ViewConversationsCommand" />
</div>
</ItemTemplate>
<SeparatorTemplate>
<hr />
</SeparatorTemplate>
</asp:Repeater>
在文件后面的代码中,我有以下方法:
protected void Page_Load(object sender, EventArgs e)
{
var paperID = Session["paperID"].ToString();
QuestionPaper = repository.GetPaper(Int32.Parse(paperID));
r.DataSource = QuestionPaper.Questions;
r.DataBind();
}
protected void paper_ItemCommand(object sender, RepeaterCommandEventArgs e)
{
switch (e.CommandName)
{
case "ViewConversationsCommand":
var hidden = e.Item.FindControl("questionID") as HiddenField;
var myquestionID = hidden.Value;
break;
}
}
我遇到的问题是,当我单击转发器上的查看对话按钮时,代码会点击page_load方法而不是我的paper_ItemCommand方法。我在这里做错了什么?