Hi SUJAYS,
Check this example. Now please take its reference and correct your code.
Database
For this example I have used of Northwind database that you can download using the link given below.
Download Northwind Database
HTML
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
Name:<asp:TextBox ID="txtval1" runat="server" AutoPostBack="true" OnTextChanged="txtval1_Changed"></asp:TextBox>
<br /><br />
<asp:GridView runat="server" ID="gvCustomers" AutoGenerateColumns="false">
<Columns>
<asp:BoundField DataField="CustomerID" HeaderText="ID" />
<asp:BoundField DataField="ContactName" HeaderText="Name" />
<asp:BoundField DataField="Country" HeaderText="Country" />
</Columns>
</asp:GridView>
</ContentTemplate>
</asp:UpdatePanel>
Namespaces
C#
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
VB.Net
Imports System.Configuration
Imports System.Data
Imports System.Data.SqlClient
Code
C#
protected void txtval1_Changed(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["strConfig"].ConnectionString);
using (SqlCommand cmd = new SqlCommand("SELECT CustomerID,ContactName,Country FROM Customers WHERE ContactName LIKE +@Name+'%'", con))
{
cmd.CommandType = CommandType.Text;
cmd.Parameters.AddWithValue("@Name", txtval1.Text.Trim());
using (SqlDataAdapter sda = new SqlDataAdapter(cmd))
{
DataTable dt = new DataTable();
sda.Fill(dt);
this.gvCustomers.DataSource = dt;
this.gvCustomers.DataBind();
}
}
}
VB.Net
Protected Sub txtval1_Changed(ByVal sender As Object, ByVal e As EventArgs)
Dim con As SqlConnection = New SqlConnection(ConfigurationManager.ConnectionStrings("strConfig").ConnectionString)
Using cmd As SqlCommand = New SqlCommand("SELECT CustomerID,ContactName,Country FROM Customers WHERE ContactName LIKE +@Name+'%'", con)
cmd.CommandType = CommandType.Text
cmd.Parameters.AddWithValue("@Name", txtval1.Text.Trim())
Using sda As SqlDataAdapter = New SqlDataAdapter(cmd)
Dim dt As DataTable = New DataTable()
sda.Fill(dt)
Me.gvCustomers.DataSource = dt
Me.gvCustomers.DataBind()
End Using
End Using
End Sub
Screenshot