我正在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
}
我希望你能帮助我,提前致谢!
答案 0 :(得分: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);
}