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

📄 amodify.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 AModify : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Request.QueryString["Aname"] != null)
        {
            bind();
        }
    }
    public void bind()
    {
        SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["connstring"].ConnectionString);
        string sql = "select Gid as '序号',Gpicture as '照片',Gname as '名称', Gprice as '价格',Gdescribe as '描述' from Goods";
        SqlCommand cmd = new SqlCommand(sql, conn);
        SqlDataAdapter da = new SqlDataAdapter(cmd);
        DataSet ds = new DataSet();
        da.Fill(ds);
        GridView1.DataSource = ds.Tables[0];
        GridView1.DataKeyNames = new string[] { "序号" };
        GridView1.DataBind();
    }
    protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
    {
        this.GridView1.EditIndex = e.NewEditIndex;
        bind();
    }
   
    protected void Button2_Click(object sender, EventArgs e)
    {
        if (String.IsNullOrEmpty(FileUpload1.FileName))
        {
            this.Label6.Text = "要上传的文件名不能为空";
            this.Label7.Text = "NO";
            return;
        }
        else
        {
            string fileName = FileUpload1.FileName;
            string serverPath = Server.MapPath("picture/") + fileName;
            FileUpload1.SaveAs(serverPath);
        }
        SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["connstring"].ConnectionString);
        string s = "~\\picture\\" + this.FileUpload1.FileName.ToString() + "";
        Label7.Text = s.ToString();
        string sql = "insert into Goods (Gpicture,Gname,Gprice,Gdescribe) values ('"+ s.ToString() + "','" + this.Tbx_Gname.Text + "','" + this.Tbx_Gprice.Text + "','" + this.Tbx_Gdept.Text + "')";
        conn.Open();
        SqlCommand cmd = new SqlCommand(sql,conn);
        if (cmd.ExecuteNonQuery() > 0)
        {
            this.Label7.Text = "OK";
        }
        else
        {
            this.Label7.Text = "NO";
        }
       // cmd.ExecuteNonQuery();
        conn.Close();
        bind();
        this.Tbx_Gname.Text = "";
        this.Tbx_Gprice.Text = "";
        this.Tbx_Gdept.Text = "";
    }

    protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
        SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["connstring"].ConnectionString);
        int index = e.RowIndex;
        int gidID=Convert.ToInt32(GridView1.DataKeys[e.RowIndex].Value.ToString());
        string sql = "delete  from Goods where Gid='" + gidID + "'";
        conn.Open();
        SqlCommand cmd = new SqlCommand(sql, conn);
        cmd.ExecuteNonQuery();
        conn.Close();
        bind();

    }
    protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
    {

        string gname = ((TextBox)this.GridView1.Rows[e.RowIndex].Cells[2].Controls[0]).Text.Trim();
        string gprice = ((TextBox)this.GridView1.Rows[e.RowIndex].Cells[3].Controls[0]).Text.Trim();
        string gdes = ((TextBox)this.GridView1.Rows[e.RowIndex].Cells[4].Controls[0]).Text.Trim();


        SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["connstring"].ConnectionString);
        conn.Open();
        string sql="update Goods set Gname='" + gname + "',Gprice='" + gprice + "',Gdescribe='" + gdes + "'where Gid='" + GridView1.DataKeys[e.RowIndex].Value.ToString()+ "'";
        SqlCommand cmd = new SqlCommand(sql, conn);
        cmd.ExecuteNonQuery();///////////////////?????????????????????????????
        GridView1.EditIndex = -1;
        conn.Close();
        bind();


    }

    protected void GridView1_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
    {
        GridView1.EditIndex = -1;
        bind(); 
    }

    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        e.Row.Cells[4].Attributes.Add("style", "width:100px;word-wrap:break-word;word-break:normal;");
        //   e.Row.Cells[4].Attributes.Add("style", "width:100px;word-wrap:break-word;word-break:normal;");//固定列的大小
    }
    protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        ((GridView)sender).PageIndex = e.NewPageIndex;
        bind();
    }
    protected void Button1_Click1(object sender, EventArgs e)//推出功能
    {
        Session.Abandon();
  
       //Session.Abandon();//清除Session
        Response.Redirect("Default.aspx");
    }
}

⌨️ 快捷键说明

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