Solved

Help with filtering data in GridView based on data entered in a Textbox Textchanged event

Posted on 2011-09-22
7
332 Views
Last Modified: 2012-05-12
Hello,

I am trying the code below in the Textboxes' Textchanged event to filter the data displayed on a Grid based on the text entered in a Textbox. However the code is not working with the dataset (ds) in the filter satement. can you please help me fix this error. The code also doesn't trigger in the Textchange event is their a way to execute the code everytime the user enters a text?

       Dim ds As New DataSet
        ds.ReadXml(Server.MapPath("~/App_Data/Country.xml"))
        GridView1.DataSource = ds.Tables(0)
        GridView1.DataBind()
        Dim SearchCriteria As String
        SearchCriteria = " Country IN (" & TextBox1.Text & " )"
        Dim FilteredDT As DataTable
        Dim DV As New DataView(ds, SearchCriteria, Nothing, DataViewRowState.CurrentRows) ***Error with ds in statement above
        FilteredDT = DV.ToTable
        GridView1.DataSource = FilteredDT
0
Comment
Question by:vcharles
  • 5
  • 2
7 Comments
 

Author Comment

by:vcharles
ID: 36582295
Hi,

I just tried the approach below but received the following error:
"Filter expression 'country' does not evaluate to a Boolean term."
How do I fix this error?

Cide:
 Dim ds As New DataSet
        ds.ReadXml(Server.MapPath("~/App_Data/Country.xml"))
        Dim dv As New DataView(ds.Tables(0))
        dv.RowFilter = String.Format("country", TextBox1.Text)
        GridView1.DataSource = dv
        GridView1.DataBind()

Thanks,

Victor
0
 
LVL 12

Expert Comment

by:jagssidurala
ID: 36582907
0
 

Author Comment

by:vcharles
ID: 36583636
Hi,

I read the section you referred me to, tried modifying my code but it still doesn't work:

 Dim ds As New DataSet
        ds.ReadXml(Server.MapPath("~/App_Data/Country.xml"))
        GridView1.DataSource = ds.Tables(0)
        GridView1.DataBind()
        Dim SearchCriteria As String
        SearchCriteria = " Country IN (" & TextBox1.Text & " )"
        Dim FilteredDT As DataTable
        '  Dim DV As New DataView(ds, SearchCriteria, Nothing, DataViewRowState.CurrentRows)
        GridView1.DataSource = FilteredDT.Select("Country IN (" & TextBox1.Text & " )")
0
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 

Author Comment

by:vcharles
ID: 36588549
Help!
0
 
LVL 12

Accepted Solution

by:
jagssidurala earned 500 total points
ID: 36591193
Need to write code like below

GridView1.DataSource= FilteredDT.Select("Country like  '" & TextBox1.Text & "%'").
GridView1.DataBind();

Refer this links

http://social.msdn.microsoft.com/Forums/en-US/vblanguage/thread/2c863ec7-b788-4f7c-b166-3aa66d33a0ba/

http://www.csharp-examples.net/dataview-rowfilter/



0
 

Author Comment

by:vcharles
ID: 36591961
Thanks, for some reason eventhough the code is the the Textboxe's textchanged event, the code doesn't work. Any ideas what I'm doing wrong? I need to filter the data in the grid for every charater the user enters in the textbox.
0
 

Author Closing Comment

by:vcharles
ID: 36711085
Thank You!!
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

861 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now