views:

126

answers:

1

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  A: 

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

Andy West
That doesn't work... Phone isn't a field or property on the datasource.I wouldn't expect it to work either, otherwise how would you qualify between a column in one table and a same named column in a PK/FK linked table?
Adam