1

我正在尝试RadioButtonList从数据库中填充一个并将其输出到ListView

我试过的:

ASP:

<ItemTemplate>
    <asp:RadioButtonList runat="server" DataSource=<%#Eval("respostas")%>></asp:RadioButtonList>
</ItemTemplate>

C#:

DataRow dr = dt.NewRow();
dr["nome_pergunta"] = reader["pergunta"];

DataTable respostas = new DataTable();
respostas.Columns.Add("respostaA", typeof(string));
respostas.Columns.Add("respostaB", typeof(string));
respostas.Columns.Add("respostaC", typeof(string));
respostas.Columns.Add("respostaD", typeof(string));
DataRow linha = respostas.NewRow();
linha["respostaA"] = reader["respostaA"].ToString();
linha["respostaB"] = reader["respostaB"].ToString();
respostas.Rows.Add(linha);


dr["respostas"] = respostas;

dt.Rows.Add(dr);

我也试过: ASP:

<ItemTemplate>
    <%#Eval("respostas")%>
</ItemTemplate>

C#:

RadioButtonList respostas = new RadioButtonList();
respostas.ID = "respostas_" + numero_respota;
respostas.Items.Add(new ListItem(reader["respostaA"].ToString(), "a"));
respostas.Items.Add(new ListItem(reader["respostaB"].ToString(), "b"));
respostas.Items.Add(new ListItem(reader["respostaC"].ToString(), "c"));
respostas.Items.Add(new ListItem(reader["respostaD"].ToString(), "d"));

他们都没有工作,有什么建议吗?

4

1 回答 1

0

经过一些测试,这里是解决方案:

ASP:

<ItemTemplate>
    <asp:RadioButtonList runat="server" DataSource=<%#Eval("respostas")%>></asp:RadioButtonList>
</ItemTemplate>

在 C# 中:

List<string> l = new List<string>();
l.Add(reader["respostaA"].ToString());
l.Add(reader["respostaB"].ToString());

dr["respostas"] = l;
于 2013-06-30T16:43:33.047 回答