动态创建控件 [英] create control dynamically

查看:56
本文介绍了动态创建控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

任何人都可以告诉我如何通过单击按钮动态创建标签框,文本框。我想自定义Web表单中的一些字段(添加更多字段)。请告诉我一些做这个的想法?

can anyone please tell me how to dynamically create labelboxes,textboxes by clicking a button .i want to customize some of the fields in the web form(adding more fields).Suggest me some ideas of doing it?

推荐答案


任何人都可以告诉我如何通过单击按钮动态创建标签箱,文本框。我想自定义一些字段在网络表单中(添加更多字段)。请教我一些做这个的想法?
can anyone please tell me how to dynamically create labelboxes,textboxes by clicking a button .i want to customize some of the fields in the web form(adding more fields).Suggest me some ideas of doing it?



按钮点击事件你可以写:

System.Web.UI.WebControls.Label myLabel = new Label( );

myLabel.Text =" Sample Label";

Form1.Controls.Add(myLabel);


系统.Web.UI.WebControls.TextBox myTextBox = new TextBox();

myTextBox.ID =" TextBox1";

myTextBox.Text =" Hi" ;; < br $>
Form1.Controls.Add(myTextBox);


-Ankit

On button click event you can write:

System.Web.UI.WebControls.Label myLabel = new Label();
myLabel.Text = "Sample Label";
Form1.Controls.Add(myLabel);

System.Web.UI.WebControls.TextBox myTextBox = new TextBox();
myTextBox.ID = "TextBox1";
myTextBox.Text="Hi";
Form1.Controls.Add(myTextBox);

-Ankit


感谢Ankit的想法..但是问题是,当我点击按钮时,会出现一个文本框,询问文本框控件的数量。如果我给5,那么5个文本框; s应该出现要求标签&当我点击提交按钮时,


5标签盒带有给定的标签&相应的5个文本框; s将出现

那么我应该如何编码循环?为此。


请帮助...


Neena




Thanks Ankit for the idea..But the problem is,when i click the button,a textbox will appear asking for "number of textbox controls".so if i give 5,then 5 text box;s should appear asking for labels & when i click the button "submit",the

5 labelbox''s with the given labels & corresponding 5 textbox;s will appear
So how should i code the "loop" for this.

please help...

Neena





按钮点击事件你可以写:

System.Web.UI.WebControls.Label myLabel = new Label() ;

myLabel.Text =" Sample Label";

Form1.Controls.Add(myLabel);


系统。 Web.UI.WebControls.TextBox myTextBox = new TextBox();

myTextBox.ID =" TextBox1";

myTextBox.Text =" Hi";

Form1.Controls.Add(myTextBox);


-Ankit
On button click event you can write:

System.Web.UI.WebControls.Label myLabel = new Label();
myLabel.Text = "Sample Label";
Form1.Controls.Add(myLabel);

System.Web.UI.WebControls.TextBox myTextBox = new TextBox();
myTextBox.ID = "TextBox1";
myTextBox.Text="Hi";
Form1.Controls.Add(myTextBox);

-Ankit


hello <如果您使用C#然后使用foreach循环来控制,那么




如果再次发布任何问题,请先试试它我将发送示例代码


一切顺利
hello


if you are using C# then use foreach loop for controls


first try it if any problem post again i will send sample code


all the best


这篇关于动态创建控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