Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>In fact, the first method you used is perhaps the most optimal solution as the query has already been made on the server-side to determine whether the column data matches the foreign key relationship. No more querying is needed, just test <code>FieldValue == null</code>. Besides, the template controls are there to be edited, which is why they're not compiled to assemblies:</p> <pre><code>protected string GetDisplayString() { object value = FieldValue; if (value == null) { //replace this //return FormatFieldValue(ForeignKeyColumn.GetForeignKeyString(Row)); //with this return ""; } else { return FormatFieldValue(ForeignKeyColumn.ParentTable.GetDisplayString(value)); } } </code></pre> <p>However, if you intend to preserved the value of the source field, use this method instead:</p> <pre><code>protected string GetNavigateUrl() { //replace this //if (!AllowNavigation) //with this if (!AllowNavigation || FieldValue == null) { return null; } if (String.IsNullOrEmpty(NavigateUrl)) { return ForeignKeyPath; } else { return BuildForeignKeyPath(NavigateUrl); } } </code></pre> <p>Under certain conditions (including the default css styles), it will generate a hyperlink-looking field that cannot be clicked. You can use jQuery to filter and remove those false hyperlinks by setting their <code>outerHTML</code> as their <code>innerHTML</code> (client-side scripting). Of course, there are more elegant methods like adding a <code>&lt;asp:label&gt;</code> to the ForeignKey.ascx and switching to that control when needed.</p> <p>Note: this method works when using ADO.NET Entity Data Model. I didn't try it on LinqToSqlClasses.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload