HTTP error 403.14-forbidden0--asp.net implementation of the drop-down box and list box

Source: Internet
Author: User

Through the beef Brisket Teacher's press release system, roaming over the xinxin Sun Teacher's html, in 427 bathing the first ray of winter sunshine beautiful month, small series ushered in the Beida Jade Bird, Beida bird, tall on the bright have, ha ha, began a small series of. NET Tour.

First of all, let's brief you on ASP. NET, which is part of the, a Microsoft technology, is a server-side scripting technology that enables scripts embedded in Web pages to be executed by Internet servers. It can then dynamically create them on the Web server when requesting documents over HTTP. Refers to the Active Server Pages (Dynamic Servers page), which runs in the IIS (Internet Information Server service, which is a Windows-developed Web server) program. The small part of the blog to lead the small partners to learn an example, the use of ASP. NET implementation of the drop-down box and list box, as well as the small part in the process encountered problems, record the small series of learning process.

First, we need to create a database:

<span style= "FONT-SIZE:18PX;" >create Database Department   --Create databases use Departmentcreate table Tdepartment   --wear tdepartment tables (depid int Primary key, Dename varchar (+) not null) insert into tdepartment values (1, ' academic ') insert into tdepartment values (2, ' Logistics Service Center ')  INSERT into tdepartment values (3, ' Office ') CREATE TABLE emp   -Creates an EMP table (EmpID int primary KEY, EmpName varchar (+) NOT NULL, depid int foreign key references tdepartment (depid)) insert into EMP values (1, ' Wang Xiaogang ', 1) insert INTO EMP values (2, ' Li Gang ', 1) INS ert into EMP values (3, ' Zhang ', 2) insert INTO EMP values (4, ' Zhang Bo ', 3) </span>
Next, open vs, we create a new project, as shown in:

Next, write the code, we need to connect to the database, the code is written as follows:

<span style= "FONT-SIZE:18PX;" >/********************************************** ' file name: Dbcon '    capacity: Connect to database ' power    : Connect to Database '    : Ding ' generated date: November 28, 2014 14:59:45 ' version number: V2.0 ' **********************************************/using system;using System.collections.generic;using system.linq;using system.web;using system.data.sqlclient;namespace departMent{ Public    class Dbcon    {public        Dbcon ()        {        } public            static SqlConnection createconnection ()           {                //Connect to database                SqlConnection con = new SqlConnection ("server= (local);d atabase=department;uid=sa;pwd=123456;");                   return con;}}}    </span>
Next , let's write the code for the Web, as follows:

      

<span style= "FONT-SIZE:18PX;" >/********************************************** ' file name: WebForm1 ' content: implementation of the drop-down box and list box "function: implementation of the dropdown box and list box of the" Author: Ding ' Generation day Issue: November 28, 2014 15:05:45 ' version number: V2.0 ' **********************************************/using system;using System.collections.generic;using system.linq;using system.web;using system.web.ui;using System.Web.UI.WebControls; Using System.data.sqlclient;namespace department{public partial class WebForm1:System.Web.UI.Page {Protec Ted void Page_Load (object sender, EventArgs e) {if (!this.                IsPostBack) {SqlConnection con = dbcon.createconnection (); Con.                Open ();                Show Department SqlCommand cmd = new SqlCommand ("SELECT * from Tdepartment", con); SqlDataReader SDR = cmd.                ExecuteReader ();                This.ddlDep.DataSource = SDR;                This.ddlDep.DataTextField = "Dename"; This.ddldep.datavaluefield= "Depid";                     This.ddlDep.DataBind (); Sdr.                Close ();                 Show employee SqlCommand cmdemp = new SqlCommand ("SELECT * from emp where depid=" +this.ddldep.selectedvalue, con);                SqlDataReader sdremp = Cmdemp.executereader (); while (Sdremp.read ()) {This.lBoxEmp.Items.Add (New ListItem (sdremp.getstring (1), sdremp.ge TInt32 (0).                ToString ()));                     } sdremp.close (); Close connection con.            Close (); }} protected void Ddldep_selectedindexchanged (object sender, EventArgs e) {this.lboxemp.            Items.clear ();            SqlConnection con = new SqlConnection ("server= (local);d atabase=department;uid=sa;pwd=123456;"); Con.            Open ();            Show employee SqlCommand cmdemp = new SqlCommand ("SELECT * from emp where depid=" + This.ddldep.selectedvalue,con); SqlDataReader sdremp = Cmdemp.executereadER (); while (Sdremp.read ()) {This.lBoxEmp.Items.Add (New ListItem (sdremp.getstring (1), Sdremp.getint32 (0).            ToString ()));            } sdremp.close (); Close connection con.        Close (); }}}</span>
Ctrl+f5 Run, cough cough, full of expectations, look forward to the operation of what the effect will look like nie, ah oh, error, as follows:

This mistake is for God horse nie, then this small part to explain the solution, take Win8 as an example:

First step: Go to the Control Panel:

Step Two: Select program options:

Step three: Select Programs and Features:

Fourth step: Enable and disable Windows features:

Fifth step: Tick the Web core that Internet Information Services can host:


Finally click "OK" to wait for the change to complete. Then restart the computer, Setup is complete, we will run again, the effect is as follows:

Click on the corresponding drop-down box, the list box will change, but this kind of linkage is not advocated for use, when the user connection is less can be used, if a large number of users to connect, the database will be a great burden.

Small series of words: The blog, the small part of the main explanation of the knowledge of the ASP, the first contact, the small universe suddenly broke out ' (*∩_∩*), small series mainly knocked an example, The United States and the name of the use of ASP. NET implementation of the dropdown box and list box, and in the process of knocking on this small example of the difficulties encountered, hoping to help other small partners, Beida Jade Bird Net is not finished, to be continued ...

HTTP Error 403.14-forbidden0--asp.net implementing drop-down and list boxes

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.