Sunday, January 12, 2014

Creation of Search BOX in C#.NET


There are certain logics of creating search boxes in DOTNET framework. Some programmers go with custom search box while other goes with google’s default search box. Both of the methods work efficiently and produce correct result.
But here is a different technique of creating search box in DOTNET framework, using C#.net. these techniques are
  • Custom Search Box
  • Google's Default Search Box
  • Through KEYWORD matching

Code:



using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

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


public partial class Search : System.Web.UI.Page
{

    SqlConnection con;
    SqlDataAdapter adap;

  protected void Page_Load(object sender, EventArgs e)
    {

        if (Session["login"] == null)
        {
            Response.Redirect("LoginMessage.aspx");
        }


    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        try
        {
            con = new SqlConnection(ConfigurationManager.ConnectionString[""].ConnectionString);

            con.open();

            string cmdst = "select UserName, UserMobile, UserEMail from UserRegistration where UserName='"+ TextBox1.Text.Trim() +"'";

            adap = new SqlDataAdapter(cmdst, con);

            DataSet ds = new DataSet();

            adap.Fill(ds);

            GridView1.DataSource = ds.Tables[0];
            GridView1.DataBind();



        }
        catch (Exception pp)
        {

        }
    }
}

Example: 





No comments:

Post a Comment