locked
get value from dynamic entry RRS feed

  • Question

  • User394843 posted

    i have got dynamic entries on the page, with button possible to add new entries. But how can i get or send data from different row entries. sample like this.

    private void add_Clicked(System.Object sender, System.EventArgs e) {

            Entry debiEntry = new Entry();
            debi.Children.Add(debiEntry);
    
        }
    

    debi is stacklayout name. each clicked button means new entry and how can i give them x:name?

    Friday, February 26, 2021 8:26 PM

Answers

  • User371688 posted

    each clicked button means new entry and how can i give them x:name?

    In file xxPage.xaml,we can give a view x:Name, but if we define a view in xxPage.cs ,we can't give them x:Name.

    But we can create a new instance name for them, just as the varivale debiEntry for the new Entry that you posted above:

       Entry debiEntry = new Entry();
    

    And we can access the entry's text as follows:

            private void Button_Clicked(object sender, EventArgs e)
        {
            Entry debiEntry = new Entry { };
            debi.Children.Add(debiEntry);
    
            debiEntry.Text = "test string";
    
            System.Diagnostics.Debug.WriteLine("debiEntry's Text = " + debiEntry.Text);
        }
    

    And if you add many entries in your pages, you can access the value of these entries as follows:

             private void GetValueButton_Clicked(object sender, EventArgs e)
        {
            var views = debi.Children;
            foreach(var mView in views) {
                if(mView is Entry) {
                    Debug.WriteLine(" an entry Text = " + ((Entry)mView).Text);
                }
            }    
        }
    

    Xamarin forums are migrating to a new home on Microsoft Q&A! We invite you to post new questions in the Xamarin forums’ new home on Microsoft Q&A! For more information, please refer to this sticky post.

    • Marked as answer by Anonymous Thursday, June 3, 2021 12:00 AM
    Monday, March 1, 2021 4:41 AM