danielivanov2
asked on
Using Jquery AutoComplete to filter GridView data asp.net 2.0
I'm unable to use for the moment ajaxtoolkit (for 2.0), so I need to implement jquery autocomplete functionality to filter my gridview data (using solution described here
Using code attached, the interface does not generate list values (although the data source is ok - stringbuilder contains data) and I don't how to capture the user selected value, in order to filter my gridview (a webservice perhaps?)
In Firebug, GET is ok, but in GETs' XML tab there is an error:"XML Parsing Error: no element found Location: moz-nullprincipal:{f199a47 1-4b31-483 8-be33-e3a b76de4cee} Line Number 1, Column 1:"
Thanks
Using code attached, the interface does not generate list values (although the data source is ok - stringbuilder contains data) and I don't how to capture the user selected value, in order to filter my gridview (a webservice perhaps?)
In Firebug, GET is ok, but in GETs' XML tab there is an error:"XML Parsing Error: no element found Location: moz-nullprincipal:{f199a47
Thanks
aspx:
<asp:Content
ID="Content1"
ContentPlaceHolderID="head"
Runat="Server">
<link href="../CSS/Clienti.css" rel="stylesheet" type="text/css" />
<link href="../CSS/jquery-ui-187custom.css" rel="stylesheet" type="text/css" />
<link href="../CSS/jquery.autocomplete.css" rel="stylesheet" type="text/css" />
<script src="../Scripts/jquery-144min.js" type="text/javascript"></script>
<script src="../Scripts/jquery-ui-182custommin.js" type="text/javascript"></script>
<script src="../Scripts/jquery.autocomplete.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function() {
$("#<%=txtSearch.ClientID%>").autocomplete('Baza.ashx');
});
<asp:TextBox ID="txtSearch" runat="server"></asp:TextBox>
----------------------------------------
aspx.cs:
using (sqlConn)
{
using (SqlCommand cmd = new SqlCommand("prc_SearchCustomer"))
{
DataTable dt = new DataTable();
SqlDataAdapter da = new SqlDataAdapter();
da.SelectCommand = cmd;
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@SearchCriteria", "Nume companie");
cmd.Parameters.AddWithValue("@SearchString", "%");
cmd.Parameters.Add("@UserName", Session["UserName"].ToString());
cmd.Connection = sqlConn;
sqlConn.Open();
cmd.ExecuteReader();
sqlConn.Close();
da.Fill(dt);
//store table in Session
Session["BaseCustomerList"] = dt;
ResultsGridView.DataSource = dt;
ResultsGridView.DataBind();
}
}
------------------------------------
ashx:
public class Baza : IHttpHandler, System.Web.SessionState.IRequiresSessionState
{
public void ProcessRequest (HttpContext context)
{
string searchText = context.Request.QueryString["q"];
StringBuilder sb = new StringBuilder();
if (HttpContext.Current.Session["BaseCustomerList"] != null)
{
DataTable dt = (DataTable)HttpContext.Current.Session["BaseCustomerList"];
foreach (DataRow dr in dt.Select("Company_Name LIKE '" + searchText + "%'"))
{
sb.Append(dr["Company_Name"])
.Append(Environment.NewLine);
}
}
}
public bool IsReusable {
get {
return false;
}
}
}
ASKER
Params and Headers ok (status 200), Response: null
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I'm trying to implement it as attached, but the error is:
Error 7 'Baza' does not implement interface member 'System.Web.IHttpHandler.P rocessRequ est(System .Web.HttpC ontext)'. 'Baza.ProcessRequest(Syste m.Web.Http Context)' is either static, not public, or has the wrong return type.
Error 7 'Baza' does not implement interface member 'System.Web.IHttpHandler.P
public string ProcessRequest (HttpContext context)
{
string searchText = context.Request.QueryString["q"];
StringBuilder sb = new StringBuilder();
if (HttpContext.Current.Session["BaseCustomerList"] != null)
{
DataTable dt = (DataTable)HttpContext.Current.Session["BaseCustomerList"];
foreach (DataRow dr in dt.Select("Company_Name LIKE '" + searchText + "%'"))
{
sb.Append(dr["Company_Name"])
.Append(Environment.NewLine);
}
}
return sb.ToString();
}
ASKER
got it, it was missing "context.Response.Write(sb .ToString( ));"
now, after selecting an item from autocomplete list, how should I use it to filter the gridview?
now, after selecting an item from autocomplete list, how should I use it to filter the gridview?
ASKER
I just need the jquery script/function that can pass the selected result to server, in order to filter the gridview's datatable source
ASKER
Feedback: Answers delayed for long time
ASKER
The answer for my last question was detalied here. Thanks anyway for the rest!
Gary Davis