ListView paging based on Ajax AutoCompleteExtender result in ASP.Net

Last Reply 5 months ago By pandeyism

Posted 5 months ago

There are 3 scenarios: 1.Search button------>paging is working 2.View button-------->paging is working 3.Autosearch--------->paging is not working. when i click on search button,results are getting displayed.when i wanted to go to next page.it goes. when i click on view button,results are getting displayed.when i wanted to go to next page.it goes. when i autosearch,results are getting displayed.when i wanted to go to next page.it is not going. why it is happening so?

error which i got during autosearch:

https://ibb.co/nN16M8

//Code for Paging using DataPager

    protected void OnPagePropertiesChanging(object sender, PagePropertiesChangingEventArgs e)
    {
        (lstvwproposals.FindControl("DataPager1") as DataPager).SetPageProperties(e.StartRowIndex, e.MaximumRows, false);
        
        if (ViewState["selectList"].Equals("Search"))
        {
            bindlistview();
        }
        else if (ViewState["selectList"].Equals("View"))
        {
            Getviewlist();
        }
        else
        {
            //cmdUpdateField_Click();
           // SearchCustomers(prefixText, count);
           
        }
        
        
    }

 

//Search button code
protected void Button2_Click(object sender, EventArgs e)//search button
    {
        bindlistview();
    }

    protected void bindlistview()
    {
        ViewState["selectList"] = "Search";
        string prefixText = txtsearch.Text;
        MySqlConnection connect = null;
        try
        {
            string connStr = ConfigurationManager.ConnectionStrings["BarterConnectionString"].ToString();
            connect = new MySqlConnection(connStr);
            // string queryStr = "select distinct bp.pro_id,bp.user_id,bu.username,bp.sent_date,bw.name,bp.email_id,bc.comp_name,bc.website,bp.contact_name,bp.proposal_status from barter_proposals bp,barter_company bc,barter_websites bw,barter_userlog bu where bp.company=bc.comp_id and bp.website_a=bw.web_id and bp.user_id=bu.user_id and bc.website like '%" + txtsearch.Text + "%' UNION ALL " +
            //"select distinct bp.pro_id,bp.user_id,bu.username,bp.sent_date,bw.name,bp.email_id,bc.comp_name,bc.website,bp.contact_name,bp.proposal_status from barter_proposals bp,barter_company bc,barter_websites bw,barter_service_exchg bsx,barter_ser_links bsl,barter_userlog bu where bsl.serv_id=bsx.exchg_service_id and bsx.proposal_id=bp.pro_id and bp.company=bc.comp_id and bp.user_id=bu.user_id and bp.website_a=bw.web_id and bsl.link like '%" + txtsearch.Text + "%'";
             string queryStr = "select distinct bp.pro_id,bp.user_id,bu.username,bp.sent_date,bw.name,bp.email_id,bc.comp_name,bc.website,bp.contact_name,bp.proposal_status from barter_proposals bp,barter_company bc,barter_websites bw,barter_service_exchg bsx,barter_ser_links bsl,barter_userlog bu where bsl.serv_id=bsx.exchg_service_id and bsx.proposal_id=bp.pro_id and bp.company=bc.comp_id and bp.user_id=bu.user_id and bp.website_a=bw.web_id and (bsl.link like '%" + txtsearch.Text + "%' OR bc.website like '%" + txtsearch.Text + "%')";//commented by chetan
           // string queryStr = "select comp_id, website from barter_company where website like '%' ?SearchText '%' union " +
   // " select bp.company as comp_id,link as website,bp.pro_id from barter_ser_links bsl,barter_service_exchg bse,barter_proposals bp where bse.exchg_service_id=bsl.serv_id and bse.proposal_id=bp.pro_id and bsl.link like '%' ?SearchText '%' ";
            connect.Open();

            MySqlCommand command = new MySqlCommand(queryStr, connect);
           // command.Parameters.AddWithValue("?SearchText", prefixText);//uncommented by chetan
            MySqlDataReader reader = command.ExecuteReader(CommandBehavior.CloseConnection);
            DataTable dt = new DataTable();
            dt.Load(reader);
            lstvwproposals.DataSource = dt;
            lstvwproposals.DataBind();
            connect.Close();
        }


        catch(Exception ex)
        {
            connect.Close();

        }
    }

 

