[英]how to get textbox value inside a datalist?
如果我有一个带有文本框和一个按钮的数据列表,并且我想访问该文本框的值并将其传递给该按钮的侦听器,那么有人知道怎么做吗?
I know how. 我知道该怎样。
Let's say you have a DataList
name myDataList, and a TextBox
in it named by myTextBox. 假设您有一个
DataList
名称为myDataList,并在其中有一个由myTextBox命名的TextBox
。
foreach (DataListItem item in myDataList.Items)
{
TextBox myTextBox = (TextBox)item.FindControl("myTextBox");
string text = myTextBox.text;
// Do whatever you need with that string value here
}
This loops through all of the items in your DataList
and places the value of your TextBox
into a local string variable named "text". 这将遍历
DataList
所有项目,并将TextBox
的值放入名为“ text”的本地字符串变量中。 From there, you can do whatever else needs to be done. 从那里,您可以做任何其他需要做的事情。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.