Solved

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

Posted on 2011-09-22
7
341 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

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…
Many times as a report developer I've been asked to display normalized data such as three rows with values Jack, Joe, and Bob as a single comma-separated string such as 'Jack, Joe, Bob', and vice versa.  Here's how to do it. 
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

803 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