简体   繁体   中英

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.

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". From there, you can do whatever else needs to be done.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM