Using String.StartsWith() to Filter a DataView

Posted on 2006-06-02
Last Modified: 2008-01-09

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?


Question by:FoxProMari
    LVL 9

    Expert Comment


    dv.RowFilter = String.Format("City IS LIKE '{0}%'", myvariable)
    LVL 9

    Accepted Solution

    I'm sorry, I think that should be without the "IS" keyword.

    dv.RowFilter = String.Format("City LIKE '{0}%'", myvariable)
    LVL 25

    Expert Comment

    Do you really have to use DataView? Why can't you filter it in SQL query?


    Author Comment

    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  I'm just trying to write more efficiently, but your question is certainly valid and a good one.  Thanks.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Training Course: Java/J2EE and SOA

    This course will cover both core and advanced Java concepts like Database connectivity, Threads, Exception Handling, Collections, JSP, Servlets, XMLHandling, and more. You'll also learn various Java frameworks like Hibernate and Spring.

    I have developed many web applications with asp & and to add and use a dropdownlist was always a very simple task, but with the new, setting the value is a bit tricky and its not similar to the old traditional method. So in this a…
    User art_snob ( encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
    how to add IIS SMTP to handle application/Scanner relays into office 365.
    In this sixth video of the Xpdf series, we discuss and demonstrate the PDFtoPNG utility, which converts a multi-page PDF file to separate color, grayscale, or monochrome PNG files, creating one PNG file for each page in the PDF. It does this via a c…

    758 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

    Need Help in Real-Time?

    Connect with top rated Experts

    14 Experts available now in Live!

    Get 1:1 Help Now