Solved

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

Posted on 2011-09-22
7
368 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Technology Partners: 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 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

Is Your Team Achieving Their Full Potential?

74% of employees feel they are not achieving their full potential. With Linux Academy, not only will you strengthen your team's core competencies but also their knowledge of of the newest IT topics.

With new material every week, we'll make sure that you stay ahead of the game.

Question has a verified solution.

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

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
If you're a developer or IT admin, you’re probably tasked with managing multiple websites, servers, applications, and levels of security on a daily basis. While this can be extremely time consuming, it can also be frustrating when systems aren't wor…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

688 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