Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
Sir M having a search form in my real estate site for searching properties there are many criterias like propertytype,city, locality,price,area i want to display the search result on diff page not on the same page...i'hv written a query which searchers the database properly but i dont know how to display the search result on another page and bind them in listview...on page load...
 
m doing like this to bind listview on searchresult page by (datatable)dt stored in session
SqlConnection con = new SqlConnection(str);
 SqlDataAdapter da = new SqlDataAdapter();
 DataTable dt = new DataTable();
 dt = Session["Search"] as DataTable;
 da.Fill(dt);
 listview1.DataSource = dt;
 listview1.DataBind();
but it is showing error..
Fill: SelectCommand.Connection property has not been initialized.
 
Code Behind
if (rbtnfs.Checked == true)
        {
            try
            {
                SqlConnection con = new SqlConnection(str);
                string strQ = ("select S.Property_Type,C.City_Name,L.Locality_Name,S.Price,S.Bedrooms,S.Area From tbl_post_property_sale as S inner join tbl_City as C on C.City_Id=S.City_id inner join tbl_Locality as L on L.Locality_Id=S.Locality_Id where S.Property_type='" + ddlpropertytype.SelectedItem.Text + "'and C.City_Id=" + ddlcity.SelectedValue + " and L.Locality_Id=" + ddllocality.SelectedValue + " and S.price between " + ddlminprice.SelectedValue + " and " + ddlmaxprice.SelectedValue + " and S.Bedrooms=" + ddlbedrooms.SelectedItem.Text + " and S.Area between '" + (txtminarea.Text).Trim() + " " + ddlarea.SelectedItem.Text + "'and '" + (txtmaxarea.Text).Trim() + " " + ddlarea.SelectedItem.Text + "'");
                SqlCommand cmdsearch = new SqlCommand(strQ, con);
                con.Open();
                cmdsearch.ExecuteNonQuery();
                con.Close();
            }
            catch (Exception ex)
            {
 
            }
 
        }
        else
        {
            try
            {
                SqlConnection con = new SqlConnection(str);
                string strQ = ("select R.Property_Type,C.City_Name,L.Locality_Name,R.Price,R.Bedrooms,R.Area From tbl_post_property_rent as R inner join tbl_City as C on C.City_Id=R.City_id inner join tbl_Locality as L on L.Locality_Id=R.Locality_Id where R.Property_type='" + ddlpropertytype.SelectedItem.Text + "'and C.City_Id=" + ddlcity.SelectedValue + " and L.Locality_Id=" + ddllocality.SelectedValue + " and R.price between " + ddlminprice.SelectedValue + " and " + ddlmaxprice.SelectedValue + " and R.Bedrooms=" + ddlbedrooms.SelectedItem.Text + " and R.Area between '" + (txtminarea.Text).Trim() + " " + ddlarea.SelectedItem.Text + "'and '" + (txtmaxarea.Text).Trim() + " " + ddlarea.SelectedItem.Text + "'");
                SqlCommand cmdsearch = new SqlCommand(strQ, con);
                con.Open();
                cmdsearch.ExecuteNonQuery();
                con.Close();
            }
            catch (Exception ex)
            {
 
            }
 
        }
Posted 4-Oct-12 1:48am
Edited 4-Oct-12 8:56am
v4
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

store your result session and get result from session on other page .
  Permalink  
Comments
solanki.net at 4-Oct-12 8:52am
   
suppose u have table that contain your all search result.
then session["Record"] =dt;// for storing table in session.
// if u want to get this session on other page then
 
DataTable dt=new DataTable();
dt=session["Record"] as DataTable;
 

Ambesha at 4-Oct-12 9:42am
   
Yes ! you can :)
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

I your are retrieving your results from a database, you can just pass the parameters of the select method to the query string dictionary and get them back in the page you want to show data in.
 
it will look something like this: domain/folder/showResults.aspx?id1=this&id2=that
Then in the showResults page all you need to do is:
get the differents ids from the query string by doing this:
var id1 = Request.QueryString[id1]; and so on.
I hope this to help you.
  Permalink  
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

SqlConnection con = new SqlConnection(str);
 SqlDataAdapter da = new SqlDataAdapter();
 DataTable dt = new DataTable();
 dt = Session["Search"] as DataTable;
 da.Fill(dt);
 listview1.DataSource = dt;
 listview1.DataBind();
Incorrect implementation.
 
I see you already have data in Session. Since you have it, you don't need to hit DB and get back data. Simply do:
if(Session["Search"] != null)
{
  listview1.DataSource = (DataTable) Session["Search"];
  listview1.DataBind();
}
 

Just to add on, the reason why you were getting an error was: You defined a dataadapter without a command and tried to fill the dataset. If you want to hit database and get data, first define the adapter command (probably a select statement) and then fill a dataset from it.
  Permalink  
Comments
Raj.Rautela at 4-Oct-12 23:41pm
   
thanks u sir....

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 540
1 OriginalGriff 300
2 CPallini 290
3 ChauhanAjay 124
4 George Jonsson 120
0 OriginalGriff 6,474
1 Sergey Alexandrovich Kryukov 6,190
2 CPallini 5,180
3 George Jonsson 3,574
4 Gihan Liyanage 2,522


Advertise | Privacy | Mobile
Web04 | 2.8.140916.1 | Last Updated 4 Oct 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100