如何把主页上textbox里接受的变量(关键字)提交到search.aspx去处理.是怎么传递的?主页上就一个textbox和一个button.
button在cs文件里怎么写?search.aspx是一个专门处理搜索结果的页面,并用DataGrid来显示.这是我写的源码:主页的:
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{ }
protected void btnclear_Click(object sender, EventArgs e)
{
this.txtsearch.Text = "";
}
protected void btnsearch_Click(object sender, EventArgs e)
{
Response.Redirect("search.aspx");
}
}
search.aspx.cs的:
public partial class search : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
SqlConnection con = DB.createCon();
SqlDataAdapter sda = new SqlDataAdapter();
sda.SelectCommand = new SqlCommand("select * from newsMaster where newsTitle like '%关键字%'", con);
DataSet ds = new DataSet();
sda.Fill(ds, "newsMaster");
this.DataGrid1.DataSource = ds.Tables["newsMaster"];
this.DataGrid1.DataBind();
}
}
}哪位高人帮我改一下上面的源码,能实现在主页提交的关键字,让search.aspx接收处理后显示出来.
button在cs文件里怎么写?search.aspx是一个专门处理搜索结果的页面,并用DataGrid来显示.这是我写的源码:主页的:
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{ }
protected void btnclear_Click(object sender, EventArgs e)
{
this.txtsearch.Text = "";
}
protected void btnsearch_Click(object sender, EventArgs e)
{
Response.Redirect("search.aspx");
}
}
search.aspx.cs的:
public partial class search : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
SqlConnection con = DB.createCon();
SqlDataAdapter sda = new SqlDataAdapter();
sda.SelectCommand = new SqlCommand("select * from newsMaster where newsTitle like '%关键字%'", con);
DataSet ds = new DataSet();
sda.Fill(ds, "newsMaster");
this.DataGrid1.DataSource = ds.Tables["newsMaster"];
this.DataGrid1.DataBind();
}
}
}哪位高人帮我改一下上面的源码,能实现在主页提交的关键字,让search.aspx接收处理后显示出来.
public partial class search : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{string name=Request.QueryString["name"];
if (!this.IsPostBack)
{
SqlConnection con = DB.createCon();
SqlDataAdapter sda = new SqlDataAdapter();
sda.SelectCommand = new SqlCommand("select * from newsMaster where newsTitle like '%关键字%'", con);
DataSet ds = new DataSet();
sda.Fill(ds, "newsMaster");
this.DataGrid1.DataSource = ds.Tables["newsMaster"];
this.DataGrid1.DataBind();
}
}
}
public partial class search : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{string name=Request.QueryString["name"];
if (!this.IsPostBack)
{
SqlConnection con = DB.createCon();
SqlDataAdapter sda = new SqlDataAdapter();
sda.SelectCommand = new SqlCommand(string.Format("select * from newsMaster where newsTitle like '%{0}%'",name), con);
DataSet ds = new DataSet();
sda.Fill(ds, "newsMaster");
this.DataGrid1.DataSource = ds.Tables["newsMaster"];
this.DataGrid1.DataBind();
}
}
}
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{}
protected void btnclear_Click(object sender, EventArgs e)
{
this.txtsearch.Text = "";
}
protected void btnsearch_Click(object sender, EventArgs e)
{
if(!string.IsNullOrEmpty(this.txtsearch.Text))
{
Response.Redirect("search.aspx?q=" + HttpUtility.UrlEncode(this.txtsearch.Text));
}
}
}
search.aspx.cs的:
public partial class search : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
string keyword = Request.QueryString["q"];
SqlConnection con = DB.createCon();
SqlDataAdapter sda = new SqlDataAdapter();
sda.SelectCommand = new SqlCommand("select * from newsMaster where newsTitle like '%"+ keyword+ "%'", con);
DataSet ds = new DataSet();
sda.Fill(ds, "newsMaster");
this.DataGrid1.DataSource = ds.Tables["newsMaster"];
this.DataGrid1.DataBind();
}
}
}