WebForm Basic Control-----DropDownList

Source: Internet
Author: User

Fill in the contents:

Private voidfillnation () {DropDownList1.Items.Clear (); //Check Datalist<nation> list =_context.nation.tolist (); //send it in---loop .ListItem Temp=NewListItem ("= = Please select = =","-1");        DROPDOWNLIST1.ITEMS.ADD (temp); foreach(Nation datainchlist) {ListItem Li=NewListItem (data. Name, data.            Code);        DropDownList1.Items.Add (LI); }        //send it in---bindingsDropdownlist1.datasource=list; Dropdownlist1.datatextfield="Name"; Dropdownlist1.datavaluefield="Code";       Dropdownlist1.databind (); //ListItem temp = new ListItem ("= = Please select = =", "-1");DropDownList1.Items.Insert (0, temp); }

Take the value out:

        // Value---selectedvalue        Label1.Text = Dropdownlist1.selectedvalue;
        // Value---selecteditem        Label1.Text = DropDownList1.SelectedItem.Text + DropDownList1.SelectedItem.Value;
        // Value---selectedindex        Label1.Text = Dropdownlist1.items[dropdownlist1.selectedindex]. Value;
        // Value---traversal        foreach inch dropdownlist1.items)        {            iftrue)            {                = li. Text + li. Value;            }        }

Set an item to the selected value:

        // SelectedValue        Dropdownlist1.selectedvalue = TextBox1.Text;
        // SelectedIndex        
        // Traverse        Dropdownlist1.selectedindex =-1;         foreach inch dropdownlist1.items)        {            if (li. Value = = TextBox1.Text            )                {true;            }        }

WebForm Basic Control-----DropDownList

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.