如图,本人用用button按钮做成搜索按钮,输入关键字后,点击搜索,就会弹出
相关代码在这:那个button按钮的代码在下面,求高手帮本人修改
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;
public partial class Jdcg : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
if (Session[“users”] == null)
{
Response.Write(“<script>alert(“请先登录!”);window.location=”Default.aspx”;</script>”);
return;
}
goods();
}
}
private void goods()
{
string sSql = “select * from Zy”;
SQL s = new SQL();
DataSet ds = s.DSSearch(sSql);// s.DSSearch(sSql);gridview是表格视图。简单说就是,数据库的内容要显示,就得通过dataset获取,才能在girdview上显示出来
PagedDataSource pds = new PagedDataSource();//初始化PagedDataSource实例,主要用做DataList1的分页使用
pds.AllowPaging = true;//允许分页
pds.PageSize = 10;//每页显示10条
pds.DataSource = ds.Tables[0].DefaultView;//将检索出的ds数据集绑定给PagedDataSource实例pds
pds.CurrentPageIndex = AspNetPager1.CurrentPageIndex – 1;//CurrentPageIndex:当前的页数。AspNetPager分页
//AspNetPager1.AlwaysShow = true;
//AspNetPager1.PageSize = 5;
AspNetPager1.RecordCount = ds.Tables[0].Rows.Count;
DataList2.DataSource = pds;//将pds内容最终绑定给DataList1,呈现到界面中
DataList2.DataBind();
}
protected void AspNetPager1_PageChanged(object sender, EventArgs e)
{
goods();
}
protected void Button1_Click(object sender, EventArgs e)
{
string sSql = “select * from Zy where title like “%” + TextBox1.Text + “%” order by dates desc”;
SQL s = new SQL();
DataSet ds = s.DSSearch(sSql);
DataList2.DataSource = ds;//将ds内容最终绑定给DataList1,呈现到界面中。DataSource,绑定的数据源;
DataList2.DataBind();
}
}
解决方案
50
检查数据库,是不是有dates这一列,仔细检查拼写
50
string sSql = "select * from Zy where title like "%" + TextBox1.Text + "%" order by dates desc";
先改成
string sSql = "select * from Zy where title like "%" + TextBox1.Text + "%"";