中继器中的Nestead控制

时间:2015-12-15 09:51:02

标签: c# asp.net .net

我有情况我在转发器中有中继器 radiobutton list具有静态值 我想要内部的另一个文本区域 现在,一旦我想将数据绑定到我的中继器上,我想要下去 显示单选按钮列表(静态)或文本区域 我现在一无所知

<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>

1 个答案:

答案 0 :(得分:0)

将它们放在各自的面板中,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;