如何从包含 UserControls 的 Repeater 中获取所有 TextBox 值?
我在 UserControl
中有一个 TextBox
,并且此 UserControl
在 Repeater
内重复。 但是,当用户用值填充 TextBox
后,我无法从 TextBox
中获取值。
default.aspx:
protected void Page_Load(object sender, EventArgs e)
{
//filling repeater with dataset
Repeater1.DataSource = ds;
Repeater1.DataBind();
}
中的值填充 List
protected void Button1_Click(object sender, EventArgs e)
{
List<string> sss = new List<string>();
foreach (Control i in Repeater1.Controls)
{
foreach (Control item in i.Controls)
{
if (item is WebUserControl1)
sss.Add(((WebUserControl1)item).getString);
}
}
}
在 button1
单击时,我尝试使用 textbox.text
和 UserControl 代码:
public string getString
{
get
{ return TextBox1.Text; }
}
protected void Page_Load(object sender, EventArgs e)
{
}
I have one TextBox
inside a UserControl
, and this UserControl
is repeating inside Repeater
.
But, when user fills TextBox
with values and after that I can't get values from TextBox
s.
default.aspx:
protected void Page_Load(object sender, EventArgs e)
{
//filling repeater with dataset
Repeater1.DataSource = ds;
Repeater1.DataBind();
}
On button1
click I'm trying to fill List<string>
with values from textbox.text
s
protected void Button1_Click(object sender, EventArgs e)
{
List<string> sss = new List<string>();
foreach (Control i in Repeater1.Controls)
{
foreach (Control item in i.Controls)
{
if (item is WebUserControl1)
sss.Add(((WebUserControl1)item).getString);
}
}
}
And UserControl
code:
public string getString
{
get
{ return TextBox1.Text; }
}
protected void Page_Load(object sender, EventArgs e)
{
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您应该循环所有中继器的项目并使用
FindControl
查找您的用户控件,然后在找到的实例上调用getString
方法,伪代码 (未测试):you should loop on all repeater's items and use
FindControl
to find your user control then call thegetString
method on such found instances, pseudo-code (not tested):