简体   繁体   English

生成aspx <div> C#代码后面的内容

[英]Generating an aspx <div> content from C# code behind

I'm developing an ASPX web page on Visual Studio 2013 and I have the follow code: 我正在Visual Studio 2013上开发ASPX网页,并且具有以下代码:

<div id="Q1" style="width: 100%; text-align:justify">
    <div style="float: left; width: 70%; align-items: center; background-color:rgba(99, 99, 99, 0.40); padding-top: 5px;padding-left: 5px;padding-bottom: 5px;padding-right: 5px;">
        <asp:Label ID="LabelM12" runat="server"></asp:Label>
    </div>
    <div style="float: left; width: 25%; text-align:center; align-items:center">
        <asp:RadioButtonList ID="RadioButtonListM12" runat="server" RepeatDirection="Horizontal" RepeatLayout="Table" onclick="ShowTxt('1');">
        <asp:ListItem Text = "Yes" Value = "Yes"></asp:ListItem>
        <asp:ListItem Text = "No" Value = "No"></asp:ListItem>
        <asp:ListItem Text = "NA" Value = "NA"></asp:ListItem>
    </asp:RadioButtonList>
    </div>
</div>

I need to build a check list repeating the code above 67 times! 我需要建立一个清单,重复67次以上的代码!

How can I create the complete div id="Q1" content from C# code behind?, something like: 如何从后面的C#代码创建完整的div id =“ Q1”内容?

for(int i = 0; i < 67; i++)
{
     //Code to generate the div id="Q1" content
}

I hope you can help me, Thanks in advance! 希望您能帮到我,谢谢!

So you want to repeat following 67 times: 因此,您想重复以下67次:

<div style="width: 100%; text-align:justify">
    <div style="float: left; width: 70%; align-items: center; background-color:rgba(99, 99, 99, 0.40); padding-top: 5px;padding-left: 5px;padding-bottom: 5px;padding-right: 5px;">
        <asp:Label ID="LabelM12" runat="server"></asp:Label>
    </div>
    <div style="float: left; width: 25%; text-align:center; align-items:center">
        <asp:RadioButtonList ID="RadioButtonListM12" runat="server" RepeatDirection="Horizontal" RepeatLayout="Table" onclick="ShowTxt('1');">
        <asp:ListItem Text = "Yes" Value = "Yes"></asp:ListItem>
        <asp:ListItem Text = "No" Value = "No"></asp:ListItem>
        <asp:ListItem Text = "NA" Value = "NA"></asp:ListItem>
    </asp:RadioButtonList>
    </div>
</div>

Simple. 简单。 Put it in a UserControl and add 67 instances of it to a panel. 将其放在UserControl ,并将其67个实例添加到面板中。

for(int i = 0; i < 67; i++)
{
    MyRadioButtonListControl c = (MyRadioButtonListControl)LoadControl("MyRadioButtonListControl.ascx");
    myPanel.Controls.Add(c);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM