| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 681 人关注过本帖
标题:菜鸟求助,关于asp数据添加的问题,做一个网上商城的新增问题 ...
只看楼主 加入收藏
chensike0603
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2007-4-14
收藏
 问题点数:0 回复次数:5 
菜鸟求助,关于asp数据添加的问题,做一个网上商城的新增问题 ...
求源码,
图片附件: 游客没有浏览图片的权限,请 登录注册
就是下面的小部分
图片附件: 游客没有浏览图片的权限,请 登录注册
,其他的搜索,分页,删除,修改都做了,就差新增了,请高手帮忙
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;

namespace lab17
{
    public partial class goodsInsert : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                getGoods();
            }

        }
        private SqlConnection GreateConnection()
        {
            SqlConnection cn = new SqlConnection();
            cn.ConnectionString = ConfigurationManager.ConnectionStrings["OnlineShopConnectionString"].ConnectionString;
            return cn;
        }



        private DataSet GetGoodsByName(string strGoodsName)
        {
            SqlConnection cn = GreateConnection();
            cn.Open();

            SqlCommand cm = new SqlCommand();
             = CommandType.StoredProcedure;
             = "GoodsGetByName";
            cm.Parameters.AddWithValue("@goodsName", strGoodsName);
            cm.Connection = cn;

            SqlDataAdapter da = new SqlDataAdapter();
            da.SelectCommand = cm;

            DataSet ds = new DataSet();
            da.Fill(ds, "tb_Goods");

            cn.Close();
            return ds;

        }
        private void getGoods()
        {
            if (ViewState["goodsname"] == null)
                ViewState["goodsname"] = "";
            string GoodsName = ViewState["goodsname"].ToString();
            DataSet ds = GetGoodsByName(GoodsName);
            gdvGoods.DataSource = ds.Tables["tb_Goods"];
            gdvGoods.DataBind();

        }

        protected void gdvGoods_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            gdvGoods.PageIndex = e.NewPageIndex;
            getGoods();
        }

        protected void btnSearch_Click(object sender, EventArgs e)
        {
            ViewState["goodsname"] = txtSearch.Text;
            getGoods();
        }

        protected void gdvGoods_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            SqlConnection cn = GreateConnection();
            cn.Open();

            SqlCommand cm = new SqlCommand();
             = CommandType.StoredProcedure;
             = "GoodsDelete";
            cm.Parameters.AddWithValue("@goodsID", gdvGoods.DataKeys[e.RowIndex].Value);
            cm.Connection = cn;
            cm.ExecuteNonQuery();
            cn.Close();
            getGoods();

        }

        protected void gdvGoods_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow && (e.Row.RowState & DataControlRowState.Edit) == 0)
            {
                LinkButton lbtn = (LinkButton)e.Row.Cells[6].Controls[0];
                lbtn.Attributes.Add("onclick", "javascript:return confirm('您确定要删除吗?')");
            }
        }

        protected void gdvGoods_RowEditing(object sender, GridViewEditEventArgs e)
        {
            gdvGoods.EditIndex = e.NewEditIndex;
            getGoods();
        }

        protected void gdvGoods_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
        {
            gdvGoods.EditIndex = -1;
            getGoods();
        }

        protected void gdvGoods_RowUpdating(object sender, GridViewUpdateEventArgs e)
        {
            SqlConnection cn = GreateConnection();
            cn.Open();
            SqlCommand cm = new SqlCommand();

             = CommandType.StoredProcedure;
             = "GoodsUpdata";

            cm.Parameters.AddWithValue("@goodsID", gdvGoods.DataKeys[e.RowIndex].Value);
            cm.Parameters.AddWithValue("@goodsName", ((TextBox)gdvGoods.Rows[e.RowIndex].Cells[0].FindControl("TextBox1")).Text.Trim());
            cm.Parameters.AddWithValue("@goodsType", ((TextBox)gdvGoods.Rows[e.RowIndex].Cells[1].Controls[0]).Text.Trim());
            cm.Parameters.AddWithValue("@goodsUnitPrice", ((TextBox)gdvGoods.Rows[e.RowIndex].Cells[2].Controls[0]).Text.Trim());
            cm.Parameters.AddWithValue("@goodsImageName", ((TextBox)gdvGoods.Rows[e.RowIndex].Cells[3].Controls[0]).Text.Trim());
            cm.Parameters.AddWithValue("@sellCount", ((TextBox)gdvGoods.Rows[e.RowIndex].Cells[4].Controls[0]).Text.Trim());
            cm.Parameters.AddWithValue("@goodsDate", ((TextBox)gdvGoods.Rows[e.RowIndex].Cells[5].Controls[0]).Text.Trim());

            cm.Connection = cn;
            cm.ExecuteNonQuery();
            gdvGoods.EditIndex = -1;
            getGoods();
        }
搜索更多相关主题的帖子: 网上商城 asp 数据 
2008-05-11 15:30
hebingbing
Rank: 6Rank: 6
来 自:黄土高坡
等 级:贵宾
威 望:27
帖 子:3417
专家分:371
注 册:2007-10-22
收藏
得分:0 
lz既然能做出来修改那么做新增就简单多了啊……
在你的新增的按钮的click事件中直接将修改的代码复制过来,再加上一些判断是否为空,是否已经存在等的操作,然后将修改的sql语句改成insert into就ok了啊……
2008-05-11 15:37
chensike0603
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2007-4-14
收藏
得分:0 
其实这都是老师教的,老师叫我们自己做'新增'的,不会啊,还有图片上传的
2008-05-11 20:05
hebingbing
Rank: 6Rank: 6
来 自:黄土高坡
等 级:贵宾
威 望:27
帖 子:3417
专家分:371
注 册:2007-10-22
收藏
得分:0 
lz还是自己做吧,其实不难的,具体的方法我都在上面说的很清楚了啊……
努力,相信你能做出来的……
2008-05-11 20:26
chensike0603
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2007-4-14
收藏
得分:0 
努力
2008-05-12 12:21
jielig1
Rank: 1
等 级:新手上路
帖 子:9
专家分:0
注 册:2008-4-27
收藏
得分:0 
看看书就可以了,努力,就是在新增的事件中,插入新数据和上传图片就行了。
2008-05-12 15:58
快速回复:菜鸟求助,关于asp数据添加的问题,做一个网上商城的新增问题 ...
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.034662 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved