gpt4 book ai didi

c# - 在 gridview 中使用 HyperLinkField 进行 URL 导航

转载 作者:太空狗 更新时间:2023-10-29 21:13:34 26 4
gpt4 key购买 nike

我正在使用 HyperLinkFieldgridview 里面,我想链接到另一个 URL + 一个 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>

gridview正在使用 datasourcedatabind .它提示:

DataNavigateUrlFormatString="/MemberPages/profile.aspx?ID=<%# Eval("PID") %>"

我不确定在哪里使用 <%# Eval("PID") %> ,我确定有类似 PID 的东西,我已经仔细检查过了。

如果我使用 NavigateUrl="/MemberPages/profile.aspx?ID=<%# Eval("PID") %>"我也遇到同样的错误:

Literal content ('<asp:HyperLinkField DataNavigateUrlFields="UName" 
DataNavigateUrlFormatString="/MemberPages/profile.aspx?ID=') is not allowed within a 'System.Web.UI.WebControls.DataControlFieldCollection'.

最佳答案

如果您需要在属性值内部使用 ",请使用 ' 作为分隔符

Attribute='Some value with " symbol'

如果需要在属性值内部使用',使用"

Attribute="Some value with ' symbol"

同时更改您的列定义

<asp:HyperLinkField DataNavigateUrlFields="PID" 
DataNavigateUrlFormatString="/MemberPages/profile.aspx?ID={0}"
DataTextField="UName"
HeaderText="Besök sida"
SortExpression="Name"
ItemStyle-Width="100px"
ItemStyle-Wrap="true" />

在 DataNavigateUrlFormatString 属性中,您使用 DataNavigateUrlFields 中指定的数据列(格式类似于 String.Format 方法)。

关于c# - 在 gridview 中使用 HyperLinkField 进行 URL 导航,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14266537/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com