动态文本框

发布于 2024-10-10 12:45:45 字数 559 浏览 8 评论 0原文

我有一个网格视图 - GridView1。
我通过代码动态地将行添加到此 Gridview1。
其中一列是从 sqldatasource 读取的下拉列表。
文本框、下拉列表和sql数据源都是数组。
如果我更改下拉列表的值,即使在任何按钮单击事件上重新加载页面后,它也会保持其状态。 这没关系。 但是,文本框的值不会被维护。
假设我在文本框中输入“Hello World”单击“添加”按钮,我想收集下拉列表中的文本值(我可以阅读)&文本框中的值(返回空白。) 请建议一种方法,以便在单击添加按钮时我可以检索我在文本框中输入的值。 每个文本框都有一个唯一的 id 和我尝试使用 ID 来获取其值
例如
protected Sub Add_Click(ByVal sender As Object, ByVal e As System.EventArgs) 处理 add.click
{
Dim valueinText = gettext(1).text }
现在,如果我在文本框中输入“Hello World”: gettext(1),
结果: valueinText = ""

提前致谢

I have a gridview - GridView1.
I am adding rows to this Gridview1 dyanamically through code.
One of the columns is a dropdownlist that reads from a sqldatasource.
The textboxes, dropdownlists & sql datasources are all arrays.
If I change the value of the dropdownlist, it maintains its state even after the page reloads on any button click event.
This is ok.
However, the values of the textboxes are not maintained.
Say I enter "Hello World" in the textbox & click "Add" button, I want to collect the text value in dropdownlist(which I can read) & the value in textbox(which returns blank.)
Please suggest a method so that on add button click I can retrive the value I had typed in the textbox.
Each textbox has a unique id & I tried using the ID to get its value
eg
protected Sub Add_Click(ByVal sender As Object, ByVal e As System.EventArgs) handles add.click
{
Dim valueinText = gettext(1).text
}
now if I type "Hello World" in textbox: gettext(1),
Reults:
valueinText = ""

Thanks in advance

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

汐鸠 2024-10-17 12:45:45

您必须重置未绑定文本框的值,这些文本框在您回发时从代码中获取其值。在您的页面加载事件中...

If Page.IsPostback Then

   'Code that uses dropdownlistAtoZ.SelectedValue
   'to fill in correct value for Textboxes.

End If

You will have to reset the values for unbound textboxes that get their value from code when you post back. In your Page Load Event...

If Page.IsPostback Then

   'Code that uses dropdownlistAtoZ.SelectedValue
   'to fill in correct value for Textboxes.

End If
深居我梦 2024-10-17 12:45:45

我试图在每个 page_load 事件上创建相同的文本框。但这只是抹去了他们的价值观和价值观。他们的 client_ID 不断变化。

相反,我尝试使所有文本框共享,并仅在添加单击事件时创建它们一次,将它们添加到行(再次共享),并且在 page_load 上,如果 page.postback = true,我刚刚再次将行添加到表中。如果不这样做,重新加载时将不会显示该行。

这解决了我的问题(现在在文本框中输入的值没有像以前一样被清除)。
我通过 classname.textboxname(i).text 访问该值。

现在解决方案似乎很明显,但我花了几天时间试图解决这个问题。

谢谢!

I was trying to create the same textboxes on every page_load event. But this just erased their values & their client_ID kept changing.

Instead, I tried making all textboxes Shared and created them only once on add click event, added them to a Row (which is again shared) and on page_load if page.postback = true I just added the row to the table again. If you don't do so, the row will not be shown on reload.

This solved my problem(now the values entered in Textbox were not cleared like before).
I accessed the value by classname.textboxname(i).text.

Now the solution seems obvious, but I spent a few days trying to solve this.

Thanks!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文