小项目2

<% @ 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 >
 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值