从动态控制中检索数据 [英] Retrive Data From Dynemic Control

查看:80
本文介绍了从动态控制中检索数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在一个按钮上单击一个面板可显示具有5个或更多textBox(TextBox是由for循环根据不受查询影响的行数而创建的)和一个按钮的显示.
只是
我想要的是,当我单击面板按钮时,textBox的值将存储在以``,''分隔的字符串中.

我是这样做的,但是文本框在roundTrip上失去了价值.
我无法处理此问题,所以请帮助我...
拜拜.

Over a button Click a panel get display with 5 or more textBox (TextBox is created by for loop according to no of row affected by query.) and one button.
Just
I want''s that when i click over panel button then the value of textBox get Stored inside a string seperated by '',''.

I did that but The textboxes are lossing there value at roundTrip.
I am not able to handle this so plz help me...
Byyy.

protected void ButtoncreateTextBox_Click(object sender, EventArgs e)
   {
       for (int i = 0; i < 5; i++)
       {
           TextBox t = new TextBox();
           t.ID = "TextBox" + i.ToString();
           Panel1.Controls.Add(t);
       }

   }


我必须通过其他按钮单击来从这些文本框(添加在面板中)中检索数据.


I have to retrive data form these text box(added in panel) over other button click.

推荐答案

添加动态控件时,您必须注意它们的状态,默认情况下不会保持状态.检索回发时动态控件的值的最简单方法是使用Request.Form[NameOfTheControl].另一种方法是编写自定义控件并自己处理视图状态.

您还可以查看以下CP文章.
在ASP.NET应用程序中为动态创建的控件保留状态 [ http://www.4guysfromrolla.com/articles/092904-1.aspx [ ^ ]
When you add dynamic control then you have to take care of their state, by default the state is not maintained. Simplest way to retrieve the value of the dynamic control on post back is to use Request.Form["NameOfTheControl"]. The other way is to write your custom control and handle the view state by yourself.

You can also check following CP article.
Retaining State for Dynamically Created Controls in ASP.NET applications[^]



Once you are able retrieve the values at server side its a simple task to make them comma separated.



Found one more useful article.

http://www.4guysfromrolla.com/articles/092904-1.aspx[^]


roundTrip最好为页面加载设置PostBack属性,然后尝试....
So at roundTrip u better set for PostBack property for the Page Load and try it....


这篇关于从动态控制中检索数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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