Click here to Skip to main content
15,883,785 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am creating autocomplete with generic handler successfully. i am l also display first 8 records.I am displaying show more Result link in Autocomplete list.the issue is after clicking show more result link appended next records in to list again again. what is the solution Please reply me.


XML
<link href="Styles/jquery.autocomplete.css" rel="stylesheet" type="text/css" />
    <script src="Scripts/autocomplete/jquery-1.3.2.min.js" type="text/javascript"></script>
    <script src="Scripts/autocomplete/jquery-1.4.1.min.js" type="text/javascript"></script>
    <script src="Scripts/autocomplete/jquery.autocomplete.js" type="text/javascript"></script>
<script type="text/javascript">
    var loggedid = session_login_id;
    jQuery(document).ready(function () {
        jQuery("#txtsearch").autocomplete("Autosearch.ashx?Uid=" + loggedid);

    });
    function textchange() {
        document.getElementById("txtsearch").value = "";
    }





<%@ WebHandler Language="C#" Class="Autosearch" %>


using System;
using MySql.Data.MySqlClient;
using System.Text;
using System.Web;
using System.Configuration;
using System.Data;
public class Autosearch : IHttpHandler {
public string _connectionString = ConfigurationManager.AppSettings["MyWindownew"].ToString();
public void ProcessRequest(HttpContext context)
{
try
{
string searchText = context.Request.QueryString["q"];
if (searchText == " ")
{ searchText = ""; }
string Userids = context.Request.QueryString["Uid"];
//string limit = context.Request.QueryString["lim"];
string str = string.Empty;
searchText = '%' + searchText + '%';
int startlimit = 0;
MySqlConnection con = new MySqlConnection(_connectionString);
con.Open();
MySqlCommand cmd = new MySqlCommand("select t.transaction_id,t.buyer_name,t.buyer_email,t.creation_amount_paid,t.trasaction_time,d.creation_title," +
"c.currency_id,msc.currency_symbol from m_selling_creations_transactions t " +
" left join m_selling_creation d on t.selling_id=d.selling_id " +
" left join m_selling_creation_details c on t.selling_id=c.selling_id " +
" left join m_selling_currency msc on c.currency_id=msc.currency_id where t.buyer_name LIKE @Name or t.buyer_email LIKE @Name and d.userid=@Userids LIMIT @startlimits,8", con);

cmd.Parameters.AddWithValue("@Name", searchText);
cmd.Parameters.AddWithValue("@Userids", Userids);
cmd.Parameters.AddWithValue("@startlimit", startlimit);
StringBuilder sb = new StringBuilder();
string strHH = string.Empty;
using (MySqlDataReader dr = cmd.ExecuteReader())
{
while (dr.Read())
{
if (dr["buyer_name"] != "")
{
DateTime update_date = Convert.ToDateTime(dr["trasaction_time"]);
double timezoediff = Convert.ToDouble(clsDataProperties.strTimeZoneDifference);
timezoediff = timezoediff * -1;
update_date = update_date.AddMinutes(timezoediff);
string date = update_date.ToString("MMM d, yyyy");
strHH = "" +
""+ dr["buyer_name"] + "
" + dr["buyer_email"] + "
" + dr["currency_symbol"] + dr["creation_amount_paid"] + "
" + date+ "
" + dr["creation_title"] + "
" + "   ";
sb.Append(strHH);

}
strHH = "
Show More Result";
}

sb.Append(strHH);

}
if (strHH == "")
{

sb.Append("No match found");
}


con.Close();
context.Response.Write(sb.ToString());
}
catch (Exception ex)
{
}

}

public bool IsReusable {
get {
return false;
}
}

}




<input id="txtsearch" class="search-query span2" placeholder="Search..." type="text" önfocus="javascript:textchange();"
style="width: 170px; position: absolute; top: 30px; left: 185px;" />


















Here is showmoreresult web method


public static string show_more_result(int transactionid)
{
int userid = Convert.ToInt32(HttpContext.Current.Session["LoggedUserId"]);
BAL.clsSellingAnalytics objSellingAnalytics = new BAL.clsSellingAnalytics();
string msg = string.Empty;
string prefixText = string.Empty;
int beginlimit = 0;
beginlimit = beginlimit + 8;
DataTable dt = objSellingAnalytics.showmoreresult(prefixText, userid, transactionid, beginlimit);
//dt.Columns.Add(beginlimit);
StringBuilder sb = new StringBuilder();
string strHH = string.Empty;

foreach (DataRow dr in dt.Rows)
{
DateTime update_date = Convert.ToDateTime(dr["trasaction_time"]);
double timezoediff = Convert.ToDouble(clsDataProperties.strTimeZoneDifference);
timezoediff = timezoediff * -1;
update_date = update_date.AddMinutes(timezoediff);
string date = update_date.ToString("MMM d, yyyy");
strHH = "" +
"" + dr["buyer_name"] + "
" + dr["buyer_email"] + "
" + dr["currency_symbol"] + dr["creation_amount_paid"] + "
" + date + "
" + dr["creation_title"] + "
" + "   ";
sb.Append(strHH).ToString();
}

return sb.Append(strHH).ToString();
}





function showmore(transactionid) {

PageMethods.show_more_result(transactionid, function (response) {

response = response.replace(/(?:\r\n|\r|\n)/g, '
');
alert(response);



public DataTable showmoreresult(string prefixText,int userid, int transactionid, int limit)
{ objDAL.ClearParameters();
objDAL.GetParameter("@userid", userid, "IN");
objDAL.GetParameter("@startlimit", limit, "IN");
objDAL.GetParameter("@transactionid", transactionid, "IN");
prefixText = "%" + prefixText + "%";
objDAL.GetParameter("@Name", prefixText, "IN");
return objDAL.GetTable_AvoidInjection("select t.transaction_id,t.buyer_name,t.buyer_email,t.creation_amount_paid,t.trasaction_time,d.creation_title," +
" c.currency_id,msc.currency_symbol from m_selling_creations_transactions t " +
" left join m_selling_creation d on t.selling_id=d.selling_id " +
" left join m_selling_creation_details c on t.selling_id=c.selling_id " +
" left join m_selling_currency msc on c.currency_id=msc.currency_id where t.buyer_name LIKE @Name or t.buyer_email LIKE @Name and d.userid=@userid and t.transaction_id=@transactionid LIMIT @startlimit,8 ", ref msg);
}
Posted
Updated 21-Jul-14 19:41pm
v2

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900