• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1187
  • Last Modified:

Using String.StartsWith() to Filter a DataView


I've been trying to figure out how I can Filter a DataView according to the beginning letter of the value in either the 1st, 2nd or 3rd column.

I've found that this is the proper format:
       dv.RowFilter = "City = 'Berlin'"

dv being the Dataview.  My Value represented by 'Berlin' is a variable so I can't hard code this although I can hardcode the 'City' part.

Can anyone think of a way for me to indicate that I want the filtering to be done on any rows that begin with my variable value or is this even possible?


  • 2
1 Solution

dv.RowFilter = String.Format("City IS LIKE '{0}%'", myvariable)
I'm sorry, I think that should be without the "IS" keyword.

dv.RowFilter = String.Format("City LIKE '{0}%'", myvariable)
Do you really have to use DataView? Why can't you filter it in SQL query?

MariyamAuthor Commented:
I increased the points because your solution was exactly what I was looking for.  I only wish there were a way to stuff that expression into the property list of the SQLDataSource and my life would be practically perfect :-)

Thanks again for all of your help.

P.S. To Nauman  Ahmed

My SP is returning a list of staff members are associated records - the maximum number is between 500 & 1000.  Any one of those staff member could be access this web page at any given time so rather than having all of that traffic on the network, I caching the dataView in a Session variable so that the procedure is only run once per session.

Believe me I understand the longing to code everything in SQL because I've been writing SQL code much longer than I'm been writing in ASP.net.  I'm just trying to write more efficiently, but your question is certainly valid and a good one.  Thanks.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now