Operand Issue

Learn2010

Member
Joined
Apr 12, 2013
Messages
7
Programming Experience
10+
I am following a course that I had previously taken to refresh my memory. I have an issue with C#. The lesson say's to use is this code in a Repeater:

C#:
<ItemTemplate>
        <a id="A1" href=<%#"~/MemberPages/viewprofile.aspx?UserId=" & Eval("UserId").ToString %> runat="server" >
                        <%#Eval("UserName")%></a><br />
    </ItemTemplate>

Here is the error message.
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.
Compiler Error Message: CS0019: Operator '&' cannot be applied to operands of type 'string' and 'method group'

I tried replacing the & with + and got the same thing. Any help on this?
 
I changed it to this:

C#:
<ItemTemplate>
        <a id="A1" href=<%#"~/MemberPages/viewprofile.aspx?UserId=" + Eval("UserId").ToString() %> runat="server" >
                        <%#Eval("UserName")%></a><br />
    </ItemTemplate>

I replaced the & with + and added () to ToString.
 
Your code from post #1 would be valid VB code, so that's probably what it is. In VB, you don't have to include parentheses on a method call if there are arguments and & is the string concatenation operator. In C#, using a method name without parentheses creates a delegate to that method, for which you use AddressOf in VB, and + is the string concatenation operator. You might want to ensure that you're using C# source code from wherever you're getting it or else you're going to have to convert from VB to C# every time.
 
Back
Top Bottom