简体   繁体   English

C#中标签附近的动态文本框

[英]dynamic textbox near label in C#

Sorry for reposting this but I haven't figure out how to do it. 很抱歉重新发布此信息,但我还没有弄清楚该怎么做。

string str = string.Empty;

 foreach (ListItem item in this.CheckBoxList1.Items)
    {
       if (item.Selected)
           {
              str += item.Value + "<br><br>";
              TextBox txt1 = new TextBox();
              form1.Controls.Add(txt1);

           }
    }

 lbl1.Text = str;

This brings up a textbox each time I check a value but I want to bring the textbox near each selected value that I retain in the label. 每次我检查一个值时都会弹出一个文本框,但是我想将文本框放在我保留在标签中的每个选定值附近。 So value1 textbox1, value2 textbox2....It's asp.net web application. 因此,value1 textbox1,value2 textbox2 ....这是asp.net Web应用程序。

Why do you want to use the same label? 为什么要使用相同的标签?

U could do: 你可以做:

foreach (ListItem item in this.CheckBoxList1.Items)
{
   if (item.Selected)
       {
          Label label = new Label();
          label.Text = item.Value;
          TextBox txt1 = new TextBox();

          form1.Controls.Add(label);
          form1.Controls.Add(txt1);

       }
}

you also might have to assign id to the textboxes if you are planning to retrieve user input from them. 如果您打算从文本框中检索用户输入,则可能还必须为这些文本框分配ID。

But if you only have limited number of fields u could use static fields, and change its visibility as Tim stated 但是,如果您只有有限数量的字段,那么您可以使用静态字段,并按Tim所述更改其可见性

我真的不知道您打算做什么,但是为什么不使用相同的y坐标但交替使用x坐标为label对象和textbox对象定义CSS类。

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

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