存储来自动态控制控件的值 [英] storing values from dynamic control controls

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

问题描述


我要在循环的帮助下动态创建一些文本框(约10个),并在循环的帮助下创建ID


现在我想在按钮的帮助下存储文本框的文本



我该怎么做

解决方案

Pradeep,

您可以通过使用字符串数组来实现.如果必须用完那些文本框中存储的值,则必须将数组声明为静态数组,并在page_load重新读取该数组.

如果您需要更多有关此内容,请分享您尝试过的内容.

希望这会有所帮助.

祝您编码愉快!


将您的函数置于页面加载事件中,以便每次加载该函数.

确保为每个文本框控件创建动态ID.

然后使用.findcontrol方法获取控件的对象,然后即可获取值.

假设面板控件内的文本框使用

字符串值= Panel1.FindControl("id").text.ToString();


我认为一些问题可以澄清您的问题:

1.到底"id:"文本框的"Name"属性的含义是什么?

2. TextBoxes中的文本将要更改:是吗?

3.当您说存储文本框的文本:"时,您的意思是:

    a.创建一个包含所有TextBoxes的 all 文本的字符串?我不愿意.

    b.然后,假设您要将每个 TextBox的文本存储在某个地方:

         1.那在哪里:文件,服务器上的内部数据结构或?

         2.哪种存储方式:List< string> :或?


...意识到我提出的解决方案对于这种简单的情况来说太复杂了...

List<TextBox> TBList = new List<TextBox>();
//
TextBox newTB;
//
// create TextBoxes: add each new instance to the List<TextBox>
/
for (int i = 0; i < 10; i++)
{
    newTB = new TextBox { 
        Name = "TB_" + i.ToString(), 
        Text = "some text for item " + i.ToString() };

    TBList.Add(newTB);
}
//
// then at any future time you can access the current Text in any TextBox by index:
string tb4TextByIndex = TBList[4].Text;

...结束编辑...

最好,比尔


hi
i m creating some text (around 10) boxes dynamically with the help of a loop and create the id with the help of loop


now i want to store the text of the text boxes with the help of a button click



how can i do that

解决方案

Hi Pradeep,

You an achieve this by using a string array. You must declare the array as static and re-read the array at page_load if in case you need to use up the values stored from those textboxes.

If you need more on that, share what you''ve tried yet.

Hope this helps.

Happy Coding !!


Put your function in page load event so every time it will loaded.

Make sure to create dynamic id for each text box control.

Then use .findcontrol method to get the object of the control and then you can get the value.

Suppose the textbox inside the panel control then use

string value = Panel1.FindControl("id").text.ToString();


A few questions I think will clarify your question:

1. exactly what do mean by "id:" the TextBox''s ''Name property ?

2. text in the TextBoxes is going to be changing: correct ?

3. when you say "store the text of the text boxes:" do you mean:

    a. to create a string containing all text of all the TextBoxes ? I''d assume not.

    b. then, assuming you want to store each TextBox''s text somewhere:

        1. where is that somewhere: a file, an internal data structure on the server, or ?

        2. what form of storage: a List<string> : or ?


... edit : realized the solution I presented was far too elaborate for this simple case ...

List<TextBox> TBList = new List<TextBox>();
//
TextBox newTB;
//
// create TextBoxes: add each new instance to the List<TextBox>
/
for (int i = 0; i < 10; i++)
{
    newTB = new TextBox { 
        Name = "TB_" + i.ToString(), 
        Text = "some text for item " + i.ToString() };

    TBList.Add(newTB);
}
//
// then at any future time you can access the current Text in any TextBox by index:
string tb4TextByIndex = TBList[4].Text;

... end edit ...

best, Bill


这篇关于存储来自动态控制控件的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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