?
Solved

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

Posted on 2011-09-22
7
Medium Priority
?
388 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:vcharles
ID: 36588549
Help!
0
 
LVL 12

Accepted Solution

by:
jagssidurala earned 2000 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

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

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

In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Suggested Courses

750 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