i seek exact solution for my problem. kindly read below.
we are making txtsearch.text as autocomplete.
so we created search.ashx generic handler file.
code:
<%@ WebHandler Language="C#" Class="Search" %>
using System;
using System.Data.SqlClient;
using System.Text;
using System.Web;
using System.Configuration;
public class Search : IHttpHandler {
public SqlConnection con;
public void ProcessRequest (HttpContext context) {
string searchText = context.Request.QueryString["q"];
// SqlConnection con = new SqlConnection("Data Source=developer;Initial Catalog=ss_db;User Id=sa;Password=.");
string constr = ConfigurationManager.ConnectionStrings["dcon"].ToString();
con = new SqlConnection(constr);
con.Open();
SqlCommand cmd = new SqlCommand("select c_id,author_name,user_image from tbless where author_name Like '%'+@Author +'%'", con);
// SqlCommand cmd = new SqlCommand("select c_id,book_name,user_image from oldb_book_upload where book_name= @Search and author_name=@author", con);
cmd.Parameters.AddWithValue("@Author", searchText);
StringBuilder sb = new StringBuilder();
using (SqlDataReader dr = cmd.ExecuteReader())
{
while (dr.Read())
{
sb.Append(string.Format("{0},{1}{2}", dr["author_name"], dr["user_image"], Environment.NewLine));
}
}
con.Close();
context.Response.Write(sb.ToString());
}
public bool IsReusable {
get {
return false;
}
}
}
and in default.aspx we wrote function:
this is working fine .means all the authors are showing in txtsearch. My problem is when i change the dropdown value to category then it must call another search.ashx generic handler .and in txtsearch only category should show not author.
please suggest
Iftikar HussainPosted Jul 2, 2013, 6:06 AM
You can create one web service and passed more than one parameter as shown below
In your aspx
You can find the attach js and css file
Regards,
Iftikar
saif begPosted Jul 2, 2013, 5:34 AM
is it possible to call different functions based on dropdown selection change. like
dropdown_selectionchanged event
if (dropdown.selecteditemtext=="author"
{
call function1 //
}
else if (dropdown.selecteditemtext=="category"
{
call function 2
}
so in function and function 2 we will write scripts like
kindly suggest
Iftikar HussainPosted Jul 2, 2013, 4:25 AM
Regards,
Iftikar
saif begPosted Jul 2, 2013, 4:10 AM
,[book_name]
,[publish_date]
,[author_name]
,[book_category]
,[book_description]
,[d_dt]
,[user_image]
,[c_language]
,[published_in_books]
FROM [ss_db].[dbo].[tbless]
this is my table.
my here whenver we are pressing any character in txtsearch then scripts is executing.
and in search.ashx handler--
<%@ WebHandler Language="C#" Class="Search" %>
using System;
using System.Data.SqlClient;
using System.Text;
using System.Web;
using System.Configuration;
public class Search : IHttpHandler {
public SqlConnection con;
public void ProcessRequest (HttpContext context) {
string searchText = context.Request.QueryString["q"];
// SqlConnection con = new SqlConnection("Data Source=developer;Initial Catalog=ss_db;User Id=sa;Password=.");
string constr = ConfigurationManager.ConnectionStrings["dcon"].ToString();
con = new SqlConnection(constr);
con.Open();
SqlCommand cmd = new SqlCommand("select c_id,author_name,user_image from tbless where author_name Like '%'+@Author +'%'", con);
// SqlCommand cmd = new SqlCommand("select c_id,book_name,user_image from oldb_book_upload where book_name= @Search and author_name=@author", con);
cmd.Parameters.AddWithValue("@Author", searchText);
StringBuilder sb = new StringBuilder();
using (SqlDataReader dr = cmd.ExecuteReader())
{
while (dr.Read())
{
sb.Append(string.Format("{0},{1}{2}", dr["author_name"], dr["user_image"], Environment.NewLine));
}
}
con.Close();
context.Response.Write(sb.ToString());
}
public bool IsReusable {
get {
return false;
}
}
}
this gives correct result.because its not depending upon the dropdown selection change condition. I need the the result based on the dropdownbox selection change event.
if my dropdownitemtext is "author" then in txtSearch box only author name should show. and if select category from drop down then only category name should show in txtSearch.
Iftikar HussainPosted Jul 2, 2013, 3:36 AM
While doing auto-complete you need to pass the category value also. and depend on that you can write the select query to filter it. Can you tell me how your are passing the txtsearch value to handler from jquery autocomplete?
you can modify the handler after receiving the category value as
string searchText = context.Request.QueryString["q"];
string category= context.Request.QueryString["categoryId"];
// SqlConnection con = new SqlConnection("Data Source=developer;Initial Catalog=ss_db;User Id=sa;Password=.");
string constr = ConfigurationManager.ConnectionStrings["dcon"].ToString();
con = new SqlConnection(constr);
con.Open();
if(category=="Author")
{
SqlCommand cmd = new SqlCommand("select c_id,author_name,user_image from tbless where author_name Like '%'+@Author +'%'", con);
cmd.Parameters.AddWithValue("@Author", searchText);
}
else
{
}
Regards,
Iftikar