//View Button Code
	
	 protected void Button3_Click(object sender, EventArgs e)//view button
    {
        Getviewlist();
        ViewState["selectList"] = "View";
    }

    protected void Getviewlist()
    {

        string eventquery = "", compquery = "", comp = "", proquery = "", email = "", emailquery = "", ser_date = "", sentdatequry = "", userquery = "", prostatus = "";
        int eventid = 0, user = 0;
        if (ddlevents.SelectedIndex != 0)
        {
            eventid = Convert.ToInt32(ddlevents.SelectedValue);
            eventquery = " and bea.event_id=?event_id";

        }
        if (txtcomp.Text != "")
        {
            comp = txtcomp.Text;
            compquery = " and bc.comp_name like '%' ?comp '%'";
        }

        if (txtemail.Text != "")
        {
            email = txtemail.Text;
            emailquery = " and bp.email_id like '%' ?emailid '%'";
        }
        if (txtsdate.Text != "")
        {
           
            //DateTime sdate = new DateTime();
            DateTime sdate = Convert.ToDateTime(txtsdate.Text).Date;
           // sdate = DateTime.ParseExact(date, "yyyy-MM-dd", null);
             ser_date = sdate.ToString("yyyy/MM/dd");
            sentdatequry = " and bp.sent_date=?sdate";
        }
        if (ddlpstatus.SelectedIndex != 0)
        {

            prostatus = ddlpstatus.SelectedItem.Text;
            proquery = " and bp.proposal_status=?prostat";

        }
        if (ddlusers.SelectedIndex != 0)
        {

            user = Convert.ToInt32(ddlusers.SelectedValue);
            userquery = " and bp.user_id=?uid";

        }

        MySqlConnection connect = null;
        try
        {
            string connStr = ConfigurationManager.ConnectionStrings["BarterConnectionString"].ToString();
            connect = new MySqlConnection(connStr);
           string queryStr = "select bp.pro_id,bp.sent_date,bw.name,bp.email_id,bc.comp_name,bp.user_id,bc.website,bp.contact_name,bp.proposal_status ,bu.username from barter_proposals bp left join barter_propeventassign bea on  bp.pro_id=bea.prop_id,barter_company bc,barter_websites bw,barter_userlog bu where bp.company=bc.comp_id and bp.website_a=bw.web_id and bp.user_id=bu.user_id " +
            eventquery + compquery + emailquery + sentdatequry + proquery + userquery + " order by bp.pro_id";
            //  string queryStr = "select * from barter_proposals";
            connect.Open();

            MySqlCommand command = new MySqlCommand(queryStr, connect);
            command.Parameters.AddWithValue("?event_id", eventid);
            command.Parameters.AddWithValue("?comp", comp);
            command.Parameters.AddWithValue("?emailid", email);
            command.Parameters.AddWithValue("?sdate", ser_date);
            command.Parameters.AddWithValue("?prostat", prostatus);
            command.Parameters.AddWithValue("?uid", user);
            MySqlDataReader reader = command.ExecuteReader(CommandBehavior.CloseConnection);
            DataTable dt = new DataTable();
            dt.Load(reader);
            lstvwproposals.DataSource = dt;
            lstvwproposals.DataBind();
            connect.Close();
        }

        catch
        {
            connect.Close();

        }
    }
	

 

//Autosearch code
	
	  [System.Web.Script.Services.ScriptMethod()]
    [System.Web.Services.WebMethod]
    public static List<string> SearchCustomers(string prefixText, int count)
    {
       // ViewState["selectList"] = "AutoSearch";
        MySqlConnection connect = null;
        string connStr = ConfigurationManager.ConnectionStrings["BarterConnectionString"].ToString();
        connect = new MySqlConnection(connStr);
        string queryStr = "select comp_id, website from barter_company where website like '%' ?SearchText '%' union "+
        " select bp.company as comp_id,link as website from barter_ser_links bsl,barter_service_exchg bse,barter_proposals bp where bse.exchg_service_id=bsl.serv_id and bse.proposal_id=bp.pro_id and bsl.link like '%' ?SearchText '%' ";
        connect.Open();

        MySqlCommand command = new MySqlCommand(queryStr, connect);
        command.Parameters.AddWithValue("?SearchText", prefixText);
        MySqlDataReader reader = command.ExecuteReader(CommandBehavior.CloseConnection);
        DataTable dt = new DataTable();
        dt.Load(reader);
        List<string> customers = new List<string>();
       
         if (dt.Rows.Count > 0)
         {

             for (int i = 0; i < dt.Rows.Count; i++)
             {
                 string item = AjaxControlToolkit.AutoCompleteExtender.CreateAutoCompleteItem(dt.Rows[i]["website"].ToString(), dt.Rows[i]["comp_id"].ToString());
                 //string item =dt.Rows[i]["website"].ToString();
                 customers.Add(item);
                 
                //customers.CssClass += "selected";
             }
         }

         connect.Close();
         return customers;

    }

 

 

<%@ Page Language="C#" AutoEventWireup="true" MasterPageFile="Site.master" CodeFile="view_proposals.aspx.cs"
    Inherits="view_proposals" %>

<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>
<asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent">
    <script type="text/javascript">
        function ClientItemSelected(sender, e) {
            $get("<%=hfCustomerId.ClientID %>").value = e.get_value();
            document.getElementById("<%=cmdUpdateField.ClientID%>").click();
        }   
    </script>
    <link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery-ui.css"
        rel="stylesheet" type="text/css" />
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script>
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js"></script>
    <script type="text/javascript">
        jQuery.noConflict();
        jQuery(document).ready(function () {
            jQuery(".datepicker").datepicker();

        });
 
 
 
    </script>
    <script type="text/javascript">
        function autoCompleteShow() {
            var elements = document.getElementsByClassName('ulclass');
            for (var i = 0; i < elements.length; i++)
                if (elements[i].innerHTML.search("") != -1)
                    elements[i].style.setProperty("background-color", "#4CC417", "!important");
                else
                    elements[i].style.setProperty("background-color", "Red", "!important");
        }
    </script>
</asp:Content>
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
    <div class="span9">
        <%--<cc1:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server"></asp:ToolkitScriptManager>--%>
        <asp:ScriptManager ID="ScriptManager1" runat="server">
        </asp:ScriptManager>
        <div class="content">
            <div class="module">
                <div class="module-head">
                    <h3>
                        All proposals</h3>
                </div>
                <div class="module-option clearfix">
                    <div id="ajaxdiv" class="input-append pull-left">
                        <%--<input type="text" class="span3" placeholder="Filter by Company/website...">--%>
                        <asp:TextBox ID="txtsearch" placeholder="Filter by website" Width="300px" AutoComplete="off"
                            runat="server"></asp:TextBox>
                        <cc1:AutoCompleteExtender ServiceMethod="SearchCustomers" OnClientShown="autoCompleteShow"
                            CompletionListCssClass="CompletionListCssClass" CompletionListItemCssClass="ulclass"
                            MinimumPrefixLength="2" CompletionInterval="100" EnableCaching="false" CompletionSetCount="10"
                            TargetControlID="txtsearch" ID="AutoCompleteExtender1" BehaviorID="ajaxid" runat="server"
                            FirstRowSelected="false" OnClientItemSelected="ClientItemSelected">
                        </cc1:AutoCompleteExtender>
                        <asp:HiddenField ID="hfCustomerId" runat="server" />
                        &nbsp&nbsp&nbsp
                        <asp:Button ID="Button2" class="btn" runat="server" Text="Search" OnClick="Button2_Click">
                        </asp:Button>
                    </div>
                    <br />
                    <br />
                    <asp:LinkButton CssClass="dnnPrimaryAction" ID="cmdUpdateField" runat="server" Text=""
                        OnClick="cmdUpdateField_Click"></asp:LinkButton>
                    <div class="panel-group" id="accordion">
                        <div class="panel panel-default" style="margin-left: 20px;">
                            <div class="panel-heading">
                                <h4 class="panel-title">
                                    <a data-toggle="collapse" data-parent="#accordion" href="#collapseThree" align="left">
                                        Advance Search</a>
                                </h4>
                            </div>
                            <div id="collapseThree" class="panel-collapse collapse">
                                <div class="panel-body">
                                    <table class="editable">
                                        <tr>
                                            <td>
                                                Exhibition:<br />
                                                <%--<asp:TextBox ID="txtExhibition" runat="server" Width="207px"></asp:TextBox>--%>
                                                <asp:DropDownList ID="ddlevents" runat="server">
                                                </asp:DropDownList>
                                            </td>
                                            <td>
                                                Company:<br />
                                                <asp:TextBox ID="txtcomp" Width="207px" runat="server"></asp:TextBox>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td>
                                                email_id:<br />
                                                <asp:TextBox ID="txtemail" Width="207px" runat="server"></asp:TextBox>
                                            </td>
                                            <td>
                                                Proposal Status:<br />
                                                <asp:DropDownList ID="ddlpstatus" runat="server" Width="207px">
                                                    <%-- <asp:ListItem>Select</asp:ListItem>
                                                  <asp:ListItem>Sent/Recieved</asp:ListItem>
                                                   <asp:ListItem>in-progress</asp:ListItem>
                                                    <asp:ListItem>Converted</asp:ListItem>--%>
                                                </asp:DropDownList>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td>
                                                Sent Date:
                                                <br />
                                                <asp:TextBox ID="txtsdate" class="datepicker" runat="server" Width="207px"></asp:TextBox>
                                            </td>
                                            <td>
                                                User:<br />
                                                <asp:DropDownList ID="ddlusers" runat="server">
                                                </asp:DropDownList>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td>
                                                <asp:Button ID="btnview" class="btn btn-mini btn-info" runat="server" Text="view"
                                                    OnClick="Button3_Click" />
                                            </td>
                                        </tr>
                                    </table>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div>
                        <div>
                            <asp:ListView ID="lstvwproposals" OnPagePropertiesChanging="OnPagePropertiesChanging"
                                OnItemDataBound="ListView1_ItemDataBound" runat="server" DataKeyNames="pro_id">
                                <LayoutTemplate>
                                    <div class="module message">
                                        <div class="module-body table">
                                            <table class="table table-message">
                                                <tbody>
                                                    <tr class="heading">
                                                        <td class="cell-title">
                                                            View
                                                        </td>
                                                        <td class="cell-title">
                                                            Edit
                                                        </td>
                                                        <td class="cell-title">
                                                            sent_date
                                                        </td>
                                                        <%-- <td class="cell-title">Event</td>--%>
                                                        <%--<th  >Website/Directory(a)</th>--%>
                                                        <td class="cell-title">
                                                            User
                                                        </td>
                                                        <%-- <td class="cell-title" >Company</td>  --%>
                                                        <td class="cell-title">
                                                            Website(b)
                                                        </td>
                                                        <td class="cell-title">
                                                            Website(a)
                                                        </td>
                                                        <td class="cell-title">
                                                            Proposal Status
                                                        </td>
                                                    </tr>
                                                    <tr id="itemPlaceholder" runat="server" />
                                                    <tr id="Tr1" runat="server" align="center">
                                                        <td colspan="2" align="left">
                                                            <asp:Label ID="lblCount" runat="server"></asp:Label>
                                                        </td>
                                                        <td id="Td1" runat="server" style="" colspan="4">
                                                            <asp:DataPager class="mpart" ID="DataPager1" PageSize="12" runat="server">
                                                                <Fields>
                                                                    <asp:NumericPagerField ButtonType="Link" ButtonCount="3" PreviousPageText="<<<" NextPageText=">>>" />
                                                                </Fields>
                                                            </asp:DataPager>
                                                        </td>
                                                        <td colspan="2" align="left">
                                                        </td>
                                                    </tr>
                                                    <tbody>
                                            </table>
                                        </div>
                                    </div>
                                </LayoutTemplate>
                                <ItemTemplate>
                                    <tr class="unread">
                                        <td class="command">
                                            <asp:LinkButton ID="HyperLink1" runat="server" OnCommand="getview" Text="view" CommandArgument='<%# Eval("pro_id")%>'
                                                CssClass="linkEditButton" Font-Underline="True" />
                                        </td>
                                        <td class="command">
                                            <asp:LinkButton OnCommand="getedit" ID="btnEdit" runat="server" Text="Edit" CommandArgument='<%# Eval("pro_id")%>'
                                                CssClass="linkEditButton" Font-Underline="True" />
                                        </td>
                                        <td class="cell-title">
                                            <%# Eval("sent_date", "{0:dd-MM-yyyy}")%>
                                        </td>
                                        <%--  <td ><%# Eval("event_name")%></td>--%>
                                        <%--  <td ><%# Eval("name")%></td>--%>
                                        <td class="cell-title">
                                            <%# Eval("username")%>
                                        </td>
                                        <%--<td class="cell-title"><%# Eval("comp_name")%></td>--%>
                                        <td class="cell-title">
                                            <%# Eval("website")%>
                                        </td>
                                        <td class="cell-title">
                                            <%# Eval("name")%>
                                        </td>
                                        <%--<td class="cell-title"><%# Eval("contact_name")%></td>--%>
                                        <td class="cell-title">
                                            <%# Eval("proposal_status")%>
                                        </td>
                                    </tr>
                                </ItemTemplate>
                                <AlternatingItemTemplate>
                                    <tr class="unread">
                                        <td class="command">
                                            <asp:LinkButton ID="HyperLink1" runat="server" OnCommand="getview" Text="view" CommandArgument='<%# Eval("pro_id")%>'
                                                CssClass="linkEditButton" Font-Underline="True" />
                                        </td>
                                        <td class="command">
                                            <asp:LinkButton OnCommand="getedit" ID="btnEdit" CommandArgument='<%# Eval("pro_id")%>'
                                                runat="server" Text="Edit" Font-Underline="True" />
                                        </td>
                                        <td>
                                            <%# Eval("sent_date", "{0:dd-MM-yyyy}")%>
                                        </td>
                                        <%--  <td ><%# Eval("event_name")%></td>--%>
                                        <%-- <td ><%# Eval("name")%></td>--%>
                                        <td class="cell-title">
                                            <%# Eval("username")%>
                                        </td>
                                        <%-- <td class="cell-title"><%# Eval("comp_name")%></td>--%>
                                        <td class="cell-title">
                                            <%# Eval("website")%>
                                        </td>
                                        <td class="cell-title">
                                            <%# Eval("name")%>
                                        </td>
                                        <%--<td class="cell-title"><%# Eval("contact_name")%></td>--%>
                                        <td class="cell-title">
                                            <%# Eval("proposal_status")%>
                                        </td>
                                    </tr>
                                </AlternatingItemTemplate>
                                <EmptyDataTemplate>
                                    <div style="text-align: center; font-weight: bold">
                                        0 Results Founds</div>
                                </EmptyDataTemplate>
                            </asp:ListView>
                            <br />
                        </div>
                    </div>
                    <%-- <asp:Button ID="Button1" class="btn btn-danger" runat="server" Text="Export" />--%>
                </div>
            </div>
        </div>
    </div>
</asp:Content>

 

You are viewing reply posted by: pandeyism 5 months ago.
Posted 5 months ago

Hi chetan,

Please refer below sample.

HTML

<div>
    <div class="span9">
        <asp:ScriptManager ID="ScriptManager1" runat="server">
        </asp:ScriptManager>
        <div class="content">
            <div class="module">
                <div class="module-head">
                    <h3>
                        All proposals</h3>
                </div>
                <div class="module-option clearfix">
                    <div id="ajaxdiv" class="input-append pull-left">
                        <asp:TextBox ID="txtsearch" placeholder="Filter by website" Width="300px" AutoComplete="off"
                            runat="server"></asp:TextBox>
                        <cc1:AutoCompleteExtender ServiceMethod="SearchCustomers" OnClientShown="autoCompleteShow"
                            CompletionListCssClass="CompletionListCssClass" CompletionListItemCssClass="ulclass"
                            MinimumPrefixLength="2" CompletionInterval="100" EnableCaching="false" CompletionSetCount="10"
                            TargetControlID="txtsearch" ID="AutoCompleteExtender1" BehaviorID="ajaxid" runat="server"
                            FirstRowSelected="false" OnClientItemSelected="ClientItemSelected">
                        </cc1:AutoCompleteExtender>
                        <asp:HiddenField ID="hfCustomerId" runat="server" />
                        &nbsp&nbsp&nbsp
                        <asp:Button ID="Button2" class="btn" runat="server" Text="Search" OnClick="Button2_Click">
                        </asp:Button>
                    </div>
                    <br />
                    <br />
                    <asp:LinkButton CssClass="dnnPrimaryAction" ID="cmdUpdateField" runat="server" Text=""
                        OnClick="cmdUpdateField_Click"></asp:LinkButton>
                    <div class="panel-group" id="accordion">
                        <div class="panel panel-default" style="margin-left: 20px;">
                            <div class="panel-heading">
                                <h4 class="panel-title">
                                    <a data-toggle="collapse" data-parent="#accordion" href="#collapseThree" align="left">
                                        Advance Search</a>
                                </h4>
                            </div>
                            <div id="collapseThree" class="panel-collapse collapse">
                            </div>
                        </div>
                    </div>
                    <div>
                        <div>
                            <asp:ListView ID="lstvwproposals" OnPagePropertiesChanging="OnPagePropertiesChanging"
                                OnItemDataBound="ListView1_ItemDataBound" runat="server" DataKeyNames="CustomerId">
                                <LayoutTemplate>
                                    <div class="module message">
                                        <div class="module-body table">
                                            <table class="table table-message">
                                                <tbody>
                                                    <tr class="heading">
                                                        <td class="cell-title">
                                                            View
                                                        </td>
                                                        <td class="cell-title">
                                                            Edit
                                                        </td>
                                                        <td class="cell-title">
                                                            sent_date
                                                        </td>
                                                        <td class="cell-title">
                                                            User
                                                        </td>
                                                        <td class="cell-title">
                                                            Website(b)
                                                        </td>
                                                        <td class="cell-title">
                                                            Website(a)
                                                        </td>
                                                        <td class="cell-title">
                                                            Proposal Status
                                                        </td>
                                                    </tr>
                                                    <tr id="itemPlaceholder" runat="server" />
                                                    <tr id="Tr1" runat="server" align="center">
                                                        <td colspan="2" align="left">
                                                            <asp:Label ID="lblCount" runat="server"></asp:Label>
                                                        </td>
                                                        <td id="Td1" runat="server" style="" colspan="4">
                                                            <asp:DataPager class="mpart" ID="DataPager1" PageSize="1" runat="server">
                                                                <Fields>
                                                                    <asp:NumericPagerField ButtonType="Link" ButtonCount="3" PreviousPageText="<<<" NextPageText=">>>" />
                                                                </Fields>
                                                            </asp:DataPager>
                                                        </td>
                                                        <td colspan="2" align="left">
                                                        </td>
                                                    </tr>
                                                    <tbody>
                                            </table>
                                        </div>
                                    </div>
                                </LayoutTemplate>
                                <ItemTemplate>
                                    <tr class="unread">
                                        <td class="command">
                                            <asp:LinkButton ID="HyperLink1" runat="server" OnCommand="getview" Text="view" CommandArgument='<%# Eval("CustomerId")%>'
                                                CssClass="linkEditButton" Font-Underline="True" />
                                        </td>
                                        <td class="command">
                                            <asp:LinkButton OnCommand="getedit" ID="btnEdit" runat="server" Text="Edit" CommandArgument='<%# Eval("CustomerId")%>'
                                                CssClass="linkEditButton" Font-Underline="True" />
                                        </td>
                                        <td class="cell-title">
                                            <%# Eval("ContactName")%>
                                        </td>
                                        <td class="cell-title">
                                            <%# Eval("Country")%>
                                        </td>
                                        <td class="cell-title">
                                            <%# Eval("City")%>
                                        </td>
                                        <td class="cell-title">
                                            <%# Eval("Phone")%>
                                        </td>
                                        <td class="cell-title">
                                            <%# Eval("Address")%>
                                        </td>
                                    </tr>
                                </ItemTemplate>
                                <AlternatingItemTemplate>
                                    <tr class="unread">
                                        <td class="command">
                                            <asp:LinkButton ID="HyperLink1" runat="server" OnCommand="getview" Text="view" CommandArgument='<%# Eval("CustomerId")%>'
                                                CssClass="linkEditButton" Font-Underline="True" />
                                        </td>
                                        <td class="command">
                                            <asp:LinkButton OnCommand="getedit" ID="btnEdit" CommandArgument='<%# Eval("CustomerId")%>'
                                                runat="server" Text="Edit" Font-Underline="True" />
                                        </td>
                                        <td>
                                            <%# Eval("ContactName")%>
                                        </td>
                                        <td class="cell-title">
                                            <%# Eval("Country")%>
                                        </td>
                                        <td class="cell-title">
                                            <%# Eval("City")%>
                                        </td>
                                        <td class="cell-title">
                                            <%# Eval("Phone")%>
                                        </td>
                                        <td class="cell-title">
                                            <%# Eval("Address")%>
                                        </td>
                                    </tr>
                                </AlternatingItemTemplate>
                                <EmptyDataTemplate>
                                    <div style="text-align: center; font-weight: bold">
                                        0 Results Founds</div>
                                </EmptyDataTemplate>
                            </asp:ListView>
                            <br />
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
    <link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery-ui.css"
    rel="stylesheet" type="text/css" />
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js"></script>
<script type="text/javascript">
    function autoCompleteShow() {
        var elements = document.getElementsByClassName('#ulclass');
        for (var i = 0; i < elements.length; i++)
            if (elements[i].innerHTML.search("") != -1)
                elements[i].style.setProperty("background-color", "#4CC417", "!important");
            else
                elements[i].style.setProperty("background-color", "Red", "!important");
    }
</script>
<script type="text/javascript">
    function ClientItemSelected(sender, e) {
        $get("<%=hfCustomerId.ClientID %>").value = e.get_value();
        document.getElementById("<%=cmdUpdateField.ClientID%>").click();
    }
</script>

Namespaces

C#

using System.Data;
using System.Data.SqlClient;
using System.Configuration;

Vb.Net

Imports System.Data.SqlClient
Imports System.Data

Code

C#

protected void Page_Load(object sender, EventArgs e)
{
    if (!this.IsPostBack)
    {
        this.BindListView();
    }
}

private void BindListView()
{
    string constr = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
    using (SqlConnection con = new SqlConnection(constr))
    {
        using (SqlCommand cmd = new SqlCommand())
        {
            cmd.CommandText = "SELECT CustomerId, ContactName, City, Phone ,Country, Address FROM Customers";
            cmd.Connection = con;
            using (SqlDataAdapter sda = new SqlDataAdapter(cmd))
            {
                DataTable dt = new DataTable();
                sda.Fill(dt);
                lstvwproposals.DataSource = dt;
                lstvwproposals.DataBind();
            }
        }
    }
}

protected void Button2_Click(object sender, EventArgs e)
{
    this.Search();
}

private void Search()
{
    string constr = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
    using (SqlConnection con = new SqlConnection(constr))
    {
        using (SqlCommand cmd = new SqlCommand())
        {
            cmd.CommandText = "SELECT CustomerId, ContactName, City, Phone ,Country, Address FROM Customers  WHERE ContactName LIKE @ContactName + '%'";
            cmd.Connection = con;
            using (SqlDataAdapter sda = new SqlDataAdapter(cmd))
            {
                cmd.Parameters.AddWithValue("@ContactName", txtsearch.Text.Trim());
                DataTable dt = new DataTable();
                sda.Fill(dt);
                lstvwproposals.DataSource = dt;
                lstvwproposals.DataBind();
            }
        }
    }
}

