We help IT Professionals succeed at work.

objectdatasource filterexpression using 'LEFT()' function?

nellster1000
nellster1000 asked
on
Medium Priority
1,188 Views
Last Modified: 2012-05-06
Hi all. I am working on a ASP NET 2.0 (vb net) site. I have created an objectdata source that is bound to a gridview. I want to filter the gridview based on matching the first letter of the firstname column with an inputted value.

I have previously matched letters using the following expression:

odsAdminSubmissionAll.FilterExpression = "SubFirstName LIKE '%" & txtSearch.Text & "%'"

In order to try and match the first letter I did the following:

        odsAdminSubmissionAll.FilterExpression = "LEFT(SubFirstName, 1) = '" & strLetter & "'"

The error I got was:
"Exception Details: System.Data.EvaluateException: The expression contains undefined function call LEFT()."

Anyone point me in the right direction?

many thanks in advance!

Nellster
Comment
Watch Question

Commented:
LEFT is not a valid command.
Here's  a list of them.
http://msdn.microsoft.com/en-us/library/system.data.datacolumn.expression(VS.80).aspx

Try:

odsAdminSubmissionAll.FilterExpression = "SUBSTRING(SubFirstName, 0, 1) = '" & strLetter & "'"

Open in new window

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts
Anurag AgarwalPython Developer

Commented:
use like this
odsAdminSubmissionAll.FilterExpression = "SubFirstName LIKE '%" & strLetter
It Should Work
 
Anurag AgarwalPython Developer

Commented:
Sorry,
use like this
odsAdminSubmissionAll.FilterExpression = "SubFirstName LIKE strLetter & "%"
It Should Work
 
Anurag

Author

Commented:
Thanks for the quick responses guys.

JPJ78, had to modify slightly to SUBSTRING(SubFirstName, 1, 1) as strating position is 1 aparantly and not 0 but you showed me the way!

anuragal, tried both your suggestions but neither worked for me but thank you for helping.

Nellster
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.