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

📄 index.aspx.cs

📁 VC#VC#VC#VC#VC#VC#VC#VC#凑合看楼
💻 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 page_index : System.Web.UI.Page
{
    DBClass db = new DBClass();
    float j = 0;
    int m = 0;

    string str = "";
    double dob = 0;
    protected void Page_Load(object sender, EventArgs e)
    {
        //float j = 0;
        //string str;
        //if (!IsPostBack)
        //{
        //    str = "";
        //}
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        //建立连接
        SqlConnection con = db.GetConnection();
        con.Open();
        SqlCommand cmd = new SqlCommand("select money ,name,id,company,d_f,o_p,a_p,L1,L2 from cpu ", con);
        //SqlCommand cmd = new SqlCommand("select id,name,money,company,d_f,o_p,a_p,L1,L2 from cpu where id in(0"+str+") ", con);

        //填充表格
        SqlDataReader sdr = cmd.ExecuteReader();
        this.GridView1.DataSource = sdr;
        //this.GridView1.= "ID";
        this.GridView1.DataBind();
        sdr.Close();

        //this.GridView1.DataKey
        //填充选择
        sdr = cmd.ExecuteReader();
        this.CheckBoxList1.DataSource = sdr;
        this.CheckBoxList1.DataTextField = "name";
        this.CheckBoxList1.DataValueField = "id";
        this.CheckBoxList1.DataBind();
        sdr.Close();

        //关闭连接
        con.Close();
    }


    //打开此类别
    protected void Button2_Click(object sender, EventArgs e)
    {
        SqlConnection con = db.GetConnection();
        con.Open();
        SqlCommand cmd = new SqlCommand("select * from DidplayCard", con);
        SqlDataReader sdr = cmd.ExecuteReader();
        this.GridView2.DataSource = sdr;
        this.GridView2.DataBind();
        sdr.Close();
        con.Close();
    }


    //xianshi 价钱
    protected void Button3_Click(object sender, EventArgs e)
    {
        SqlConnection con = db.GetConnection();
        con.Open();
        SqlCommand cmd = new SqlCommand("select * from harddisk", con);
        SqlDataReader sdr = cmd.ExecuteReader();
        this.GridView3.DataSource = sdr;
        this.GridView3.DataBind();
        sdr.Close();
        con.Close();

        //SqlConnection con = db.GetConnection();
        //con.Open();

        ////SqlCommand cmd = new SqlCommand("select name,money from cpu where id=" + this.GridView1.DataKeys[m][0], con);
        ////SqlCommand cmd = new SqlCommand("select money,name,id,company,d_f,o_p,a_p,L1,L2 from cpu where id in(0" + str + ") ", con);

        ////SqlCommand cmd = new SqlCommand("select * from harddisk", con);
        //SqlDataReader sdr = cmd.ExecuteReader();
        //this.GridView3.DataSource = sdr;
        //this.GridView3.DataBind();
        //sdr.Close();
        //con.Close();














    }


    //显示购物车
    protected void Button4_Click(object sender, EventArgs e)
    {
        //SqlConnection con = db.GetConnection();
        //con.Open(); 
        //con.Close();
        // SqlCommand cmd = new SqlCommand("select * from cpu ");
        //SqlDataReader sdr = cmd.ExecuteReader(); 
        //this.ListBox2.Items.Add(new ListItem(sdr.GetString(16),sdr.GetInt32(0).ToString));

        //this.ListBox2.DataSource = sdr;

        //this.ListBox2 .DataBind();
        //sdr.Close();

        int i;


        for (i = 0; i < CheckBoxList1.Items.Count; i++)
        {


            if (this.CheckBoxList1.Items[i].Selected == true)
            {

                this.ListBox1.Items.Add(this.CheckBoxList1.Items[i].Text);



                dob += Convert.ToDouble(this.GridView1.Rows[i].Cells[2].Text);





            }




            

        }
       this.Label1.Text= Convert.ToString ( dob) ;
    }

    //protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
    //{
    //    string str = this.GridView1.DataKeys[e.Equals].ToString;

    //}
    //protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
    //{
    //    
    //}


    //删除
    protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {

        //e.RowIndex


        this.Label3.Text = "删除了  " + e.RowIndex;

    }

    //选择
    protected void GridView1_SelectedIndexChanging(object sender, GridViewSelectEventArgs e)
    {


        //this.Response.Write(str);



        SqlConnection con = db.GetConnection();
        con.Open();

        m = e.NewSelectedIndex;


        str += "," + this.GridView1.DataKeys[m][0];


        SqlCommand cmd = new SqlCommand("select money from cpu where id=" + this.GridView1.DataKeys[m][0], con);
        string k;

        k = Convert.ToString(cmd.ExecuteScalar());

        this.Label3.Text = k;


        j += float.Parse(k);
        this.Label3.Text = Convert.ToString(j);

        con.Close();




        //每点击一下显示一个
        //SqlConnection con = db.GetConnection();
        //con.Open();

        //SqlCommand cmd = new SqlCommand("select name,money from cpu where id=" + this.GridView1.DataKeys[m][0], con);


        ////SqlCommand cmd = new SqlCommand("select * from harddisk", con);
        //SqlDataReader sdr = cmd.ExecuteReader();
        //this.GridView3.DataSource = sdr;
        //this.GridView3.DataBind();
        //sdr.Close();
        //con.Close();




        //String[] str = new string[3] { "id", "name", "money" };

        //this.GridView1.DataKeyNames = str;
        //Convert.ToString(cmd.ExecuteScalar());
        //this.Label3.Text = "添加成功  " + this.GridView1.SelectedIndex + "价钱是" + i;
        //SqlDataReader sdr = cmd.ExecuteReader();
        //this.ListBox.Items.Add(new ListItem(sdr.GetString(16), sdr.GetInt32(0).ToString));
        //this.ListBox2.DataSource = sdr;
        //this.ListBox2.DataBind();
        //sdr.Close();
        //"select money from cpu where id="+this.GridView1.SelectedValue


        //if (!IsPostBack)
        //{
        //}

    }


    protected void ListBox1_SelectedIndexChanged(object sender, EventArgs e)
    {
        this.Label3.Text = this.ListBox1.SelectedValue ;


    }
    protected void GridView3_SelectedIndexChanged(object sender, EventArgs e)
    {

    }
    protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
    {

    }
    protected void CheckBoxList1_SelectedIndexChanged(object sender, EventArgs e)
    {

    }
}

⌨️ 快捷键说明

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