protected void Button3_Click(object sender, EventArgs e)
{

}

protected void cmdUpdateField_Click(object sender, EventArgs e)
{

}

protected void linkEditButton(object sender, EventArgs e)
{

}

protected void getedit(object sender, EventArgs e)
{

}

protected void getview(object sender, EventArgs e)
{

}

protected void ListView1_ItemDataBound(object sender, ListViewItemEventArgs e)
{

}

protected void OnPagePropertiesChanging(object sender, PagePropertiesChangingEventArgs e)
{
    (lstvwproposals.FindControl("DataPager1") as DataPager).SetPageProperties(e.StartRowIndex, e.MaximumRows, false);
    this.Search();
}

[System.Web.Script.Services.ScriptMethod()]
[System.Web.Services.WebMethod]
public static List<string> SearchCustomers(string prefixText, int count)
{     
    string connStr = ConfigurationManager.ConnectionStrings["constr"].ToString();
    SqlConnection con = new SqlConnection(connStr);
    SqlCommand cmd = new SqlCommand("SELECT CustomerId, ContactName, City, Phone ,Country, Address FROM Customers  WHERE ContactName LIKE @ContactName + '%'",con);
        con.Open();
        cmd.Parameters.AddWithValue("@ContactName", prefixText);
        SqlDataReader reader = cmd.ExecuteReader(CommandBehavior.CloseConnection);
        DataTable dt = new DataTable();
        dt.Load(reader);
        List<string> customers = new List<string>();

        if (dt.Rows.Count > 0)
        {

            for (int i = 0; i < dt.Rows.Count; i++)
            {
                string item = AjaxControlToolkit.AutoCompleteExtender.CreateAutoCompleteItem(dt.Rows[i]["ContactName"].ToString(), dt.Rows[i]["CustomerId"].ToString());
                customers.Add(item);
            }
        }
        con.Close();
        return customers;

}

 Vb.Net

Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
    If Not Me.IsPostBack Then
        Me.BindListView()
    End If
