⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 admincourseselect.aspx.cs

📁 学生网上选课系统,实现了学生的在线选课和教师课程的上传
💻 CS
字号:
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;

public partial class _Default : System.Web.UI.Page
{
    SqlConnection conn;
    protected void Page_Load(object sender, EventArgs e)
    {
      string strconn=System .Configuration .ConfigurationManager .AppSettings ["ConnectionString"];
        conn =new SqlConnection (strconn );
      if (!IsPostBack)
      {
                GridViewBind();
                GridViewBind1();
                TypeBind();
        }
    }
    private void GridViewBind1()
    {
        string SqlStr = "";
        if (CourceName.Text.Trim() == "")
        {

            SqlStr = "SELECT Cource.*,Teacher.*,type.* FROM Cource,Teacher,type where Cource.teaID=Teacher.teaID and Cource.typeID=type.typeID and Cource.typeID like '%" + DropDownList1.Text.Trim() + "%' order by Teacher.teaID";
        }
        else
        {
            //DropDownList1.Enabled = false;
            SqlStr = "SELECT Cource.*,Teacher.*,type.* FROM Cource,Teacher,type where Cource.teaID=Teacher.teaID and Cource.typeID=type.typeID and Cource.CourceName like '%" + CourceName.Text.Trim() + "%' order by Teacher.teaID";
        }

        DataSet ds = new DataSet();

        try
        {
            if (conn.State.ToString() == "Closed")
                conn.Open();
            SqlDataAdapter da = new SqlDataAdapter(SqlStr, conn);
            da.Fill(ds);

            GridView1.DataSource = ds.Tables[0].DefaultView;
            GridView1.DataBind();
        }
        catch (Exception ex)
        {
            Response.Write("数据库错误,错误原因:" + ex.Message);
            Response.End();
        }
        finally
        {
            if (conn.State.ToString() == "Open")
                conn.Close();
        }
    }
    private void GridViewBind()
    {
        // string connStr = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
        string SqlStr = "SELECT Cource.*,Teacher.*,type.* FROM Cource,Teacher,type where Cource.teaID=Teacher.teaID and Cource.typeID=type.typeID order by Teacher.teaID";
        DataSet ds = new DataSet();
        // SqlConnection conn = new SqlConnection(connStr);
        try
        {
            if (conn.State.ToString() == "Closed")
                conn.Open();
            SqlDataAdapter da = new SqlDataAdapter(SqlStr, conn);
            da.Fill(ds);

            GridView1.DataSource = ds.Tables[0].DefaultView;
            GridView1.DataBind();
        }
        catch (Exception ex)
        {
            Response.Write("数据库错误,错误原因:" + ex.Message);
            Response.End();
        }
        finally
        {
            if (conn.State.ToString() == "Open")
                conn.Close();
        }
    }
    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
 
    }
    protected void TypeBind()
    {
        string sql = "select typename,typeid from type";
        SqlDataAdapter da = new SqlDataAdapter(sql,conn);
        DataSet ds = new DataSet();
        da.Fill(ds,"ds");
        for (int i = 0; i < ds.Tables["ds"].Rows.Count; i++)
        {
            DropDownList1.Items.Add(new ListItem(ds.Tables["ds"].Rows[i]["typename"].ToString(),ds.Tables["ds"].Rows[i]["typeid"].ToString()));
        }
    }
    protected void chaxun_Click(object sender, EventArgs e)
    {
        GridViewBind1();
    }
    protected void fanhui_Click(object sender, EventArgs e)
    {
        Response.Redirect("main.aspx");
    }
    public void Data_Page(object sender, GridViewPageEventArgs e)
    {
        try
        {
            GridView1.PageIndex = e.NewPageIndex;
            GridViewBind();
            //GridViewBind1();
        }
        catch 
        { }
        
    }
    
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -