Creation of Search Box in C#

There is certain logic to the creation of search boxes in the .NET Framework. Some programmers use custom search boxes while other use Google's default search box. Both of the methods work efficiently and produce a correct result. But here is a different way to create a search box in .NET Framework, using C#.

different technique of creating search box

Code

  1. using System;  
  2. using System.Collections.Generic;  
  3. using System.Linq;  
  4. using System.Web;  
  5. using System.Web.UI;  
  6. using System.Web.UI.WebControls;  
  7. using System.Configuration;  
  8. using System.Data;  
  9. using System.Data.SqlClient;  
  10. public partial class Search : System.Web.UI.Page  
  11. {  
  12.     SqlConnection con;  
  13.     SqlDataAdapter adap;  
  14.     protected void Page_Load(object sender, EventArgs e)  
  15.     {  
  16.         if (Session["login"] == null)  
  17.         {  
  18.             Response.Redirect("LoginMessage.aspx");  
  19.         }  
  20.     }  
  21.     protected void Button1_Click(object sender, EventArgs e)  
  22.     {  
  23.         try  
  24.         {  
  25.             con = new SqlConnection(ConfigurationManager.ConnectionString[""].ConnectionString);  
  26.             con.open();  
  27.             string cmdst = "select UserName, UserMobile, UserEMail from UserRegistration where UserName='" + TextBox1.Text.Trim() + "'";  
  28.             adap = new SqlDataAdapter(cmdst, con);  
  29.             DataSet ds = new DataSet();  
  30.             adap.Fill(ds);  
  31.             GridView1.DataSource = ds.Tables[0];  
  32.             GridView1.DataBind();  
  33.         }  
  34.         catch (Exception pp)  
  35.         {  
  36.         }  
  37.     }  
  38. }   

Search Box

(Through database connectivity and keywords.)


Similar Articles