我有2个中继器,第一个列出问题,第二个列出该特定问题的多个选择。 但是,有一些多项选择(输入类型="无线电")或文本(输入类型="文本")anwers。我试图得到一个(无线电)或另一个(文本)的价值。
<%#DataBinder.Eval(Container.DataItem," Descricao")%>
<%-- Listagem de Respostas --%>
<asp:Repeater ID="uxRespList" runat="server" OnItemDataBound="uxRespList_ItemDataBound" OnItemCommand="uxRespList_ItemCommand">
<ItemTemplate>
<tr>
<td>
<div id="uxRespostaText" visible="false" runat="server">
<input type="text" id="uxRespostaDissertativa" placeholder="Resposta" style="width:1000px" ></input>
</div>
<div id="uxRespostaRadio" visible="false" runat="server">
<input type="radio" id="uxResposta" runat="server" value='<%# DataBinder.Eval(Container.DataItem, "Descricao")%>'/><%# DataBinder.Eval(Container.DataItem, "Descricao")%>
</div>
</td>
</tr>
</ItemTemplate>
</asp:Repeater>
</ItemTemplate>
</asp:Repeater>
背后的代码
protected void uxQuestList_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
Repeater rptRespostas = (Repeater)(e.Item.FindControl("uxRespList"));
QuestionarioPergunta pergunta = (QuestionarioPergunta)e.Item.DataItem;
rptRespostas.DataSource = ctx.QuestionarioRespostas.Where(x => x.PergId == pergunta.Id).ToList();
PergId.Text = pergunta.Id.ToString();
rptRespostas.DataBind();
}
}
protected void uxRespList_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
System.Web.UI.HtmlControls.HtmlContainerControl uxRespostaText = (System.Web.UI.HtmlControls.HtmlContainerControl)e.Item.FindControl("uxRespostaText");
System.Web.UI.HtmlControls.HtmlContainerControl uxRespostaRadio = (System.Web.UI.HtmlControls.HtmlContainerControl)e.Item.FindControl("uxRespostaRadio");
int PerguntaID = Int32.Parse(PergId.Text);
var pergunta = ctx.QuestionarioPerguntas.Where(x => x.Id == PerguntaID).FirstOrDefault();
if (pergunta.TipoPergunta == "Dissertativa")
{
uxRespostaText.Visible = true;
}
else
{
uxRespostaRadio.Visible = true;
}
}
}
//Save here
protected void uxSalvarPesquisa_Click(object sender, EventArgs e)
{
foreach (RepeaterItem item in uxRespList.Items)
{
}
}
答案 0 :(得分:0)
您可以按照以下方式获取html输入的值,并根据您的要求修改代码。
foreach (RepeaterItem item in uxQuestList.Items)
{
Repeater uxRespList = (Repeater)item.FindControl("uxRespList");
foreach (RepeaterItem inneritem in uxRespList.Items)
{
HtmlInputText input = (HtmlInputText)inneritem.FindControl("uxRespostaDissertativa");
if (input.Attributes["visible"] == "true")
{
var answer = input.Value;
}
HtmlInputRadioButton inputRadio = (HtmlInputRadioButton)inneritem.FindControl("uxRespostaRadio");
if (inputRadio.Attributes["visible"] == "true")
{
var answer = inputRadio.Value;
}
}
}