Click here to Skip to main content
15,902,299 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
Hi,

i am trying to add a text box and based on the value i give in text box search should be done in gridview.

here is the code i am using
Partial Class _Default
    Inherits System.Web.UI.Page
    Dim str As String = ConfigurationManager.ConnectionStrings("constring").ConnectionString
    Dim sqlcon As New SqlConnection(str)
    Dim ds As New DataSet
    Protected Sub txtserach_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtsearch.TextChanged
        Dim sqladapt As New SqlDataAdapter
        If txtsearch.Text = "" Then
            'sqladapt = New SqlDataAdapter("SELECT * from Card_type", sqlcon)
            'ds = New DataSet
            'sqladapt.Fill(ds, "1")
            'gdvsearch.DataSource = ds.Tables("1")
            sqladapt = New SqlDataAdapter("SELECT * from Card_type", sqlcon)
            sqladapt.Fill(ds)
            gdvsearch.DataSource = ds
            gdvsearch.DataBind()
        Else
            Dim sqlda As New SqlDataAdapter("SELECT * FROM Card_type WHERE membership_type like '" + txtsearch.Text + "%'", sqlcon)
            ds = New DataSet
            sqlda.Fill(ds)
            gdvsearch.DataSource = ds
            gdvsearch.DataBind()
        End If
    End Sub

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Dim sqladapt As New SqlDataAdapter
        sqladapt = New SqlDataAdapter("SELECT * from Card_type", sqlcon)
        sqladapt.Fill(ds)
        gdvsearch.DataSource = ds
        gdvsearch.DataBind()
    End Sub

End Class


But i am getting the result but only after i enter the string and click enter BUT I WANT TO DISPLAY IN GRIDVIEW AS SOON AS THE VALUE IS ENTERED IN ETXTBOX


THANKS IN ADVANCE
Posted

Add following to your Page_Load
txtserach.AutoPostBack = true

or set AutoPostBack to true at design time.

But I think it's not a good experience for users, as page will refresh to get the data from server.

As per me, you should think of some ajax or jquery alternatives.
 
Share this answer
 
v2
in your ASPX file.. set this property of textsearch
AutoPostBack="true"

please vote this answer if it helps
 
Share this answer
 
Use Ajax AutoComplete Extender for this.


http://www.asp.net/ajax/ajaxcontroltoolkit/samples/autocomplete/autocomplete.aspx


Please Vote if this helps you.
 
Share this answer
 
is there any other solution other than ajax control
 
Share this answer
 
Comments
MalikRizwan 24-Sep-10 9:52am    
yes there is if you use client based (javascript) for text change event and on each key pressed pass value to iframe and in that iframe have your grid...to show tabular data.. but i dont understand why would you want to use anything else than ajax.. I suggest you to do it like this
<asp:updatepanel runat="server" updatemode="Conditional">
<contenttemplate>
-- put your textbox and gridview here..



don't forget to drag scriptmanager on top of your page...

and don't forget to add Ajax extension in your project... this is all you have to do with ajax thing.. it will solve your problem...
anupama962010 25-Sep-10 1:32am    
yaa i know its simple using ajax but for auto complete extender it is asking to crreate some asmx page and calling it which i did but remained unsuccessful can u help me with any userdefined code other than the example given in tutorials

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900