Link to home
Start Free TrialLog in
Avatar of Mariyam
Mariyam

asked on

Using String.StartsWith() to Filter a DataView

Hello,

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?

TIA
-Mari

Avatar of HappyFunBall
HappyFunBall

Yes,

dv.RowFilter = String.Format("City IS LIKE '{0}%'", myvariable)
ASKER CERTIFIED SOLUTION
Avatar of HappyFunBall
HappyFunBall

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Do you really have to use DataView? Why can't you filter it in SQL query?

-Nauman.
Avatar of Mariyam

ASKER

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.