getting the value for the dynamically generated textbox

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • mylog
    New Member
    • Sep 2007
    • 20

    getting the value for the dynamically generated textbox

    Hi all,

    I am having a small problem on getting the values of the dynamically generated textboxes in C# windows application. I have successfully read an xml file and put its key and value fields as Label and TextBox respectively. Now what I need is the user changes the values in one of the textBox and I need to get that value. The problem is I cannot get the values from the textbox i.e. I don't know how to get the particular textbox value. Can anyone help me?

    Thanks in advance.


    This is how I made the Label and TextBox dynamically

    Label label = new Label();
    label.Name = "lbl" + lblID;
    label.Text = str2;
    label.Visible = true;
    label.SetBounds (5, y, 125, 20);
    viewPanel.Contr ols.Add(label);
    viewPanel.Visib le = true;
    lblID++;

    txtBox = new TextBox();
    txtBox.Name = "txtBox" + txtBoxID;
    txtBox.Text = str2;
    txtBox.Visible = true;
    txtBox.SetBound s(140, y, 300, 20);
    viewPanel.Contr ols.Add(txtBox) ;
    viewPanel.Visib le = true;
    txtBoxID++;


    now how can i get the values out from each of the textboxes?
  • yogesha
    New Member
    • Feb 2008
    • 5

    #2
    Hi,
    you can try this one.
    you can iterate trhough all the textbox controls and u can access alle text content of those textboxes...

    IEnumerator enumerator = this.Controls.G etEnumerator();
    while (enumerator.Mov eNext())
    {
    Control control = enumerator.Curr ent as Control;
    if (control is TextBox)
    {
    String text = control.Text;
    // thus you will get the text of text boxes
    }
    }

    Hope this will help you



    Originally posted by mylog
    Hi all,

    I am having a small problem on getting the values of the dynamically generated textboxes in C# windows application. I have successfully read an xml file and put its key and value fields as Label and TextBox respectively. Now what I need is the user changes the values in one of the textBox and I need to get that value. The problem is I cannot get the values from the textbox i.e. I don't know how to get the particular textbox value. Can anyone help me?

    Thanks in advance.


    This is how I made the Label and TextBox dynamically

    Label label = new Label();
    label.Name = "lbl" + lblID;
    label.Text = str2;
    label.Visible = true;
    label.SetBounds (5, y, 125, 20);
    viewPanel.Contr ols.Add(label);
    viewPanel.Visib le = true;
    lblID++;

    txtBox = new TextBox();
    txtBox.Name = "txtBox" + txtBoxID;
    txtBox.Text = str2;
    txtBox.Visible = true;
    txtBox.SetBound s(140, y, 300, 20);
    viewPanel.Contr ols.Add(txtBox) ;
    viewPanel.Visib le = true;
    txtBoxID++;


    now how can i get the values out from each of the textboxes?

    Comment

    • mylog
      New Member
      • Sep 2007
      • 20

      #3
      Thank u very much for your suggestion . It worked perfectly for me.

      Comment

      Working...