Fetch all records in gridview according to record which user insert any value in textbox

Satyapriyanayak
Posted by Satyapriyanayak under ASP.NET category on | Points: 40 | Views : 922
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="Textbox_gridview._Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >

<head runat="server">

<title>Untitled Page</title>

</head>

<body>

<form id="form1" runat="server">

<div>

<asp:ScriptManager ID="ScriptManager1" runat="server">

</asp:ScriptManager>

<asp:UpdatePanel ID="up1" runat="server">

<ContentTemplate >

<asp:Label ID="Label1" runat="server" Text="Type Empid " BackColor="#FFFF99"

ForeColor="Red" Width="100px"></asp:Label>

<asp:TextBox ID="txt_empid" runat="server" ClientIDMode="Static"

AutoPostBack ="true" ontextchanged="txt_empid_TextChanged"

></asp:TextBox>

<asp:Timer ID="Timer1" runat="server" Interval="10000" ontick="Timer1_Tick">

<asp:Label ID="Label3" runat="server" Text="Label"></asp:Label>

</asp:Timer>

</ContentTemplate>

</asp:UpdatePanel>

<br />

<asp:UpdatePanel ID="up2" runat="server">

<ContentTemplate >

<asp:Label ID="Label2" runat="server" Text="Corresponding Records" BackColor="#FFFF66"

ForeColor="Red" Width="100px"></asp:Label>

<asp:GridView ID="GridView1" runat="server">

</asp:GridView>

</ContentTemplate>

</asp:UpdatePanel>

<br />

</div>

</form>

</body>

</html>




using System;

using System.Collections;

using System.Configuration;

using System.Data;

using System.Linq;

using System.Web;

using System.Web.Security;

using System.Web.UI;

using System.Web.UI.HtmlControls;

using System.Web.UI.WebControls;

using System.Web.UI.WebControls.WebParts;

using System.Xml.Linq;

using System.Data.SqlClient;

namespace Textbox_gridview

{

public partial class _Default : System.Web.UI.Page

{

string strConnString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;

string str;

SqlCommand com;

SqlDataAdapter sqlda;

DataSet ds;

protected void Page_Load(object sender, EventArgs e)

{

if (!IsPostBack)

{

bindgrid();

}

}

public void bindgrid()

{

SqlConnection con = new SqlConnection(strConnString);

con.Open();

str = "select * from employee";

com = new SqlCommand(str, con);

sqlda = new SqlDataAdapter(com);

ds = new DataSet();

sqlda.Fill(ds, "employee");

GridView1.DataMember = "employee";

GridView1.DataSource = ds;

GridView1.DataBind();

con.Close();

}


protected void txt_empid_TextChanged(object sender, EventArgs e)

{

SqlConnection con = new SqlConnection(strConnString);

con.Open();

str = "select * from employee where empid like '" + txt_empid.Text + "%'";

com = new SqlCommand(str, con);

sqlda = new SqlDataAdapter(com);

ds = new DataSet();

sqlda.Fill(ds, "employee");

GridView1.DataMember = "employee";

GridView1.DataSource = ds;

GridView1.DataBind();

con.Close();

}

protected void Timer1_Tick(object sender, EventArgs e)

{

Label3.Text = DateTime.Now.ToString();


}

}

}

Comments or Responses

Login to post response