wuruie
ITEM47
2017-03-16 16:10

web端 textbox和gridview做收银界面问题?求教

  • 数据
  • textbox
  • web
  • gridview

前台就一个textbox2和一个gridview1,想要实现textbox2找一条数据并追加到gridview中显示,现在已经实现了,但是只能找一条,找第二条的时候就只显示第二条,我要效果是,找到一条数据后放在gridview1中然后在找第二第三全条……并在gridview1中显示全部!类似收银前台的功能!下面是后台的代码,请高手赐教啊!
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Data.OleDb;
using System.Collections;

public partial class pos : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

}
protected void TextBox2_TextChanged(object sender, EventArgs e)
{
    GetUserInfo("SELECT Code,Goodsname,price FROM goods where Code = " + TextBox2.Text + "");
}
private void GetUserInfo(string strcmd)  //使用方法对Gridview填充查询到的数据,前台属性设置AutoGenerateColumns="false" 即可开启需要显示的列
{
    SqlConnection conn = new SqlConnection(rvshiconn.sqlconn);
    try
    {
        conn.Open();
        SqlDataAdapter da = new SqlDataAdapter(strcmd, conn);
        DataSet ds = new DataSet();
        da.Fill(ds, "goods");
        GridView1.DataSource = ds.Tables[0].DefaultView;
        GridView1.DataBind();
        Label1.Text = ds.Tables[0].Compute("Sum(price)", "true").ToString(); ;
    }
    catch (SqlException ex)
    {
        Page.ClientScript.RegisterStartupScript(Page.GetType(), "", "<Script>alere('" + ex.Message + "')</Script>");
    }
    finally
    {
        conn.Close();
    }
}

}

  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

1条回答