ASPForums.Net RSS Feedhttp://www.aspforums.net/Handlers/RSS.ashxLatest additions to the content that appears on ASPForums.Net(c) 2019 www.aspforums.com. All rights reserved.ListView paging based on Ajax AutoCompleteExtender result in ASP.Net<p>Hi <a class="username" rel="chetan">chetan</a>,</p> <p>Please refer below sample.</p> <p><span style="text-decoration: underline;"><strong>HTML</strong></span></p> <pre class="brush: html">&lt;div&gt; &lt;div class=&#34;span9&#34;&gt; &lt;asp:ScriptManager ID=&#34;ScriptManager1&#34; runat=&#34;server&#34;&gt; &lt;/asp:ScriptManager&gt; &lt;div class=&#34;content&#34;&gt; &lt;div class=&#34;module&#34;&gt; &lt;div class=&#34;module-head&#34;&gt; &lt;h3&gt; All proposals&lt;/h3&gt; &lt;/div&gt; &lt;div class=&#34;module-option clearfix&#34;&gt; &lt;div id=&#34;ajaxdiv&#34; class=&#34;input-append pull-left&#34;&gt; &lt;asp:TextBox ID=&#34;txtsearch&#34; placeholder=&#34;Filter by website&#34; Width=&#34;300px&#34; AutoComplete=&#34;off&#34; runat=&#34;server&#34;&gt;&lt;/asp:TextBox&gt; &lt;cc1:AutoCompleteExtender ServiceMethod=&#34;SearchCustomers&#34; OnClientShown=&#34;autoCompleteShow&#34; CompletionListCssClass=&#34;CompletionListCssClass&#34; CompletionListItemCssClass=&#34;ulclass&#34; MinimumPrefixLength=&#34;2&#34; CompletionInterval=&#34;100&#34; EnableCaching=&#34;false&#34; CompletionSetCount=&#34;10&#34; TargetControlID=&#34;txtsearch&#34; ID=&#34;AutoCompleteExtender1&#34; BehaviorID=&#34;ajaxid&#34; runat=&#34;server&#34; FirstRowSelected=&#34;false&#34; OnClientItemSelected=&#34;ClientItemSelected&#34;&gt; &lt;/cc1:AutoCompleteExtender&gt; &lt;asp:HiddenField ID=&#34;hfCustomerId&#34; runat=&#34;server&#34; /&gt; &amp;nbsp&amp;nbsp&amp;nbsp &lt;asp:Button ID=&#34;Button2&#34; class=&#34;btn&#34; runat=&#34;server&#34; Text=&#34;Search&#34; OnClick=&#34;Button2_Click&#34;&gt; &lt;/asp:Button&gt; &lt;/div&gt; &lt;br /&gt; &lt;br /&gt; &lt;asp:LinkButton CssClass=&#34;dnnPrimaryAction&#34; ID=&#34;cmdUpdateField&#34; runat=&#34;server&#34; Text=&#34;&#34; OnClick=&#34;cmdUpdateField_Click&#34;&gt;&lt;/asp:LinkButton&gt; &lt;div class=&#34;panel-group&#34; id=&#34;accordion&#34;&gt; &lt;div class=&#34;panel panel-default&#34; style=&#34;margin-left: 20px;&#34;&gt; &lt;div class=&#34;panel-heading&#34;&gt; &lt;h4 class=&#34;panel-title&#34;&gt; &lt;a data-toggle=&#34;collapse&#34; data-parent=&#34;#accordion&#34; href=&#34;#collapseThree&#34; align=&#34;left&#34;&gt; Advance Search&lt;/a&gt; &lt;/h4&gt; &lt;/div&gt; &lt;div id=&#34;collapseThree&#34; class=&#34;panel-collapse collapse&#34;&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;div&gt; &lt;div&gt; &lt;asp:ListView ID=&#34;lstvwproposals&#34; OnPagePropertiesChanging=&#34;OnPagePropertiesChanging&#34; OnItemDataBound=&#34;ListView1_ItemDataBound&#34; runat=&#34;server&#34; DataKeyNames=&#34;CustomerId&#34;&gt; &lt;LayoutTemplate&gt; &lt;div class=&#34;module message&#34;&gt; &lt;div class=&#34;module-body table&#34;&gt; &lt;table class=&#34;table table-message&#34;&gt; &lt;tbody&gt; &lt;tr class=&#34;heading&#34;&gt; &lt;td class=&#34;cell-title&#34;&gt; View &lt;/td&gt; &lt;td class=&#34;cell-title&#34;&gt; Edit &lt;/td&gt; &lt;td class=&#34;cell-title&#34;&gt; sent_date &lt;/td&gt; &lt;td class=&#34;cell-title&#34;&gt; User &lt;/td&gt; &lt;td class=&#34;cell-title&#34;&gt; Website(b) &lt;/td&gt; &lt;td class=&#34;cell-title&#34;&gt; Website(a) &lt;/td&gt; &lt;td class=&#34;cell-title&#34;&gt; Proposal Status &lt;/td&gt; &lt;/tr&gt; &lt;tr id=&#34;itemPlaceholder&#34; runat=&#34;server&#34; /&gt; &lt;tr id=&#34;Tr1&#34; runat=&#34;server&#34; align=&#34;center&#34;&gt; &lt;td colspan=&#34;2&#34; align=&#34;left&#34;&gt; &lt;asp:Label ID=&#34;lblCount&#34; runat=&#34;server&#34;&gt;&lt;/asp:Label&gt; &lt;/td&gt; &lt;td id=&#34;Td1&#34; runat=&#34;server&#34; style=&#34;&#34; colspan=&#34;4&#34;&gt; &lt;asp:DataPager class=&#34;mpart&#34; ID=&#34;DataPager1&#34; PageSize=&#34;1&#34; runat=&#34;server&#34;&gt; &lt;Fields&gt; &lt;asp:NumericPagerField ButtonType=&#34;Link&#34; ButtonCount=&#34;3&#34; PreviousPageText=&#34;&lt;&lt;&lt;&#34; NextPageText=&#34;&gt;&gt;&gt;&#34; /&gt; &lt;/Fields&gt; &lt;/asp:DataPager&gt; &lt;/td&gt; &lt;td colspan=&#34;2&#34; align=&#34;left&#34;&gt; &lt;/td&gt; &lt;/tr&gt; &lt;tbody&gt; &lt;/table&gt; &lt;/div&gt; &lt;/div&gt; &lt;/LayoutTemplate&gt; &lt;ItemTemplate&gt; &lt;tr class=&#34;unread&#34;&gt; &lt;td class=&#34;command&#34;&gt; &lt;asp:LinkButton ID=&#34;HyperLink1&#34; runat=&#34;server&#34; OnCommand=&#34;getview&#34; Text=&#34;view&#34; CommandArgument=&#39;&lt;%# Eval(&#34;CustomerId&#34;)%&gt;&#39; CssClass=&#34;linkEditButton&#34; Font-Underline=&#34;True&#34; /&gt; &lt;/td&gt; &lt;td class=&#34;command&#34;&gt; &lt;asp:LinkButton OnCommand=&#34;getedit&#34; ID=&#34;btnEdit&#34; runat=&#34;server&#34; Text=&#34;Edit&#34; CommandArgument=&#39;&lt;%# Eval(&#34;CustomerId&#34;)%&gt;&#39; CssClass=&#34;linkEditButton&#34; Font-Underline=&#34;True&#34; /&gt; &lt;/td&gt; &lt;td class=&#34;cell-title&#34;&gt; &lt;%# Eval(&#34;ContactName&#34;)%&gt; &lt;/td&gt; &lt;td class=&#34;cell-title&#34;&gt; &lt;%# Eval(&#34;Country&#34;)%&gt; &lt;/td&gt; &lt;td class=&#34;cell-title&#34;&gt; &lt;%# Eval(&#34;City&#34;)%&gt; &lt;/td&gt; &lt;td class=&#34;cell-title&#34;&gt; &lt;%# Eval(&#34;Phone&#34;)%&gt; &lt;/td&gt; &lt;td class=&#34;cell-title&#34;&gt; &lt;%# Eval(&#34;Address&#34;)%&gt; &lt;/td&gt; &lt;/tr&gt; &lt;/ItemTemplate&gt; &lt;AlternatingItemTemplate&gt; &lt;tr class=&#34;unread&#34;&gt; &lt;td class=&#34;command&#34;&gt; &lt;asp:LinkButton ID=&#34;HyperLink1&#34; runat=&#34;server&#34; OnCommand=&#34;getview&#34; Text=&#34;view&#34; CommandArgument=&#39;&lt;%# Eval(&#34;CustomerId&#34;)%&gt;&#39; CssClass=&#34;linkEditButton&#34; Font-Underline=&#34;True&#34; /&gt; &lt;/td&gt; &lt;td class=&#34;command&#34;&gt; &lt;asp:LinkButton OnCommand=&#34;getedit&#34; ID=&#34;btnEdit&#34; CommandArgument=&#39;&lt;%# Eval(&#34;CustomerId&#34;)%&gt;&#39; runat=&#34;server&#34; Text=&#34;Edit&#34; Font-Underline=&#34;True&#34; /&gt; &lt;/td&gt; &lt;td&gt; &lt;%# Eval(&#34;ContactName&#34;)%&gt; &lt;/td&gt; &lt;td class=&#34;cell-title&#34;&gt; &lt;%# Eval(&#34;Country&#34;)%&gt; &lt;/td&gt; &lt;td class=&#34;cell-title&#34;&gt; &lt;%# Eval(&#34;City&#34;)%&gt; &lt;/td&gt; &lt;td class=&#34;cell-title&#34;&gt; &lt;%# Eval(&#34;Phone&#34;)%&gt; &lt;/td&gt; &lt;td class=&#34;cell-title&#34;&gt; &lt;%# Eval(&#34;Address&#34;)%&gt; &lt;/td&gt; &lt;/tr&gt; &lt;/AlternatingItemTemplate&gt; &lt;EmptyDataTemplate&gt; &lt;div style=&#34;text-align: center; font-weight: bold&#34;&gt; 0 Results Founds&lt;/div&gt; &lt;/EmptyDataTemplate&gt; &lt;/asp:ListView&gt; &lt;br /&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;link href=&#34;http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery-ui.css&#34; rel=&#34;stylesheet&#34; type=&#34;text/css&#34; /&gt; &lt;script type=&#34;text/javascript&#34; src=&#34;http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js&#34;&gt;&lt;/script&gt; &lt;script type=&#34;text/javascript&#34; src=&#34;http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js&#34;&gt;&lt;/script&gt; &lt;script type=&#34;text/javascript&#34;&gt; function autoCompleteShow() { var elements = document.getElementsByClassName(&#39;#ulclass&#39;); for (var i = 0; i &lt; elements.length; i++) if (elements[i].innerHTML.search(&#34;&#34;) != -1) elements[i].style.setProperty(&#34;background-color&#34;, &#34;#4CC417&#34;, &#34;!important&#34;); else elements[i].style.setProperty(&#34;background-color&#34;, &#34;Red&#34;, &#34;!important&#34;); } &lt;/script&gt; &lt;script type=&#34;text/javascript&#34;&gt; function ClientItemSelected(sender, e) { $get(&#34;&lt;%=hfCustomerId.ClientID %&gt;&#34;).value = e.get_value(); document.getElementById(&#34;&lt;%=cmdUpdateField.ClientID%&gt;&#34;).click(); } &lt;/script&gt;</pre> <p><span style="text-decoration: underline;"><strong>Namespaces</strong></span></p> <p><strong>C#</strong></p> <pre class="brush: csharp">using System.Data; using System.Data.SqlClient; using System.Configuration;</pre> <p><strong>Vb.Net</strong></p> <pre class="brush: vb">Imports System.Data.SqlClient Imports System.Data </pre> <p><span style="text-decoration: underline;"><strong>Code</strong></span></p> <p><strong>C#</strong></p> <pre class="brush: csharp">protected void Page_Load(object sender, EventArgs e) { if (!this.IsPostBack) { this.BindListView(); } } private void BindListView() { string constr = ConfigurationManager.ConnectionStrings[&#34;constr&#34;].ConnectionString; using (SqlConnection con = new SqlConnection(constr)) { using (SqlCommand cmd = new SqlCommand()) { cmd.CommandText = &#34;SELECT CustomerId, ContactName, City, Phone ,Country, Address FROM Customers&#34;; 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[&#34;constr&#34;].ConnectionString; using (SqlConnection con = new SqlConnection(constr)) { using (SqlCommand cmd = new SqlCommand()) { cmd.CommandText = &#34;SELECT CustomerId, ContactName, City, Phone ,Country, Address FROM Customers WHERE ContactName LIKE @ContactName + &#39;%&#39;&#34;; cmd.Connection = con; using (SqlDataAdapter sda = new SqlDataAdapter(cmd)) { cmd.Parameters.AddWithValue(&#34;@ContactName&#34;, 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(&#34;DataPager1&#34;) as DataPager).SetPageProperties(e.StartRowIndex, e.MaximumRows, false); this.Search(); } [System.Web.Script.Services.ScriptMethod()] [System.Web.Services.WebMethod] public static List&lt;string&gt; SearchCustomers(string prefixText, int count) { string connStr = ConfigurationManager.ConnectionStrings[&#34;constr&#34;].ToString(); SqlConnection con = new SqlConnection(connStr); SqlCommand cmd = new SqlCommand(&#34;SELECT CustomerId, ContactName, City, Phone ,Country, Address FROM Customers WHERE ContactName LIKE @ContactName + &#39;%&#39;&#34;,con); con.Open(); cmd.Parameters.AddWithValue(&#34;@ContactName&#34;, prefixText); SqlDataReader reader = cmd.ExecuteReader(CommandBehavior.CloseConnection); DataTable dt = new DataTable(); dt.Load(reader); List&lt;string&gt; customers = new List&lt;string&gt;(); if (dt.Rows.Count &gt; 0) { for (int i = 0; i &lt; dt.Rows.Count; i++) { string item = AjaxControlToolkit.AutoCompleteExtender.CreateAutoCompleteItem(dt.Rows[i][&#34;ContactName&#34;].ToString(), dt.Rows[i][&#34;CustomerId&#34;].ToString()); customers.Add(item); } } con.Close(); return customers; }</pre> <p>&nbsp;<strong>Vb.Net</strong></p> <pre class="brush: vb">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(&#34;constr&#34;).ConnectionString Using con As SqlConnection = New SqlConnection(constr) Using cmd As SqlCommand = New SqlCommand() cmd.CommandText = &#34;SELECT CustomerId, ContactName, City, Phone ,Country, Address FROM Customers&#34; 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(&#34;constr&#34;).ConnectionString Using con As SqlConnection = New SqlConnection(constr) Using cmd As SqlCommand = New SqlCommand() cmd.CommandText = &#34;SELECT CustomerId, ContactName, City, Phone ,Country, Address FROM Customers WHERE ContactName LIKE @ContactName + &#39;%&#39;&#34; cmd.Connection = con Using sda As SqlDataAdapter = New SqlDataAdapter(cmd) cmd.Parameters.AddWithValue(&#34;@ContactName&#34;, 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(&#34;DataPager1&#34;), DataPager).SetPageProperties(e.StartRowIndex, e.MaximumRows, False) Me.Search() End Sub &lt;System.Web.Script.Services.ScriptMethod()&gt; &lt;System.Web.Services.WebMethod()&gt; Public Shared Function SearchCustomers(ByVal prefixText As String, ByVal count As Integer) As List(Of String) Dim connStr As String = ConfigurationManager.ConnectionStrings(&#34;constr&#34;).ToString() Dim con As SqlConnection = New SqlConnection(connStr) Dim cmd As SqlCommand = New SqlCommand(&#34;SELECT CustomerId, ContactName, City, Phone ,Country, Address FROM Customers WHERE ContactName LIKE @ContactName + &#39;%&#39;&#34;, con) con.Open() cmd.Parameters.AddWithValue(&#34;@ContactName&#34;, 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 &gt; 0 Then For i As Integer = 0 To dt.Rows.Count - 1 Dim item As String = AjaxControlToolkit.AutoCompleteExtender.CreateAutoCompleteItem(dt.Rows(i)(&#34;ContactName&#34;).ToString(), dt.Rows(i)(&#34;CustomerId&#34;).ToString()) customers.Add(item) Next End If con.Close() Return customers End Function</pre> <p><span style="text-decoration: underline;"><strong>Screenshot</strong></span></p> <p><img src="https://i.imgur.com/gWheGdC.gif" alt="" width="452" height="349" /></p>https://www.aspforums.net:443/Threads/642555/ListView-paging-based-on-Ajax-AutoCompleteExtender-result-in-ASPNet/https://www.aspforums.net:443/Threads/642555/ListView-paging-based-on-Ajax-AutoCompleteExtender-result-in-ASPNet/Thu, 26 Jul 2018 06:20:52 GMT