62,254
社区成员
发帖
与我相关
我的任务
分享
public partial class PartList_NoPrice : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
this.bind();
}
}
protected void btnsearch_Click(object sender, EventArgs e)
{
string txtname = this.txtname.Text;
string sql = "where 1=1";
if (txtname != "")
{
sql = sql + "and pn like '%" + txtname + "%'";
}
Session["sql"] = sql;
this.bind();
}
protected void bind()
{
SqlConnection strcon = new SqlConnection(System.Configuration.ConfigurationManager.AppSettings["strcon"]);
strcon.Open();
string sql = "select * from NoPrice " + Session["sql"] + " order by id desc";
SqlDataAdapter sda = new SqlDataAdapter(sql, strcon);
DataSet ds = new DataSet();
sda.Fill(ds);
DataTable dt = ds.Tables[0];
if (dt.Rows.Count > 0)
{
this.div.Visible = true;
this.GridView1.DataSource = dt;
this.GridView1.DataKeyNames = new string[] { "id" };
this.GridView1.DataBind();
this.laberor.Visible = false;
this.lbl1.Text = "第" + (GridView1.PageIndex + 1).ToString() + "页";
this.lbl2.Text = "共" + this.GridView1.PageCount.ToString() + "页";
this.lbl3.Text = "共" + dt.Rows.Count.ToString() + "条";
strcon.Close();
}
else
{
this.div.Visible = false;
this.laberor.Visible = true;
this.laberor.Text = "对不起,没有你要查询的记录";
}
}
}
