?
Solved

Using Jquery AutoComplete to filter GridView data asp.net 2.0

Posted on 2011-02-20
9
Medium Priority
?
2,331 Views
Last Modified: 2012-05-11
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:{f199a471-4b31-4838-be33-e3ab76de4cee} Line Number 1, Column 1:"

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;
        }
    }
}

Open in new window

0
Comment
Question by:danielivanov2
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 2
9 Comments
 
LVL 18

Expert Comment

by:Gary Davis
ID: 34938198
Usually, the XML Parse error is due to the Ajax request not returning xml and instead, returning an HTML error message. You say the GET is OK but verify the data returned. Go to the Ajax request from your browser to view the xml returned is as expected (view source if necessary) and not and error page.

Gary Davis
0
 

Author Comment

by:danielivanov2
ID: 34940454
Params and Headers ok (status 200), Response: null
0
 
LVL 18

Accepted Solution

by:
Gary Davis earned 1500 total points
ID: 35040304
I looked at it again - your sb variable is built up but not returned to the caller of the ashx.

    public void ProcessRequest

You need to return this data in the format needed by the autocomplete.
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

Author Comment

by:danielivanov2
ID: 35069461
I'm trying to implement it as attached, but the error is:

Error      7      'Baza' does not implement interface member 'System.Web.IHttpHandler.ProcessRequest(System.Web.HttpContext)'. 'Baza.ProcessRequest(System.Web.HttpContext)' is either static, not public, or has the wrong return type.      

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();
    }

Open in new window

0
 

Author Comment

by:danielivanov2
ID: 35069707
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?
0
 

Author Comment

by:danielivanov2
ID: 35069812
I just need the jquery script/function that can pass the selected result to server, in order to filter the gridview's datatable source
0
 

Author Closing Comment

by:danielivanov2
ID: 35079458
Feedback: Answers delayed for long time
0
 

Author Comment

by:danielivanov2
ID: 35079467
The answer for my last question was detalied here. Thanks anyway for the rest!
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…

649 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question