GridView LINQ double foreign key

  • Thread starter Thread starter Chuck P
  • Start date Start date
C

Chuck P

I can run the following query in LinqPad

from u in UsersInRoles
select new {u.ApplicationID, u.ApplicationRoles.Application.ApplicationName}

However,
<asp:LinqDataSource ID="LinqDataSource1" runat="server"
ContextTypeName="ApplicationManagment.ApplicationsDataContext"
TableName="UsersInRoles" StoreOriginalValuesInViewState="False">
</asp:LinqDataSource>

<asp:Label ID="lblApplicationName" runat="server" Text='<%#
Bind("ApplicationRoles.Application.ApplicationName") %>'></asp:Label>

Parser Error Message: A call to Bind was not well formatted. Please refer
to documentation for the correct parameters to Bind.


Is the double link not allowed or wrong syntax in a GridView?
The Primary Key on ApplicationRoles is on ApplicationID, RoleID (FK to
UsersInRoles)


The tables are Applications (description of application; PK ApplicationID)
ApplicationRoles (the roles allowed in an application )
UsersInRoles (users in a role for an application)
 
Hello Chunk

This is a frequently asked question. The error "A call to Bind was not well
formatted. Please refer to documentation for the correct parameters to
Bind" is listed by the compiler because it can only be bound to the
first-level properties of a class object. In your code snippet,
Bind("ApplicationRoles.Application.ApplicationName") has three levels,
thus, the error appears. My colleague, Linda, once wrote a blog for the
issue:
http://blogs.msdn.com/msdnts/archive/2007/01/19/how-to-bind-a-datagridview-c
olumn-to-a-second-level-property-of-a-data-source.aspx. It shows a
workaround to bind to the second, third, or any other level of sub
properties. Another possible workaround is to move the third level property
to the first level by using creating a DB view.

Please let me know if you have any other concerns, or need anything else.

Regards,
Jialiang Ge ([email protected], remove 'online.')
Microsoft Online Community Support

Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 
Hello Chunk

This is a frequently asked question. The error ¡°A call to Bind was not well
formatted. Please refer to documentation for the correct parameters to
Bind¡± is listed by the compiler because it can only be bound to the
first-level properties of a class object. In your code snippet,
Bind("ApplicationRoles.Application.ApplicationName") has three levels, thus,
the error appears. My colleague, Linda, once wrote a blog for the issue:
http://blogs.msdn.com/msdnts/archiv...a-second-level-property-of-a-data-source.aspx.
It shows a workaround to bind to the second, third, or any other level of
sub properties. Another possible workaround is to move the third level
property to the first level by using creating a DB view.

Please let me know if you have any other concerns, or need anything else.

Regards,
Jialiang Ge ([email protected], remove ¡®online.¡¯)
Microsoft Online Community Support

Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notifications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 
Hello Chunk

You may have noticed that Scott Gu's blog uses "Eval", a one-way
databinding keyword, to bind the 2-level property "Supplier.CompanyName".
It's not using the keyword "Bind". "Bind" supports two-way databinding,
i.e, both selecting and updating the data, however, it suffers from the
defects that it cannot bind mult-level properties. That's to say, if we
modify Scott's blog to use "Bind":

<asp:TemplateField HeaderText="Supplier"
SortExpression="Supplier.ComparyName">
<ItemTemplate>
<asp:Label runat="server" ID="lbl" Text='<%#
Bind("Supplier.CompanyName") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>

It will also throw the error "A call to Bind was not well formatted.
Please¡­" in the compilation time.

In order to work-around this problem and do "update" operations on the
Category column, Scott uses an additional dropdownlist "CategoryList" to
bind to the data source "CategoryDataSource". In this way, the "Text" shown
in UI is the readable category name, but the real value bound to the column
will still be the category ID, i.e. the one-level property.

All in all, "Eval" supports mult-level property, but does not support the
operation of "update", whereas, "Bind" supports "update", but it suffers
from one-level property binding. Therefore, Chunk, you may consider Scott's
workaround in his blog entry, or my two in the last reply. Is this
explanation helping you have a clearer picture about how "Bind" and "Eval"
work in databinding?

Thanks
Jialiang Ge ([email protected], remove 'online.')
Microsoft Online Community Support

=================================================
Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).

This posting is provided "AS IS" with no warranties, and confers no rights.
=================================================
 
Hello Chuck,

I am writing to check the status of the issue on your side. Would you mind
letting me know the result of the suggestions? If you need further
assistance, feel free to let me know. I will be more than happy to be of
assistance.

Have a great day!

Regards,
Jialiang Ge ([email protected], remove 'online.')
Microsoft Online Community Support

=================================================
Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).

This posting is provided "AS IS" with no warranties, and confers no rights.
=================================================
 
Back
Top