Link to home
Start Free TrialLog in
Avatar of Jay
Jay

asked on

Search not working when button is clicked

It does not show the searched items when I type in a name.

What I did to search for aspx
 <input type="text" class="field" id="searchtextbox"/>
 <input type ="button" class="search-submit" value="Search" onclick="search();"/>
 <script type ="text/javascript">
            function search() {
                window.location = "Events.aspx?search=" + document.getElementById("searchtextbox").value;
            }  
        </script> 

Open in new window

Code behind. Those bolded are what I did to search
protected void Page_Load(object sender, EventArgs e)
    {
        SqlConnection con = new SqlConnection(_connStr);
        con.Open();
        SqlCommand cmd = con.CreateCommand();
        // event types
        string sql = "Select * from [EventType] order by 1";
    cmd.CommandText=sql;
      DataTable dtet = new DataTable();
    SqlDataAdapter daet = new SqlDataAdapter(cmd);
    daet.Fill(dtet);
      dd.DataSource = dtet;
      dd.DataBind();

      // events
      int EventTypeID = 0;
      if (Request.QueryString["type"] != null)
        EventTypeID = Convert.ToInt32(Request.QueryString["type"].ToString());
      if (EventTypeID == 0)
        sql = "select * from EventDetail order by EventDetail_ID";
      else
        sql = "select * from EventDetail where EventType_ID=" + EventTypeID.ToString() + " order by EventDetail_ID";

   if(Request.QueryString["type"] != null && Request.QueryString["search"] != null)
        {
            sql = "select * from EventDetail where =eventDetailName like('% " + Request.QueryString["search"].ToString() + "%')";

        }

        cmd.CommandText=sql;
      DataTable dte = new DataTable();
    SqlDataAdapter dae = new SqlDataAdapter(cmd);
    dae.Fill(dte);
          d1.DataSource = dte;
          d1.DataBind();
          con.Close();
    }
ASKER CERTIFIED SOLUTION
Avatar of Albert Van Halen
Albert Van Halen
Flag of Netherlands image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Jay
Jay

ASKER

idk why but it works now?!!? thanks for yr help btw
The url for submitting your search request is Events.aspx?search={criteria}
The querystring parameter search is set and you can use that in code behind (Request.QueryString["search"])
You are also checking if the querystring parameter type is not null, but that is not part of the search url; therefore not showing the results...