Solved

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

Posted on 2011-09-22
7
323 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
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

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 …
Browsing the questions asked to the Experts of this forum, you will be amazed to see how many times people are headaching about monster regular expressions (regex) to select that specific part of some HTML or XML file they want to extract. The examp…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

743 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

14 Experts available now in Live!

Get 1:1 Help Now