【问题标题】:Generating an aspx <div> content from C# code behind从后面的 C# 代码生成 aspx <div> 内容
【发布时间】:2015-06-12 14:56:11
【问题描述】:

我正在 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>

我需要建立一个检查清单,将上面的代码重复 67 次!

如何从后面的 C# 代码创建完整的 div id="Q1" 内容?,例如:

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

希望你能帮助我,在此先感谢!

【问题讨论】:

    标签: c# html asp.net c#-4.0 code-behind


    【解决方案1】:

    所以你想重复以下 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>
    

    简单。将其放入 UserControl 并将其 67 个实例添加到面板中。

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

    【讨论】:

    • 完美运行!谢谢!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-08-18
    • 1970-01-01
    • 2020-07-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多