加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c# – 使用网格视图中的HyperLinkField进行URL导航

发布时间:2020-12-15 08:18:33 所属栏目:百科 来源:网络整理
导读:我在gridview中使用HyperLinkField,我想链接到另一个URL ID. div id="searchResults" runat="server" asp:GridView ID="gvSearchResult" runat="server" AutoGenerateColumns = "false" CaptionAlign="NotSet" CellPadding="5" Columns asp:TemplateField He
我在gridview中使用HyperLinkField,我想链接到另一个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使用datasource和databind.它在抱怨:

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方法).

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读