views:

41

answers:

1

Hi,

I'm creating a text box with auto-suggested. So, it works well. It suggests only first name, but I want it to suggest the full name (first and last name which two different columns). Take a look at the following code behind that worked as expected :

<System.Web.Services.WebMethod()> _
Public Shared Function GetNames(ByVal prefixText As String, ByVal count As Integer) As String()

    Dim db As New DemoDataContext()
    Return db.Students.Where(Function(n) n.FirstName.StartsWith(prefixText)).OrderBy(Function(n) n.FirstName).Select(Function(n) n.FirstName).Take(count).ToArray

End Function

Here's the mark-up :

        <asp:TextBox ID="TextBox1" runat="server" Width="191px"></asp:TextBox>
    <cc1:AutoCompleteExtender ID="TextBox1_AutoCompleteExtender" runat="server" 
         Enabled="True" minimumprefixlength="1"  ServiceMethod ="GetNames" TargetControlID="TextBox1">
    </cc1:AutoCompleteExtender>

I wrote the following code to try to get the text box to suggest the full name but it didn't work :

        Dim query = (From s In db.Students _
               Where s.FirstName.StartsWith(prefixText) _
               Order By s.FirstName _
               Select New With {.Name = s.FirstName & " " & s.LastName}).Take(count).ToArray
        Return query

When I build the project it says "Value of type '1-dimensional array of (line 50)' cannot be converted to '1-dimensional array of String' because ' (line 50)' is not derived from 'String'"

Anyboy has a suggestion, please comment. Thank you.

+2  A: 

Don't create a new anonymous object with a name attribute that is a string, just return the string itself:

    Dim query = (From s In db.Students _
           Where s.firstname.StartsWith(prefixText) _
           Order By s.firstname _
           Select s.firstname & " " & s.lastname).Take(count).ToArray
Mark Byers