尝试在gridview中添加链接

时间:2019-06-06 17:27:44

标签: gridview hyperlink

我已经创建了一个sql数据库,其中一个名为“链接”的列之一具有我网站内以及网站外网站的网站URL。示例我有一个到Geico保险的链接。问题是,当我将此列添加到gridview时,它仅显示网站的网址。我需要它作为指向该网站的链接,我可以单击该链接并显示在新页面中,而我只想将“网站”一词作为链接。

<asp:GridView id="GridView1" runat="server" AutoGenerateColumns="False" BackColor="White" BorderColor="#999999" BorderStyle="None" BorderWidth="1px" CellPadding="3" DataSourceID="apps2" GridLines="Vertical" AllowSorting="True">
    <AlternatingRowStyle BackColor="#DCDCDC" />
    <Columns>
        <asp:HyperLinkField HeaderText="Link" Text="Website" DataNavigateUrlFields="Link" DataNavigateUrlFormatString="{0}" target=_blank/>
        </asp:HyperLinkField>
        <asp:BoundField DataField="Source" HeaderText="Source" SortExpression="Source">
        </asp:BoundField>
        <asp:BoundField DataField="Name" HeaderText="Name" SortExpression="Name">
        </asp:BoundField>
        <asp:BoundField DataField="Address" HeaderText="Address" SortExpression="Address">
        </asp:BoundField>
        <asp:BoundField DataField="City" HeaderText="City" SortExpression="City">
        </asp:BoundField>
        <asp:BoundField DataField="Primary_Number" HeaderText="Phone Number" SortExpression="Primary_Number">
        </asp:BoundField>
        <asp:BoundField DataField="Backup_Number" HeaderText="Backup Number" SortExpression="Backup_Number">
        </asp:BoundField>
        <asp:BoundField DataField="Fax_Number" HeaderText="Fax Number" SortExpression="Fax_Number">
        </asp:BoundField>
        <asp:BoundField DataField="Alarm_Reset_Code" HeaderText="Alarm Reset Code" SortExpression="Alarm_Reset_Code">
        </asp:BoundField>
        <asp:BoundField DataField="First_Contact_Name" HeaderText="1st Contact Name" SortExpression="First_Contact_Name">
        </asp:BoundField>
        <asp:BoundField DataField="First_Contact_Number" HeaderText="1st Contact #" SortExpression="First_Contact_Number">
        </asp:BoundField>
        <asp:BoundField DataField="Second_Contact_Name" HeaderText="2nd Contact Name" SortExpression="Second_Contact_Name">
        </asp:BoundField>
        <asp:BoundField DataField="Second_Contact_Number" HeaderText="2nd Contact #" SortExpression="Second_Contact_Number">
        </asp:BoundField>
        <asp:BoundField DataField="Third_Contact_Name" HeaderText="3rd Contact Name" SortExpression="Third_Contact_Name">
        </asp:BoundField>
        <asp:BoundField DataField="Third_Contact_Number" HeaderText="3rd Contact #" SortExpression="Third_Contact_Number">
        </asp:BoundField>
        <asp:BoundField DataField="Notes" HeaderText="Notes" SortExpression="Notes">
        </asp:BoundField>
        <asp:BoundField DataField="Modified" HeaderText="Date Modified" SortExpression="Modified">
        </asp:BoundField>
    </Columns>

当我使用此脚本时,gridview不会在我的网站上启动。我收到服务器错误,错误之处是超链接字段所在的行。

1 个答案:

答案 0 :(得分:0)

最好使用Gridview的 <ItemTemplate> 显示网站链接。这样,您可以完全自定义HyperLink列的UI /设计。

示例:

$(exec sh -c 'echo $PPID')