我在中继器中有复读机,我有一个具有静态值的无线电按钮列表,现在我想要另一个文本区域,一旦我将数据绑定到我的中继器,条件是我想退出显示单选按钮列表(静态)或文本区域,我现在是毫无头绪的。
<asp:Repeater ID="rpt_Questions" runat="server"> <%--OnItemDataBound="rpt_Questions_ItemDataBound"--%>
<ItemTemplate>
<div><span class="presenter"><%# Eval("QuestionText") %></span></div>
<asp:Label ID="lblQID" Visible="false" runat="server" Text='<%# Eval("ItemID") %>' />
<div>
<ul class="clearfix">
<asp:RadioButtonList ID="rbtAnswers" runat="server" RepeatDirection="Horizontal">
<asp:ListItem>Not At all</asp:ListItem>
<asp:ListItem>Fine</asp:ListItem>
<asp:ListItem>Average</asp:ListItem>
<asp:ListItem>Good</asp:ListItem>
<asp:ListItem>Very Much</asp:ListItem>
</asp:RadioButtonList>
<asp:TextBox ID="txtDesc" runat="server" TextMode="MultiLine"/>
</ul>
</div>
</ItemTemplate>
</Repeater>发布于 2015-12-15 10:01:48
将它们放在自己的面板中,pnlRadio,pnlText:
<ul class="clearfix">
<asp:Panel id="pnlRadio" runat="server">
<asp:RadioButtonList ID="rbtAnswers" runat="server" RepeatDirection="Horizontal">
<asp:ListItem>Not At all</asp:ListItem>
<asp:ListItem>Fine</asp:ListItem>
<asp:ListItem>Average</asp:ListItem>
<asp:ListItem>Good</asp:ListItem>
<asp:ListItem>Very Much</asp:ListItem>
</asp:RadioButtonList>
</asp:Panel>
<asp:Panel id="pnlText" runat="server">
<asp:TextBox ID="txtDesc" runat="server" TextMode="MultiLine"/>
</ul>重新启用onItemDataBound,然后
protected void rpt_Questions_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
DataRowView drv = (DataRowView)e.Item.DataItem;
Panel pnlRadio = e.Item.FindControl("pnlRadio") as Panel;
Panel pnlText= e.Item.FindControl("pnlText") as Panel;
if(drv["questionType"].ToString()=="choice") //or however you distinguish between the two
{ pnlRadio.Visible = True; pnlText.Visible = False;}
else
{ pnlRadio.Visible = False; pnlText.Visible = True;https://stackoverflow.com/questions/34285892
复制相似问题