johnturgoose
Technical User
I have a class Relationships which has various properties. One of which is Person which is a class with various properties.
I am trying to bind my ddl to the property PersonLastName which is a property of Person which is a property of Relationship
So:
ddlPerson.DataTextField = "Person.PersonLastName"
ddlPerson.DataValueField = "Person.PersonID"
ddlPerson.DataSource = _TMSUserSession.RelationshipList
ddlPerson.DataBind()
returns the error _TMSUserSession.RelationshipList does not contain the property Person.PersonLastName
I have a grid view which i bind in mark up using
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" Font-Names="Verdana" Font-Size="X-Small" CellSpacing="2">
<Columns>
<asp:CommandField ButtonType="Image" SelectImageUrl="~/Images/Arrow1.gif"
ShowSelectButton="True" />
<asp:BoundField HeaderText="ID" DataField = "RelationshipID" />
<asp:TemplateField HeaderText="Person Name">
<ItemTemplate>
<asp:Label ID="lblPersonName" runat="server"
Text='<%# Eval("Person").PersonFirstName %>'>
</asp:Label>
<asp:Label ID="lblPersonLastName" runat="server"
Text='<%# Eval("Person").PersonLastName %>'>
</asp:Label>
</ItemTemplate>
</asp:TemplateField>
Etc......
Which works fine but any attempt to use Eval with DataValueField and DataTextField for ddl returns the error
"Databinding methods such as Eval(), XPath(), and Bind() can only be used in the context of a databound control"
Put simply all I want to do is set my DataTextField and DataValueField properties to properties in a child object. Surely that shouldn't be as hard as it appears!!
Many thanks in advance
I am trying to bind my ddl to the property PersonLastName which is a property of Person which is a property of Relationship
So:
ddlPerson.DataTextField = "Person.PersonLastName"
ddlPerson.DataValueField = "Person.PersonID"
ddlPerson.DataSource = _TMSUserSession.RelationshipList
ddlPerson.DataBind()
returns the error _TMSUserSession.RelationshipList does not contain the property Person.PersonLastName
I have a grid view which i bind in mark up using
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" Font-Names="Verdana" Font-Size="X-Small" CellSpacing="2">
<Columns>
<asp:CommandField ButtonType="Image" SelectImageUrl="~/Images/Arrow1.gif"
ShowSelectButton="True" />
<asp:BoundField HeaderText="ID" DataField = "RelationshipID" />
<asp:TemplateField HeaderText="Person Name">
<ItemTemplate>
<asp:Label ID="lblPersonName" runat="server"
Text='<%# Eval("Person").PersonFirstName %>'>
</asp:Label>
<asp:Label ID="lblPersonLastName" runat="server"
Text='<%# Eval("Person").PersonLastName %>'>
</asp:Label>
</ItemTemplate>
</asp:TemplateField>
Etc......
Which works fine but any attempt to use Eval with DataValueField and DataTextField for ddl returns the error
"Databinding methods such as Eval(), XPath(), and Bind() can only be used in the context of a databound control"
Put simply all I want to do is set my DataTextField and DataValueField properties to properties in a child object. Surely that shouldn't be as hard as it appears!!
Many thanks in advance