首先,可以使用中继器和中继器吗?如果是的话,我将如何在下面的场景中使用嵌套中继器。
<div class="row">
<asp:Repeater ID="rp_Question" runat="server">
<ItemTemplate>
<p class="_100">
<h2 id="h4_Question" runat="server"><%# Eval("question_text") %></h2>
</p>
<p class="left">
<asp:RadioButtonList ID="rb_Question" runat="server">
<asp:ListItem Text="Option1" Value="1"></asp:ListItem>
<asp:ListItem Text="Option2" Value="2"></asp:ListItem>
<asp:ListItem Text="Option3" Value="3"></asp:ListItem>
<asp:ListItem Text="Option4" Value="4"></asp:ListItem>
</asp:RadioButtonList>
</p>
</ItemTemplate>
</asp:Repeater
中继器绑定
rp_Question.DataSource = _question.GetAll();
rp_Question.DataBind();
每个问题的选项都保存在数据库中,最小选项可以是3,最大选项可以是6。如何使用rp_Question中的其他中继器重复每个问题的选项。我想表现得像这样。
发布于 2016-11-14 13:15:40
扩展KateCute给出的答案,您可以使用ItemDataBound
事件。
<asp:Repeater ID="rp_Question" runat="server" OnItemDataBound="rp_Question_ItemDataBound">
然后在后面的代码中。
protected void rp_Question_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
//find the radiobuttonlist with findcontrol and cast back to it's original type
RadioButtonList rb_Question = e.Item.FindControl("rb_Question") as RadioButtonList;
//get the current datarow
DataRowView row = e.Item.DataItem as DataRowView;
//get the id from the datarow object
string questionID = row["question_id"].ToString();
//get the answers from the db with questionID and bind them as listitems just like in the loop below
//just a loop to add some listitems for demo
for (int i = 0; i < 5; i++)
{
rb_Question.Items.Insert(i, new ListItem("Option " + i.ToString(), i.ToString(), true));
}
}
发布于 2016-11-14 08:20:51
不幸的是,您不能在asp:RadioButtonList
中使用中继器。它只允许内部的ListItem
。您将得到一个错误,该中继器是一个未知的元素。但是您可以在后面的代码中绑定asp:RadioButtonList
。
https://stackoverflow.com/questions/40583778
复制相似问题