Asp.net Webforms:UpdatePanel中的Update RadioButtonList

Asp.net Webforms:UpdatePanel中的Update RadioButtonList,asp.net,webforms,updatepanel,radiobuttonlist,Asp.net,Webforms,Updatepanel,Radiobuttonlist,我正在尝试做一个网页,下面有一个问题和答案。问题是一个问题,答案是一个无线电按钮列表。我想在单击提交按钮后,使用ajax(在UpdatePanel中)更改问题和答案以及其他问题和答案。这是我的html: <asp:UpdatePanel runat="server" ID="QuestionUpdatePanel" UpdateMode="Conditional"> <ContentTemplate> <div>

我正在尝试做一个网页,下面有一个问题和答案。问题是一个问题,答案是一个无线电按钮列表。我想在单击提交按钮后,使用ajax(在UpdatePanel中)更改问题和答案以及其他问题和答案。这是我的html:

<asp:UpdatePanel runat="server" ID="QuestionUpdatePanel" UpdateMode="Conditional">
    <ContentTemplate>
        <div>
            <asp:Label ID="QuestionLabel" runat="server"></asp:Label>
        </div>
        <asp:RadioButtonList ID="RadioButtonList" runat="server" SelectMethod="GetAnswersData"></asp:RadioButtonList>
        <asp:Button runat="server" ID="SubmitAnswerButton" Text="Submit Answer" OnClick="SubmitAnswerButton_Click" />
    </ContentTemplate>
</asp:UpdatePanel>

我的脚本管理器在母版页中定义

代码背后:

private int currentQuestion = 0;
private int currentGameId = 0;

protected void Page_Load(object sender, EventArgs e)
    {
        this.currentGameId = int.Parse(Request.QueryString["id"]);
        LoadFirstQuestion();
    }

    private void LoadFirstQuestion()
    {
        this.QuestionLabel.Text = this.games.GetById(this.currentGameId).Questions.FirstOrDefault().Text;
        currentQuestion++;
    }

public IQueryable<string> GetAnswersData()
    {
        var answers = new List<string>();
        answers.Add(this.games.GetById(currentGameId).Questions.Skip(currentQuestion - 1).Take(1).FirstOrDefault().WrongAnswerOne);
        answers.Add(this.games.GetById(currentGameId).Questions.Skip(currentQuestion - 1).Take(1).FirstOrDefault().WrongAnswerTwo);
        answers.Add(this.games.GetById(currentGameId).Questions.Skip(currentQuestion - 1).Take(1).FirstOrDefault().WrongAnswerThree);
        answers.Add(this.games.GetById(currentGameId).Questions.Skip(currentQuestion - 1).Take(1).FirstOrDefault().TrueAnswer);

        return answers.AsQueryable();
    }

    protected void SubmitAnswerButton_Click(object sender, EventArgs e)
    {
        CheckIfCorrectAnswer();
        currentQuestion++;
        this.RadioButtonList.DataSource = GetAnswersData();
        this.RadioButtonList.DataBind();
        this.QuestionUpdatePanel.Update();
    }
private int currentQuestion=0;
私有int currentGameId=0;
受保护的无效页面加载(对象发送方、事件参数e)
{
this.currentGameId=int.Parse(Request.QueryString[“id]”);
LoadFirstQuestion();
}
私有void LoadFirstQuestion()
{
this.QuestionLabel.Text=this.games.GetById(this.currentGameId).Questions.FirstOrDefault().Text;
当前问题++;
}
公共可查询的GetAnswersData()
{
var answers=新列表();
answers.Add(this.games.GetById(currentGameId).Questions.Skip(currentQuestion-1).Take(1.FirstOrDefault().ErrorAnswerOne);
answers.Add(this.games.GetById(currentGameId).Questions.Skip(currentQuestion-1).Take(1.FirstOrDefault().ErrorAnswerTwo);
answers.Add(this.games.GetById(currentGameId).Questions.Skip(currentQuestion-1).Take(1.FirstOrDefault().ErrorAnswerThree);
Add(this.games.GetById(currentGameId).Questions.Skip(currentQuestion-1).Take(1.FirstOrDefault().TrueAnswer);
返回答案。AsQueryable();
}
受保护的无效提交按钮单击(对象发送者,事件参数e)
{
CheckIfCorrectAnswer();
当前问题++;
this.RadioButtonList.DataSource=GetAnswersData();
this.RadioButtonList.DataBind();
this.QuestionUpdatePanel.Update();
}
因此,我在
this.RadioButtonList.DataBind()上得到了错误行,表示:

{“无法在“RadioButtonList”上定义DataSource或DataSourceID” 当它使用模型绑定时。“}

提前感谢!:)


我找到了解决这个问题的办法。我只需要将
GetAnswersData()
方法的返回类型更改为
IList