Learn how to a build a cloud-first strategyRegister Now

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1055
  • 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.

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering 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