在Repeater中的FindControl [英] FindControl in Repeater

查看:68
本文介绍了在Repeater中的FindControl的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在转发器控件中动态创建控件(文本框)。我知道

他们的名字(例如TextBox1)。如何在表单中找到TextBox1的文本?

FindControl似乎不起作用。

I dynamically create controls (textboxes) in a repeater control. I know
their names (eg. TextBox1). How do I find the text of TextBox1 in the Form?
FindControl does not seem to work.

推荐答案

对不起,控件是动态创建的,并放置在PlaceHolder

控件中。是否需要某种方法才能找到控制权?

< msnews.microsoft.com写信息

新闻:OG ******** ****** @ TK2MSFTNGP06.phx.gbl ...
Sorry, the controls are dynamically created and placed in a PlaceHolder
control. Does there have to be some sort of looipng to find the control?
<msnews.microsoft.comwrote in message
news:OG**************@TK2MSFTNGP06.phx.gbl...

>我在转发器控件中动态创建控件(文本框)。我知道他们的名字(例如TextBox1)。如何在
表单中找到TextBox1的文本? FindControl似乎不起作用。
>I dynamically create controls (textboxes) in a repeater control. I know
their names (eg. TextBox1). How do I find the text of TextBox1 in the
Form? FindControl does not seem to work.



有一种更好的方法可以做到这一点,但这里有一个老的例子>
我可以玩的代码。不确定这是否确实是你想要的,但是我发现

框架中的FindControl功能最多也是如此,所以我抛出任何动态控件我进入了

a集合,在本例中是一个ArrayList。适用于我正在做的事情,

希望它指向正确的方向:

//创建一个ArrayList来保存所有动态控件。

ArrayList controls = new ArrayList();


//让我们制作一些文本框。

int i = 0;

while(i< = 10)

{

TextBox tb = new TextBox();

tb.ID = i。 ToString();


/ *在这里做任何你想要控制到页面的内容,



*

*

* /

//将TextBox添加到数组列表中。

controls.Add(tb );

}


//现在只是为了测量我们是否依赖于通过PostBacks保存和保存

数据,等等
会话[" Controls"] =(ArrayList)控件;

//现在稍后如果我们想从这些文本中获取数据

box

ArrayList controls2 =(ArrayList)Session [" Controls"];


/ /制作循环以查看我们所拥有的内容并向他们推荐。

foreach(控制cOUT in controls2)

{

TextBox txtOUT =(TextBox)cOUT;


//用txtOUT.Text获取数据;


}

Lucid

Phreak2000.Com

管理员


< msnews.microsoft.com写信息

新闻:Os **************** @ TK2MSFTNGP05.phx.gbl ...
There is a better way of doing this, but here is an example from some old
code of mine that you can play with. Not sure if this is EXACTLY what you
are looking for, but i''ve found that the FindControl ability in the
framework is spotty at best so I throw whatever dynamic controls I make into
a collection, in this case an ArrayList. Works well for what I was doing,
hopefully it points you in the right direction:
//Make an ArrayList to hold all of the dynamic controls.
ArrayList controls = new ArrayList();

//Lets make some text boxes.
int i = 0;
while (i <= 10)
{
TextBox tb = new TextBox();
tb.ID = i.ToString();

/*Do here whatever you will to render the control to the page,
etc.
*
*
*/
//Add the TextBox to your array List.
controls.Add(tb);
}

//Now just for measure if we are dependent on keeping and saving
that data through PostBacks, etc.
Session["Controls"] = (ArrayList)controls;
//Now at a later time if we want to get the data from those text
boxes
ArrayList controls2 = (ArrayList)Session["Controls"];

//Make a loop to see what we have and make a referrence to them.
foreach (Control cOUT in controls2)
{
TextBox txtOUT = (TextBox)cOUT;

//Get the data however you with such as txtOUT.Text;

}
Lucid
Phreak2000.Com
Administrator

<msnews.microsoft.comwrote in message
news:Os****************@TK2MSFTNGP05.phx.gbl...

对不起,控件是动态创建的,并放置在PlaceHolder

控件中。是否需要某种方法才能找到控制权?


< msnews.microsoft.com写信息

新闻:OG **** ********** @ TK2MSFTNGP06.phx.gbl ...
Sorry, the controls are dynamically created and placed in a PlaceHolder
control. Does there have to be some sort of looipng to find the control?
<msnews.microsoft.comwrote in message
news:OG**************@TK2MSFTNGP06.phx.gbl...

>>我在转发器控件中动态创建控件(文本框) 。我知道他们的名字(例如TextBox1)。如何在
表单中找到TextBox1的文本? FindControl似乎不起作用。
>>I dynamically create controls (textboxes) in a repeater control. I know
their names (eg. TextBox1). How do I find the text of TextBox1 in the
Form? FindControl does not seem to work.



FindControl不会递归搜索。


你需要做RepeaterControl.FindControl(" textbox1")而不是

Page.FindControl(" textbox1")。


-

Madhur


< msnews.microsoft.com写信息

新闻:Os ********** ****** @ TK2MSFTNGP05.phx.gbl ...
FindControl does not search recursively.

You need to do RepeaterControl.FindControl("textbox1") instead of
Page.FindControl ("textbox1").

--
Madhur

<msnews.microsoft.comwrote in message
news:Os****************@TK2MSFTNGP05.phx.gbl...

抱歉,控件是动态创建并放置在PlaceHolder中

控制。是否需要某种方法才能找到控制权?


< msnews.microsoft.com写信息

新闻:OG **** ********** @ TK2MSFTNGP06.phx.gbl ...
Sorry, the controls are dynamically created and placed in a PlaceHolder
control. Does there have to be some sort of looipng to find the control?
<msnews.microsoft.comwrote in message
news:OG**************@TK2MSFTNGP06.phx.gbl...

>>我在转发器控件中动态创建控件(文本框) 。我知道他们的名字(例如TextBox1)。如何在
表单中找到TextBox1的文本? FindControl似乎不起作用。
>>I dynamically create controls (textboxes) in a repeater control. I know
their names (eg. TextBox1). How do I find the text of TextBox1 in the
Form? FindControl does not seem to work.



这篇关于在Repeater中的FindControl的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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