Hi friends you will have to seen there are lots of records in database at this time.In this tutorial i will explain how to make search to user friendly in asp.net application.you can easily search related data from the database.In this application you can search lots of data by entering the single character in search box. Google also search lots of records from the database or cache memory like this application but it use very complex algorithm.This concept is also known as Dictionary search algorithm.But we can not compare with Google search engine. To provide relevant search to your user you can use this concepts on your asp.net application.
There are some steps to implement this concept on your asp.net application which are given below:-
Step 1:- First open your visual studio-->File--> New -->website-->select ASP.NET Empty website--> Add-->open Solution Explorer-->Add a New web form --> drag and drop label ,Text Box, SqlDataSource and Gridview control from toolbox as shown below:-
Step 2:- Now go properties of every Text Box control-->set AutoPostBack = True.There are some steps to implement this concept on your asp.net application which are given below:-
Step 1:- First open your visual studio-->File--> New -->website-->select ASP.NET Empty website--> Add-->open Solution Explorer-->Add a New web form --> drag and drop label ,Text Box, SqlDataSource and Gridview control from toolbox as shown below:-
Step 3:- Now create Database .mdf file on your website -->create an employee table --> Insert some values in employee table as shown below:-
Step 4:- Now Double click on each Text Box and write the following codes which are given below:
using System;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Configuration;
using System.Drawing;
using System.Data;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
}
protected void searchtxt_TextChanged(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);
con.Open();
SqlDataAdapter da = new SqlDataAdapter("Select*from employee where [Emp Name] like'" + searchtxt.Text + "%'", con);
string text = ((TextBox)sender).Text;
DataSet ds = new DataSet();
da.Fill(ds);
if (ds.Tables[0].Rows.Count > 0)
{
myGridview1.DataSource = ds.Tables[0];
myGridview1.DataBind();
Label2.Visible = false;
}
else
{
Label2.Visible = true;
Label2.Text = "No Record Found";
this.Label2.ForeColor = Color.Red;
}
}
protected void txtsearch_TextChanged(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);
con.Open();
SqlDataAdapter da = new SqlDataAdapter("Select*from employee where Mobile like'" + txtsearch.Text + "%'", con);
string text = ((TextBox)sender).Text;
DataSet ds = new DataSet();
da.Fill(ds);
if (ds.Tables[0].Rows.Count > 0)
{
myGridview1.DataSource = ds.Tables[0];
myGridview1.DataBind();
Label2.Visible = false;
}
else
{
Label2.Visible = true;
Label2.Text = "No Record Found";
this.Label2.ForeColor = Color.Red;
}
}
}
Step 5:- Now Run the application (press F5)-->enter some value in first text box-->you will see following output-
Step 6:- Enter some value in Second text box-->you will see following output-
I hope this is helpful for you.
For More...
- Microsoft Sql server
- Store procedure in sql server
- Views in sql server
- Data List Real Application
- .Net Interview Questions and answers
- Composit application in asp.net
- Threading in c#
- File Handling Real application
- Web form controls
- Host asp.net website free on server
Download
Sir i have tried as u said above step by step but its showing the following error
ReplyDeleteServer Error in '/ASP.NETCONTROLS' Application.
The user instance login flag is not supported on this version of SQL Server. The connection will be closed.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Data.SqlClient.SqlException: The user instance login flag is not supported on this version of SQL Server. The connection will be closed.
Source Error:
Tis is My Error Both DataSource and DataSourceID are defined on 'GridView1'. Remove one definition.
ReplyDeleteSir how can display Record in Two Date with calendar in grid view
ReplyDeletenice 1 its very helpful and it working thanks
ReplyDelete