<% @ Page Language = " C# " Debug = " true " %> <% @ OutputCache Duration = 1 VaryByParam = " none " %> <% @ Import NameSpace = " System.Data " %> <% @ Import NameSpace = " System.Data.OleDb " %> < Html > < Head > < style type = " text/css " > body ... { font:12px tahoma; margin:0px; } table ... { font:12px tahoma; } </ style > < script runat = " server " > OleDbConnection myConn; OleDbCommand myComm; OleDbDataAdapter myDA; void Page_Load( object sender,EventArgs e) ... { if(!IsPostBack) ...{ classList.DataSource=classListData(); classList.DataBind(); myConn.Close(); } } void ConnOpen() ... { myConn=new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source="+Server.MapPath("test.mdb")); myConn.Open(); } DataSet classListData() ... { ConnOpen(); string strComm="select * from Class"; myDA=new OleDbDataAdapter(strComm,myConn); DataSet ds=new DataSet(); myDA.Fill(ds,"Class"); return ds; } string Command( string comm) ... { try ...{ ConnOpen(); myComm=new OleDbCommand(comm,myConn); myComm.ExecuteNonQuery(); return "Successful"; } catch(Exception e) ...{ return e.Message; } finally ...{ myConn.Close(); } } void Buttons_Click( object sender,EventArgs e) ... { Button myButton=(Button)sender; string strComm; switch(myButton.ID) ...{ case "classAdd": if(classList.SelectedItem==null || classList.SelectedItem.Value.Length==0) ...{ strComm="insert into class(PID,Name)values(0,'"+className.Text+"')"; Command(strComm); Response.Redirect(Server.MapPath("Admin.aspx")); } else ...{ strComm="insert into class(PID,Name)values(classList.SelectedItem.Value,'"+className.Text+"')"; Command(strComm); //Response.Redirect(Server.MapPath("Admin.aspx")); Response.Write(classList.SelectedValue+" "+className.Text); } break; case "classUpdate": Response.Write("131313"); break; case "classDelete": Response.Write("test"); break; } } </ script > < Title ></ Title > </ Head > < Body > < form id = " form1 " runat = " server " method = " post " > < table border = " 1px " > < tr > < th colspan = " 2 " > ClassManager </ th > </ tr > < tr > < td > ClassName: </ td > < td > < asp:TextBox ID = " className " runat = " server " ></ asp:TextBox > </ td > </ tr > < tr > < td > ParentClass: </ td > < td > < asp:DropDownList ID = " classList " runat = " server " AutoPostBack = " true " DataTextField = " Name " DataValueField = " ID " ></ asp:DropDownList > </ td > </ tr > < tr > < td > AddClass </ td > < td > < asp:Button ID = " classAdd " runat = " server " Text = " AddClass " OnClick = " Buttons_Click " > </ asp:Button > </ td > </ tr > < tr > < td > UpdateClass </ td > < td > < asp:Button ID = " classUpdate " runat = " server " Text = " UpdateClass " OnClick = " Buttons_Click " ></ asp:Button > </ td > </ tr > < tr > < td > DeleteClass </ td > < td > < asp:Button ID = " classDelete " runat = " server " Text = " DeleteClass " OnClick = " Buttons_Click " ></ asp:Button > </ td > </ tr > </ table > </ form > </ Body > </ Html >