Select program code for asp.net province and city

Source: Internet
Author: User

1. The first is the establishment of the database tutorial. The code given will cause Chinese garbled characters, so I simply changed it.
First: change varchar (50) to nvarchar (50 );
Second: adds N to the front of each Chinese string
2. Winform program creation, simple interface

The DropDownStyle attribute is changed to DropDownList.
3. Add an application configuration file

Put the database connection part here. When the IP address changes, you only need to change the configuration file, instead of modifying the source program.
4. Code
The code in the winform is not included in the reference of the configuration class and must be manually added.
A class is defined here.


Class ProvinceItem
        {
Public string name;
Public int id;
Public string Name
            {
Get
                {
Return this. name;
                }
Set
                {
This. name = value;
                }
            }
Public int Id
            {
Get
                {
Return this. id;
                }
Set
                {
This. id = value;
                }
            }
        }


Because the version is 2005, it cannot be abbreviated
Cb saving. items. add (item); in this sentence, an item object is actually added, and the class name is actually returned when the object is converted to the string type. Therefore, you need to modify the attributes of ComboBox for this part: change the DisplayMember attribute value to Name.


 
Then there is code in cb province
This involves a forced type conversion, which converts the object type to the ProvinceItem type.


 
5. Running result


We recommend an ajax asp tutorial. net linkage menu code.

Http://down.111cn.net/down/code/net/2011/0612/23159.html

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.