SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

share|improve this question
<%# ClassName.MyMethod() %> this doesn't work? or <%# NameSpace.ClassName.MyMethod() %> – Arsalan Adam Khatri Nov 1 '12 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 '12 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! – Arsalan Adam Khatri Nov 1 '12 at 9:37
up vote 1 down vote accepted

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.

share|improve this answer
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. – Sam Sussman Nov 1 '12 at 12:35

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.