consider the following classes (similar to the ones i am working with):

namespace Project
{
    public class Person
    {

        public Person()
        {

        }

      private string name;
      public string Name
{

 get { return name; }
            set { name = value; }
}

        private List<Pet> myPets;

        public List<Pet> MyPets
        {
            get { return myPets; }
            set { myPets = value; }
        }
    }
}
namespace Project
{
    public class Pet
    {

        public Pet()
        {

        }
        private int numberOfPaws;

        public int NumberOfPaws
        {
            get { return numberOfPaws; }
            set { numberOfPaws = value; }
        }
    }
}

Lets just say i bound my gridview to a List<Person>,

if i had template fields in the gridview markup how would I use Databinder.Eval() function to display 'numberOfPaws' for a pet at a certain index

eg.

<Gridview datasource=generic list of person>
<columns>
<TemplateField>
<ItemTemplate>
   <asp: Label id="person" text="<% #Eval(Person.name) %>"></Label>
</ItemTemplate>
</TemplateField>
  <TemplateField>
    <ItemTemplate>
         <asp: Label id="id" Text="<% [B][U]# (Container.DataItem).MyPets[0].NumberOfPaws.ToString()[/U][/B] %>"></Label>
     </ItemTemplate>
  </TemplateField>
</columns>
</Gridview>

i get error saying "server tag is not well formed " so that highlight code isnt how to do it, any suggestions or rough guidance???

<Gridview datasource=generic list of person>
<columns>
<TemplateField>
<ItemTemplate>
<asp: Label id="person" text="[U]<%# Eval(Person.name) %>[/U]"></Label>
</ItemTemplate>
</TemplateField>
<TemplateField>
<ItemTemplate>
<asp: Label id="id" Text="<%# [U]Eval(Container.DataItem,MyPets[0].NumberOfPaws.ToString())[/U] %>"></Label>
</ItemTemplate>
</TemplateField>
</columns>
</Gridview>

i got error:

"The name MyPets doesn't exist in the current context"

I found a workaround to solve this problem.

I just programmatically set label text via the rowdatabound event of the gridview.

Thanks Shoaib for having a look at it.

You need to use single quotes:

Text='<%# [U]Eval(Container.DataItem,MyPets[0].NumberOfPaws.ToString())[/U] %>'

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.