SearchResults.aspx
This
page displays the search results when you type some product in the search box.
Session["fullname"]="";
txtHidden.Text=Session["search"].ToString();
// Used sessions to capture the search parameter.
SqlConnection
objcon = new
SqlConnection(ConfigurationSettings.AppSettings["ConnectionString"]);
// Use connection string always.
string sql=@"Select
pr.productid,im.imagename,pr.modelname,pr.unitcost from products pr,images im
where pr.productid=im.productid and pr.modelname like '%"+txtHidden.Text
+"%" +"'";
try
{
SqlDataAdapter
objda = new SqlDataAdapter(sql,objcon);
DataSet
ds = new DataSet();
objda.Fill(ds);
string cnt = ds.Tables[0].Rows.Count.ToString();
// Used for counting the number of results.
if(ds.Tables[0].Rows.Count==0)
{
lblMessage.Text="Sorry
Results not found";
}
if(ds.Tables[0].Rows.Count > 0)
{
lblMessage.Text= cnt + " results found";
}
dsSearchResults.DataSource
=ds; // results bound to a datalist.
dsSearchResults.DataBind();
}
catch(Exception em)
{
Console.WriteLine(em.Message);
}
}