Cannot fetch value when dynamically bound DropDownList update in asp.net gridview

Source: Internet
Author: User

Each row of data in the GridView has a selection, which displays only values in its normal state, and after clicking on the edited button, the status is switched to a drop-down box for the user to modify.
Now these are all in good condition, including clicking on the edit to automatically select the current item, using the Onrowcreated method, creating a data table will generate binding events, including when the click Edit.
Now the question is coming.
Because there is only one DropDownList control tag in the ASPX page, the data is provided by the. CS, which means that the data is bound dynamically when the Drop-down control is bound. The problem with this is that when you click the "Update" button, you can't get the value of the Drop-down control, and if the selection is written to die on the page, you can take it.
Now, how do you solve the dynamic binding of data and the value of this dynamically bound Drop-down when you click update?

Workaround:

dropdownlist dl = (DropDownList) gridview1.items[i]. FindControl ("DL1");
                    for (int f = 0; f < dl. Items.Count; f++)
                    {
   & nbsp                    if (DL. ITEMS[F]. Selected)
                        {
                          & nbsp Label1.Text + = dl. ITEMS[F]. Text;
                        }
                    }

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.