End Sub

Private Sub BindListView()
    Dim constr As String = ConfigurationManager.ConnectionStrings("constr").ConnectionString
    Using con As SqlConnection = New SqlConnection(constr)
        Using cmd As SqlCommand = New SqlCommand()
            cmd.CommandText = "SELECT CustomerId, ContactName, City, Phone ,Country, Address FROM Customers"
            cmd.Connection = con
            Using sda As SqlDataAdapter = New SqlDataAdapter(cmd)
                Dim dt As DataTable = New DataTable()
                sda.Fill(dt)
                lstvwproposals.DataSource = dt
                lstvwproposals.DataBind()
            End Using
        End Using
    End Using
End Sub

Protected Sub Button2_Click(ByVal sender As Object, ByVal e As EventArgs)
    Me.Search()
End Sub

Private Sub Search()
    Dim constr As String = ConfigurationManager.ConnectionStrings("constr").ConnectionString
    Using con As SqlConnection = New SqlConnection(constr)
        Using cmd As SqlCommand = New SqlCommand()
            cmd.CommandText = "SELECT CustomerId, ContactName, City, Phone ,Country, Address FROM Customers  WHERE ContactName LIKE @ContactName + '%'"
            cmd.Connection = con
            Using sda As SqlDataAdapter = New SqlDataAdapter(cmd)
                cmd.Parameters.AddWithValue("@ContactName", txtsearch.Text.Trim())
                Dim dt As DataTable = New DataTable()
                sda.Fill(dt)
                lstvwproposals.DataSource = dt
                lstvwproposals.DataBind()
            End Using
        End Using
    End Using
