【发布时间】:2017-06-02 16:25:53
【问题描述】:
到目前为止,我已经在 C# 中通过此函数动态创建了标签和文本框
private void AddControls(int controlNumber, string label)
{
var newLabel = new Label()
{
Text = "(" + label + ")"
};
var title = new Label()
{
Text = "External Name",
};
var newTextbox = new TextBox()
{
Width = 306,
MaxLength = 10
};
// textbox needs a unique id to maintain state information
newTextbox.ID = "TextBox_" + controlNumber;
// add the labels and textbox to form
Name.Controls.Add(title);
Name.Controls.Add(newTextbox);
Name.Controls.Add(newLabel);
Name.Controls.Add(new LiteralControl("<br/>"));
}
动态部分工作正常,除了我希望标题和 newTextBox 与下面的 newLabel 并排。此外,Name 是唯一可以添加标签和文本框的 id。似乎无法弄清楚如何在 C# 而不是 HTML 中执行此操作。非常感谢任何帮助!
【问题讨论】: