如何使用Web窗体和一个GridView的HyperLinkFields路由 [英] How to use routing in web forms and HyperLinkFields of a GridView
问题描述
我有这样映射路线:
routes.MapPageRoute("section-page-id", "{section}/{page}/{id}", "~/{section}/{page}.aspx")
我有一个HyperLinkField字段的GridView使用看起来像这样:
I have a GridView with a HyperLinkField that use to look like this:
<asp:HyperLinkField NavigateUrl="<%$RouteUrl:RouteName=section-page-id,section=Clients,page=Groups,id=5%>" Text="Groups" />
这工作正常;不过,我想有5作为在GridView的记录动态ID。之前我试过路由,我会用DataNavigateUrlFields但我无法得到它的工作在这里。有什么建议?
This works fine; however, I want to have the 5 as the dynamic Id of the record in the GridView. Before I tried routing, I would use DataNavigateUrlFields but I cannot get it working here. Any suggestions?
推荐答案
在ASP超链接控件将无法正常工作,但一个简单的锚会!我试图吨,服务器端code和引用控制不同的解决方案,但是这似乎是我一直在asp.net 4.0 Web表单一个gridview和路由发现的唯一解决方案。
The asp hyperlink control will not work, but a simple anchor will! I tried tons of different solutions with server side code and referencing controls, but this appears to be the only solution I have found with a gridview and routing in asp.net 4.0 web forms.
<asp:TemplateField>
<ItemTemplate>
<a href="<% #GetRouteUrl("section-page-id",
new with {.section="Clients", .page="Groups", .id=Eval("Id")})%>">test</a>
</ItemTemplate>
</asp:TemplateField>
这篇关于如何使用Web窗体和一个GridView的HyperLinkFields路由的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!