从控件构建动态Web列表 [英] building dynamic list of web from controls

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

问题描述

有没有办法在运行时动态生成说文本框控件列表

时间,基于数据库中出现的值可能会有所不同

代码运行的时间。在传统的asp中你可以运行一个循环来做这样的事情。我知道你可以使用类似

Form1.Controls.Add(TextBox1)的东西在运行时动态添加文本框但是你还需要声明每个单独的文本框控件据我所知..

这不实用,因为我不知道在运行

页面之前我需要多少。

-

Scott

Is there a way to generate a list of say textbox controls dynamically at run
time, based on say a value coming out of a database which could vary each
time the code is run. In traditional asp you could just have run a loop to do
something like that. I am aware in you can use something like
Form1.Controls.Add(TextBox1) to add textboxes dynamically at run time but you
still need to declare each individual textbox control as far as I can tell..
This is not practial as I don''t know how many I will need before I run the
page.
--
Scott

推荐答案

dim x as integer = 10''从db

for i = 1到10

dim txt as new TextBox()

txt.Id = i.ToString()

Form1.Controls.Add(txt)

结束


Karl


-

我的ASP.Net教程
http:// www。 openmymind.net/ - 新增和改进(是的,弹出窗口是

烦人)
http://www.openmymind.net/faq.aspx - 非官方新闻组常见问题(更多的是

来了!)

" scottrm" < SC ***** @ newsgroup.nospam>在消息中写道

news:74 ********************************** @ microsof t.com ...
dim x as integer = 10 ''pull this from db

for i = 1 to 10
dim txt as new TextBox()
txt.Id = i.ToString()
Form1.Controls.Add(txt)
end

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/ - New and Improved (yes, the popup is
annoying)
http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
come!)
"scottrm" <sc*****@newsgroup.nospam> wrote in message
news:74**********************************@microsof t.com...
有没有办法在
运行时动态生成所谓的文本框控件列表,基于数据库中出现的值,每个值可能会有所不同<运行代码的时间。在传统的asp中你可以运行循环到
做类似的事情。我知道你可以使用类似
Form1.Controls.Add(TextBox1)的东西在运行时动态添加文本框但是b $ b你还需要声明每个单独的文本框控件尽可能
告诉..这不实用,因为我不知道在运行
页面之前我需要多少。

-
Scott
Is there a way to generate a list of say textbox controls dynamically at run time, based on say a value coming out of a database which could vary each
time the code is run. In traditional asp you could just have run a loop to do something like that. I am aware in you can use something like
Form1.Controls.Add(TextBox1) to add textboxes dynamically at run time but you still need to declare each individual textbox control as far as I can tell.. This is not practial as I don''t know how many I will need before I run the
page.
--
Scott



也许您可以将TextBox控件添加到更高级别的父级

控件,如Panel或甚至是Repeater。你不必在后面的代码中声明

每个TextBox控件作为类成员变量 -

你可以遍历容器中的控件并对其执行操作

他们。


有意义吗?


-

Scott
http://www.OdeToCode.com/blogs/scott/


星期一,2005年4月18日07:11:13 -0700,scottrm

< sc ***** @ newsgroup.nospam> ;写道:
Perhaps you could add the TextBox controls to a higher level parent
control, like a Panel or even a Repeater. You wouldn''t have to declare
each TextBox control in the code behind as a class member variable -
you could loop through the controls in the container and act upon
them.

Making sense?

--
Scott
http://www.OdeToCode.com/blogs/scott/

On Mon, 18 Apr 2005 07:11:13 -0700, "scottrm"
<sc*****@newsgroup.nospam> wrote:
有没有办法在运行时动态生成说文本框控件的列表,基于数据库中出现的值可能会有所不同<运行代码的时间。在传统的asp中你可以运行循环来做类似的事情。我知道你可以使用类似
Form1.Controls.Add(TextBox1)的东西在运行时动态添加文本框但是你仍然需要声明每个单独的文本框控件,据我所知。
这不实用,因为在我运行
页面之前我不知道需要多少。
Is there a way to generate a list of say textbox controls dynamically at run
time, based on say a value coming out of a database which could vary each
time the code is run. In traditional asp you could just have run a loop to do
something like that. I am aware in you can use something like
Form1.Controls.Add(TextBox1) to add textboxes dynamically at run time but you
still need to declare each individual textbox control as far as I can tell..
This is not practial as I don''t know how many I will need before I run the
page.






是的,这很容易。最大的问题是,在回发中,你需要重新创建控件。我刚刚发布了一个样本:

http://groups-beta.google.com/group/...717a97bd32c450


-Brock

DevelopMentor
http://staff.develop.com/ballen
Yep, it''s fairly easy. The big problem is that across postbacks it''s up to
you to recreate the controls. I just posted a sample earlier:

http://groups-beta.google.com/group/...717a97bd32c450

-Brock
DevelopMentor
http://staff.develop.com/ballen
有没有办法动态生成说文本框控件列表
在运行时,基于数据库中出现的值,每次运行代码时都会发生变化。在传统的asp中你可以运行一个循环来做类似的事情。我知道你可以使用
类似Form1.Controls.Add(TextBox1)的东西在运行时动态添加文本框但是你仍然需要声明每个单独的
文本框控件可以说..这不实用,因为我不知道在运行页面之前我需要多少。
Is there a way to generate a list of say textbox controls dynamically
at run time, based on say a value coming out of a database which could
vary each time the code is run. In traditional asp you could just have
run a loop to do something like that. I am aware in you can use
something like Form1.Controls.Add(TextBox1) to add textboxes
dynamically at run time but you still need to declare each individual
textbox control as far as I can tell.. This is not practial as I don''t
know how many I will need before I run the page.






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

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