I'm using a HyperLinkField
inside a gridview
, and I want to link to another URL + an ID.
<div id="searchResults" runat="server">
<asp:GridView ID="gvSearchResult" runat="server" AutoGenerateColumns = "false"
CaptionAlign="NotSet" CellPadding="5">
<Columns>
<asp:TemplateField HeaderText="Användare">
<ItemTemplate>
<%# Eval("UName")%>
<br />
</ItemTemplate>
</asp:TemplateField>
<asp:HyperLinkField DataNavigateUrlFields="UName"
DataNavigateUrlFormatString='/MemberPages/profile.aspx?ID=<%# Eval("PID") %>'
DataTextField="UName"
HeaderText="Besök sida"
SortExpression="Name"
ItemStyle-Width="100px"
ItemStyle-Wrap="true" />
</Columns>
</asp:GridView>
</div>
The gridview
is using datasource
and databind
. It's complaining about:
DataNavigateUrlFormatString="/MemberPages/profile.aspx?ID=<%# Eval("PID") %>"
I'm not sure where to use <%# Eval("PID") %>
, I'm sure there is something like PID, I've doublechecked.
If I'm using NavigateUrl="/MemberPages/profile.aspx?ID=<%# Eval("PID") %>"
I also get the same error:
Literal content ('<asp:HyperLinkField DataNavigateUrlFields="UName"
DataNavigateUrlFormatString="/MemberPages/profile.aspx?ID=') is not allowed within a 'System.Web.UI.WebControls.DataControlFieldCollection'.
If you need to use " inside attribute value, use ' as delimiter
Attribute='Some value with " symbol'
If you need to use ' inside attribute value, use "
Attribute="Some value with ' symbol"
Also change your column definition
<asp:HyperLinkField DataNavigateUrlFields="PID"
DataNavigateUrlFormatString="/MemberPages/profile.aspx?ID={0}"
DataTextField="UName"
HeaderText="Besök sida"
SortExpression="Name"
ItemStyle-Width="100px"
ItemStyle-Wrap="true" />
In DataNavigateUrlFormatString attribute you use data column specified in DataNavigateUrlFields (the formating is similar to String.Format method).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With