Div标签上的动态无线电盒生成

时间:2016-04-29 06:15:28

标签: c# asp.net dynamic-controls

我有一个要求,我需要以特定的html顺序生成动态控件 我尝试了许多选项,例如通过div.controls.add(radioButton)向div标签添加控件,并添加htmldiv.InnerHtml(),但从未在我想要的页面上呈现控件。

只有这种结构对我有帮助,但这种方法有一些缺点,我想避免这种情况。请查看下面的代码并建议我是否可以提出更方便的其他内容。

foreach (var pair in dictionary) {
    if (pair.Value.Count > 0) {
        divDay = divDay + "<tr>";
        divDay = divDay + "<td>";
        divDay = divDay + pair.Key.DayOfWeek.ToString() + " " + pair.Key.Date.ToString("MMMM");
        divDay = divDay + "</td>";

        divDay = divDay + "<td>";
        appointment_days.InnerHtml = divDay;
        foreach (Appointment appointment in pair.Value) {
            string radioButtonHtml = string.Format("<input type=\"radio\" id=\"{0}\" runat=\"server\">{1}</input>",
                appointment.AppointmentCode.ToString() + "_" + appointment.AppointmentStart.Value.ToShortDateString() + "_" + appointment.AppointmentEnd.Value.ToShortDateString(),
                appointment.AppointmentStart.Value.TimeOfDay.ToString() + "-" + appointment.AppointmentEnd.Value.TimeOfDay.ToString()
            );

            divDay = divDay + radioButtonHtml;
        }
        divDay = divDay + "</td>";
        divDay = divDay + "</tr>";
    }
}
divDay = divDay + "</table>";
appointment_days.InnerHtml = divDay;

0 个答案:

没有答案