Databases Reference
In-Depth Information
</div>
</ItemTemplate>
</asp:FormView>
Notice how the
DynamicHyperLink
controls in this example do not have the
ContextTypeName
and
TableName
properties specified. The
FormView
control databinds its
ItemTemplate
to the entity instance provided by the associated
EntityDataSource
control.
The controls locate the
MetaTable
object based on the entity type and generate URLs that
look like this:
http://localhost/Products/Edit.aspx?ProductID=1
http://localhost/Products/Delete.aspx?ProductID=1
http://localhost/Products/List.aspx?ProductID=1
Dynamic hyperlinks can be also generated with the help of the
RouteUrl
markup expres-
sion. This is a special syntax that ASP.NET parser recognizes and uses to generate a
dynamic URL based on parameter values you specify:
<asp:HyperLink runat=”server” Text=”Show all”
NavigateUrl=”
<%$RouteUrl:table=Products, action=List%>
” />
Under the hood, both the
RouteUrl
markup expression and the
DynamicHyperLink
control
rely on the low-level API the ASP.NET provides for routing. The next code sample illus-
trates how they work by creating a dynamic hyperlink programmatically. It creates a
RouteValueDictionary
to hold the
Table
and
Action
parameter values and then calls the
GetVirtualPath
method of the global
Routes
collection to generate the URL in a form of a
virtual path:
HyperLink hyperLink = // ...
RequestContext context =
DynamicDataRouteHandler.GetRequestContext(HttpContext.Current);
RouteValueDictionary routeValues = new RouteValueDictionary();
routeValues[“table”] = “Products”;
routeValues[“action”] = “List”;
VirtualPathData pathData = RouteTable.Routes.GetVirtualPath(
context, routeValues);
hyperLink.NavigateUrl = pathData.VirtualPath;
Route Evaluation and Constraints
Although you will probably never need to write code that creates dynamic hyperlinks
programmatically, it is important to understand how they are generated by the ASP.NET