End Sub

Protected Sub Button3_Click(ByVal sender As Object, ByVal e As EventArgs)
End Sub

Protected Sub cmdUpdateField_Click(ByVal sender As Object, ByVal e As EventArgs)
End Sub

Protected Sub linkEditButton(ByVal sender As Object, ByVal e As EventArgs)
End Sub

Protected Sub getedit(ByVal sender As Object, ByVal e As EventArgs)
End Sub

Protected Sub getview(ByVal sender As Object, ByVal e As EventArgs)
End Sub

Protected Sub ListView1_ItemDataBound(ByVal sender As Object, ByVal e As ListViewItemEventArgs)
End Sub

Protected Sub OnPagePropertiesChanging(ByVal sender As Object, ByVal e As PagePropertiesChangingEventArgs)
    TryCast(lstvwproposals.FindControl("DataPager1"), DataPager).SetPageProperties(e.StartRowIndex, e.MaximumRows, False)
    Me.Search()
End Sub

<System.Web.Script.Services.ScriptMethod()>
<System.Web.Services.WebMethod()>
Public Shared Function SearchCustomers(ByVal prefixText As String, ByVal count As Integer) As List(Of String)
    Dim connStr As String = ConfigurationManager.ConnectionStrings("constr").ToString()
    Dim con As SqlConnection = New SqlConnection(connStr)
    Dim cmd As SqlCommand = New SqlCommand("SELECT CustomerId, ContactName, City, Phone ,Country, Address FROM Customers  WHERE ContactName LIKE @ContactName + '%'", con)
    con.Open()
    cmd.Parameters.AddWithValue("@ContactName", prefixText)
    Dim reader As SqlDataReader = cmd.ExecuteReader(CommandBehavior.CloseConnection)
    Dim dt As DataTable = New DataTable()
    dt.Load(reader)
    Dim customers As List(Of String) = New List(Of String)()

    If dt.Rows.Count > 0 Then
        For i As Integer = 0 To dt.Rows.Count - 1
            Dim item As String = AjaxControlToolkit.AutoCompleteExtender.CreateAutoCompleteItem(dt.Rows(i)("ContactName").ToString(), dt.Rows(i)("CustomerId").ToString())
            customers.Add(item)
        Next
    End If
    con.Close()
    Return customers
End Function

Screenshot