0

I'm creating a SharePoint Web Part that displays list items.

To display these items I am using an asp:ListView and <%#Eval() %>. I needed to change the output of <%#Eval() %> so I added a new static class to the project, created an extension method and imported the namespace in the user control.

So the <%#Eval() %> looks like this: <%#Eval("xxx").ToString().MyMethod() %>

The problem is that when I debug this Web Part I get an error saying that 'string' does not contain a definition for MyMethod.

3
  • <%# ClassName.MyMethod() %> this doesn't work? or <%# NameSpace.ClassName.MyMethod() %> Nov 1, 2012 at 8:59
  • I have imported the namespace like this:<%@ Import Namespace="MyClassNamespace"%> and used my method like this: <%#Eval("xxx").ToString().MyMethod() %>
    – user3470
    Nov 1, 2012 at 9:18
  • Moussa, try not to call extension method directly... First call a method in your page class and then return the output of Extension Method! Nov 1, 2012 at 9:37

1 Answer 1

1

You have to try it different way:

  • In your ascx.cs file, declare a public method
public string Abc(DataRowView row) {
return  row["xxx"].ToString().MyMethod()
}
  • call this function from list view like:
<%# Abc(Container.DataItem) %>

This should work.

1
  • I agree, sometimes the best way is to simplify the namespace evaluating for asp and just give it one method to call which does the rest of the logic itself. Nov 1, 2012 at 12:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.