从gridview中动态生成的文本框中访问值. [英] Access value from dynamically generated textboxes in the gridview.

查看:59
本文介绍了从gridview中动态生成的文本框中访问值.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用设计时创建的2个模板字段创建了一个gridview.我想在运行时动态生成更多模板字段(gridview列),因为没有.网格视图中的列数每次都在变化.我还需要在每个模板字段中都有一个文本框.

在使用ITemplete生成这些模板字段以及文本框之前,我已经做完了,我还可以在RowDataBound事件中获取这些文本框.然后,我允许用户更新文本框中的值.但是,当我尝试在gridview外部的Submit按钮的click事件上获取这些文本框值时,我找不到这些新生成的列,因此也找不到这些文本框.


谁能帮我找到解决方案,以便我可以在提交按钮的单击事件中获取文本框值.

谢谢.

解决方案

您需要做的是,您需要在回发时(单击提交按钮)再次使用文本框重新创建模板列.您将获得模板列以及文本框的值

由于视图状态,它将保留其值.只是需要确保在初始页面加载时为模板列和文本框创建的ID在回发后应该相同.


我认为在IsPostback()中,您已经编写了在这些列中添加模板列和文本框的代码.


I have created a gridview with 2 template fields created at design time. I want to generate more template fields(gridview columns) dynamically at runtime,because no. of columns in the gridview is varying every time.I also need to have a textbox inside every template field.

I have done up till generating these template fields along with the textboxes using ITemplete and I can also get these textboxes at the RowDataBound event. Then I am allowing the user to update the values in the textboxes. But when I try to get these textbox values on click event of the submit button which is outside the gridview, I can''t find those newly generated columns and hence neither the textboxes.


Can anyone please help me to find out the solution to this so that I can get the textbox values on submit button''s click event.

Thanks.

解决方案

What you have to do is, you need to recreate the template columns with textboxes again on postback (on click of submit button), then and then only you will get your template column as well as the value of textboxes


It will retain its value due to view-state. Just you need to make sure that the id which you have created for template columns and textboxes at initial page load, should be same after postback.


I think in IsPostback(), you had written the code of adding template columns and textboxes in those columns.


这篇关于从gridview中动态生成的文本框中访问值.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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