<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %> <%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title>Untitled Page</title> </head> <body> <form id="form1" runat="server"> <asp:ScriptManager ID="ScriptManager1" EnablePageMethods="true" runat="server" /> <div> <cc1:AutoCompleteExtender ServiceMethod="SearchCD" MinimumPrefixLength="2" CompletionInterval="100" EnableCaching="false" CompletionSetCount="10" TargetControlID="txtSearch" ID="AutoCompleteExtender1" runat="server" FirstRowSelected="true"> </cc1:AutoCompleteExtender> <asp:TextBox ID="txtSearch" runat="server" AutoPostBack="True"></asp:TextBox> <asp:GridView ID="dgv1" runat="server"> </asp:GridView> <asp:Button ID="btnSearch" runat="server" Text="Search" /></div> </form> </body> </html >
using System; using System.Data; using System.Configuration; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; using System.Data.SqlClient; using System.Collections.Generic; public partial class _Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } [System.Web.Script.Services.ScriptMethod()] [System.Web.Services.WebMethod] public static List<string> SearchCD(string prefixText, int count) { string constring = ConfigurationManager.AppSettings.Get("con").ToString(); SqlConnection conn = new SqlConnection(constring); SqlCommand cmd = new SqlCommand("select CD_NAME from CD_DETAILS where " + "CD_NAME like @SearchText + '%'", conn); cmd.Parameters.AddWithValue("@SearchText", prefixText); cmd.Connection = conn; conn.Open(); List<string> cds = new List<string>(); using (SqlDataReader sdr = cmd.ExecuteReader()) { while (sdr.Read()) { cds.Add(sdr["CD_NAME"].ToString()); } } conn.Close(); return cds; } protected void btnSearch_Click(object sender, EventArgs e) { string constring = ConfigurationManager.AppSettings.Get("con").ToString(); SqlConnection conn = new SqlConnection(constring); conn.Open(); SqlCommand check = new SqlCommand("spSearch", conn); check.CommandType = CommandType.StoredProcedure; check.Parameters.Add(new SqlParameter("@searchKey", SqlDbType.NVarChar, 50)); check.Parameters["@searchKey"].Value = txtSearch.Text; SqlDataAdapter da = new SqlDataAdapter(check); DataSet ds = new DataSet(); da.Fill(ds); this.dgv1.DataSource = ds.Tables[0].DefaultView; dgv1.DataBind(); conn.Close(); } }
<asp:button id="btnSearch" runat="server" text="Search" xmlns:asp="#unknown" />
<asp:button id="btnSearch" runat="server" text="Search" onclick="btnSearch_Click" xmlns:asp="#unknown" />
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)