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

📄 masterpage.master.cs

📁 完成一个网上书店系统
💻 CS
字号:
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
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.Xml.Linq;
using System.Data.SqlClient;
public partial class MasterPage : System.Web.UI.MasterPage
{
    
    protected void Page_Load(object sender, EventArgs e)
    {
        if(!IsPostBack)
        {
            DropDownList1Bind();
            if (Session["UserName"] == null || Session["UserName"].ToString() == "")
            {
                Label2.Text = "匿名用户";
                Label3.Text = "未知";
            }
            else
            {
                Label2.Text = Convert.ToString(Session["UserName"]);
                Label3.Text = Convert.ToString(Session["Role"]);
            }
        }
        String selectedid = Request.Params["selection"];
        if (selectedid != null)
        {
            DataList1.SelectedIndex = Int32.Parse(selectedid);
            
        }

        string settings = Convert.ToString(ConfigurationManager.ConnectionStrings["BookShopConnectionString"]);
        SqlConnection myconn = new SqlConnection(settings);
        myconn.Open();

        SqlCommand mycmd = new SqlCommand("ListBookCategory", myconn);
        mycmd.CommandType = CommandType.StoredProcedure;

        SqlDataReader result = mycmd.ExecuteReader(CommandBehavior.CloseConnection);
        DataList1.DataSource = result;
        DataList1.DataBind();
        
    }
    private void DropDownList1Bind()
    {
        string settings = Convert.ToString(ConfigurationManager.ConnectionStrings["BookShopConnectionString"]);
        SqlConnection myconn = new SqlConnection(settings);
        myconn.Open();
        String str = "select Cname,Ename  from DropDownList ";
        SqlCommand mycmd = new SqlCommand(str, myconn);
        SqlDataReader result=mycmd.ExecuteReader();

        DropDownList1.DataSource = result;
        DropDownList1.DataTextField = "Cname";
        DropDownList1.DataValueField = "Ename";
        DropDownList1.DataBind();
    }

  /*  protected void Button1_Click(object sender, EventArgs e)
    {
        string selectitem = DropDownList1.SelectedItem.Text.ToString();
        HttpCookie mycookie = new HttpCookie("search");
        string bookname = TextBox1.Text;
        if (bookname.Equals(""))
        {
            Page.ClientScript.RegisterStartupScript(this.GetType(), "MessageBox", "alert('搜索内容不能为空!')", true);
        }
        else
        {
            mycookie["bookname"] = bookname;
            mycookie["Cname"] = selectitem;
            Response.Cookies.Add(mycookie);
            Response.Redirect("Serach.aspx");
        }

    }*/
    protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
    {
        string selectitem = DropDownList1.SelectedItem.Text.ToString();
        HttpCookie mycookie = new HttpCookie("search");
        string bookname = TextBox1.Text;
        if (bookname.Equals(""))
        {
            Page.ClientScript.RegisterStartupScript(this.GetType(), "MessageBox", "alert('搜索内容不能为空!')", true);
        }
        else
        {
            mycookie["bookname"] = bookname;
            mycookie["Cname"] = selectitem;
            Response.Cookies.Add(mycookie);
            Response.Redirect("Serach.aspx");
        }
    }
}

⌨️ 快捷键说明

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