Asp.net assigns a value to DropDownList

Source: Internet
Author: User

Asp tutorial. net: assign a value to dropdownlist


Every option in the dropdownlist control is defined by the listitem element!

Tip: This control supports data binding!
Attribute
Property Description. net
Selectedindex option 1.0
Onselectedindexchanged the name of the function executed when the index of the option is changed. 1.0
Runat specifies that the control is a server control. Must be set to "server ". 1.0
Listcontrol standard attributes
Appenddatabounditems, autopostback, causesvalidation, datatextfield,
Datatextformatstring, datavaluefield, items, runat, selectedindex, selecteditem,
The selectedvalue, tagkey, text, validationgroup, and onselectedindexchangedlistcontrol controls include all the basic functions of the list control. Controls inherited from this control include: checkboxlist, dropdownlist, listbox, and radiobuttonlist.

For a complete description, visit the standard attributes of listcontrol.
Standard properties of web controls
Accesskey, attributes, backcolor, bordercolor, borderstyle, borderwidth,
Css tutorial class, enabled, font, enabletheming, forecolor, height, isenabled,
For a complete description of skinid, style, tabindex, tooltip, and width, visit the standard properties of the web control.
Standard properties
Apprelativetemplatesourcedirectory, bindingcontainer, clientid, controls,
Enabletheming, enableviewstate, id, namingcontainer, page, parent, site,
Templatecontrol, templatesourcedirectory, uniqueid, and visible. For a complete description, visit the standard properties of the control.

 

Assign a value to combobox in winform. In winform, combobox obtains the selectedvalue supplement of the bound object set.

On the asp.net tutorial page, assign a value to dropdownlist as follows:


Dptype. selectedindex = dptype. items. indexof (dptype. items. findbytext (m_tradereport.r_catename ));
Or


Dptype. selectedindex = dptype. items. indexof (dptype. items. findbyvalue (m_tradereport.r_cateid ));
These two methods can avoid the following situations where values cannot be set:


Dptype. selectedvalue = convert. tostring (m_tradereport.r_cateid );
Obtain the selected value for dropdownlist:

Try {m_tradereport.r_cateid = sqlparser. intparse (dptype. selectedvalue); m_tradereport.r_catename = sqlparser. stringparse (dptype. selecteditem. text);} catch {}
Or

M_tradereport.r_cateid = sqlparser. intparse (request [dptype. clientid]);

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.