从列表视图中的文本框中获取值
问题描述:
我在listview中创建动态texbox,现在想在数据库中保存文本框值,这样我该怎么做?或者用于创建动态texbox并从中获取值的任何其他解决方案?
谢谢!
i am creating dynamic texboxes in listview and now want to save textboxes values in database so how can i do this? or any other solution for create dynamic texboxes and get values from these?
Thanks!
答
这里需要更多细节来解释解决方案,我仍然按照我的理解尽我所能。希望这对你有所帮助。
我假设你有一个ListView的每一行按钮,这样你就可以保存它的值,所以同一行项目也包含文本框本身。
首先我们必须得到按钮的容器(假设id是'btnSave')。
点击事件处理程序执行以下操作: -
It seems more details needed here to explain the solution, still i am trying my best as per my understanding. Hope this will be of help for you.
I am assuming that you have a button for each row of ListView so that you will be able to save the value for it, so the same row item also contains the textbox itself.
First of all we have to get the container for the button(Let say id is 'btnSave').
On click event handler do this like :-
Button btnSave = sender as Button;
然后获取容器就像; -
Then get the container for it like ;-
ListViewDataItem container = btnSave.NamingContainer as ListViewDataItem;
现在从这个容器中找到你想要的文本框,如下所示: -
Now find the textbox you want from this container as below ;-
TextBox txtName = container.FindControl("txtName") as TextBox;
然后只需'txtName.Text'即可获得所需的价值。
如果这对您有用,请告诉我,或者您需要更多帮助?
Then simply 'txtName.Text' will give you the desired value you want.
Please let me know if this worked for you or not, or you need any more help on this ?