datasources and Eval in a gridview

1.1k Views Asked by At

I have a gridview using a linqdatasource with a datamodelcontext that I've created.

Why is it that I can do this:

<asp:TemplateField>
    <ItemTemplate>
       <asp:Label ID="Label3" runat="server" Text='<%# Eval("tblUserProfile.Phone") %>'>
       </asp:Label>
     </ItemTemplate>
 </asp:TemplateField>

But this:

<asp:BoundField DataField="tblUserProfile.Phone" HeaderText="ph" ReadOnly="True"/>    

Gives an error:

"A field or property with the name 'tblUserProfiles.Phone' was not found on the selected data source."

If the field or property doesn't exist on the datasource, how does it work in the first case? What does the eval do exactly? I thought it just let you access a field on the datasource?

Pretty new to this, so if someone could give me a basic explanation I'd appreciate it.

For an extra cookie, any ideas why this would let me edit this field, but when I click update on the gridview it wouldn't actually save it?

  <asp:TemplateField>
     <ItemTemplate>
        <asp:Label ID="Label3" runat="server" Text='<%# Eval("tblUserProfile.Phone") %>'>
        </asp:Label>
     </ItemTemplate>
     <EditItemTemplate>
        <asp:TextBox ID="tb1" runat="server" Text='<%#Bind("tblUserProfile.Phone") %>'></asp:TextBox>
      </EditItemTemplate>
   </asp:TemplateField>
1

There are 1 best solutions below

1
On

Perhaps you do not need to qualify the Phone field with tblUserProfile? Try it without; just use DataField="Phone".