0

我有一个多项选择题的对象列表。我需要使用对象属性创建一个 RadioButtonList:Choice_A、Choice_B、... Choice_D。

var qs = (from questions in dc.Survey_Questions
                  where questions.Survey_ID == surveyid                     
                  select new SQuestions
                  {
                      QuestionID = questions.Question_ID,
                      SurveyID = questions.Survey_ID,                         
                      Description = questions.Description,
                      Choice_A = questions.Choice_A,
                      Choice_B = questions.Choice_B,
                      Choice_C = questions.Choice_C,
                      Choice_D = questions.Choice_D,
                    }).ToList();
DataList dtQuestion.DataSource = qs;

HTML结构:

<asp:DataList ID="dtQuestion" runat="server" RepeatDirection="Vertical" >`
    <ItemTemplate>
        <%# Eval("Description") %> `          
    <ItemTemplate> 
    <RadioButtonList></RadiobuttonList>
    </ItemTemplate>

    </ItemTemplate>
</asp:DataList>
4

1 回答 1

0

好的,尝试建模 SQuestion 以匹配以下内容:

public class SQuestion
{
    int QuestionId = 0; //int? change to whatever
    int SurveyId = 0; //same as above
    string Description = string.Empty;
    List<string> Choices = new List<string>(); //notice this is a list
}

所以现在您可以将选项绑定到下拉列表。我建议使用 onDataBinding 方法或 onDataBound (其中之一,我不确定),然后您可以将内部选择下拉列表与当前 question.Choices 绑定。那应该行得通。

希望这有助于为您指明正确的方向。

于 2012-07-26T00:38:37.810 回答