How can i automatically search without first clicking the search button.
i would like when the name is typed in the txtsearch the names to automatically be displayed in editable mode
thanks in advance
Imports System.Data
Imports System.Data.SqlClient
Imports System.Configuration
Imports System.Text.RegularExpressions
Partial Class VB
Inherits System.Web.UI.Page
Private Shared PageSize As Integer = 5
Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
If Not IsPostBack Then
Me.BindGrid()
End If
End Sub
Protected Sub Search(sender As Object, e As EventArgs)
Me.BindGrid()
End Sub
Private Sub BindGrid()
Dim constr As String = ConfigurationManager.ConnectionStrings("UNIFORMConnectionString").ConnectionString
Using con As New SqlConnection(constr)
Using cmd As New SqlCommand()
cmd.CommandText = "SELECT Name, Class, stream FROM student WHERE Name LIKE '%' + @ContactName + '%'"
cmd.Connection = con
cmd.Parameters.AddWithValue("@ContactName", txtSearch.Text.Trim())
Dim dt As New DataTable()
Using sda As New SqlDataAdapter(cmd)
sda.Fill(dt)
gvCustomers.DataSource = dt
gvCustomers.DataBind()
End Using
End Using
End Using
End Sub
Protected Sub OnPageIndexChanging(sender As Object, e As GridViewPageEventArgs)
gvCustomers.PageIndex = e.NewPageIndex
Me.BindGrid()
End Sub
Protected Sub OnRowDataBound(sender As Object, e As GridViewRowEventArgs)
If e.Row.RowType = DataControlRowType.DataRow Then
e.Row.Cells(0).Text = Regex.Replace(e.Row.Cells(0).Text, txtSearch.Text.Trim(), _
Function(match As Match) String.Format("<span style = 'background-color:#D9EDF7'>{0}</span>", match.Value), _
RegexOptions.IgnoreCase)
End If
End Sub
Protected Sub txtSearch_TextChanged(sender As Object, e As EventArgs) Handles txtSearch.TextChanged
Me.BindGrid()
End Sub
End Class
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="VB.aspx.vb" Inherits="VB" %>
<!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 id="Head1" runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
Search:
<asp:TextBox ID="txtSearch" runat="server" />
<asp:Button Text="Search" runat="server" OnClick="Search" />
<hr />
<asp:GridView ID="gvCustomers" runat="server" AutoGenerateColumns="false" AllowPaging="true"
OnRowDataBound="OnRowDataBound" OnPageIndexChanging="OnPageIndexChanging">
<Columns>
<asp:BoundField HeaderStyle-Width="150px" DataField="Name" HeaderText="Contact Name"
ItemStyle-CssClass="ContactName" HtmlEncode = "false" />
<asp:BoundField HeaderStyle-Width="150px" DataField="Class" HeaderText="Class" />
<asp:BoundField HeaderStyle-Width="150px" DataField="Stream" HeaderText="Stream" />
</Columns>
</asp:GridView>
</form>
</body>
</html>