asp.net gridview DataNavigateUrlFormatString from

2019-05-16 10:05发布

I have a gridview that is being populated from a datasouce.
The Stored procedure that is populating the datasource, has a field "Client" and a field "Client WebSite".

I want to populate the field "Client" in the gridview column called "Client" which would be a hyperlink field and the hyperlink field would be the "Client WebSite" value from the dataset. The client website is an external site (not within my asp project)

Below is my html code. How can I get the "Client WebSite" appear as the DataNavigatrURL value?

            <asp:HyperLinkField DataTextField="Client" HeaderText="Client" DataNavigateUrlFields="Client"
                DataNavigateUrlFormatString="Client WebSite">
                <HeaderStyle HorizontalAlign="Center" />
                <ItemStyle HorizontalAlign="Left" />
            </asp:HyperLinkField>

1条回答
混吃等死
2楼-- · 2019-05-16 11:02

Use databinding on the NavigateUrl attribute, like this:

NavigateUrl = '<%# Bind("ClientWebSite") %>'

Or more fully:

<asp:HyperLinkField DataTextField='<%# Bind("Client" %>' HeaderText="Client" NavigateUrl='<%# Bind("ClientWebSite") %>'>
    <HeaderStyle HorizontalAlign="Center" />
    <ItemStyle HorizantalAlign="Left" />
</asp:HyperLinkField>

DataNavigateUrlFields is used to gets or set the names of the fields from the data source used to construct the URLs for the hyperlinks in the HyperLinkField object.

'DataNavigateUrlFormatString` is used to gets or sets the string that specifies the format in which the URLs for the hyperlinks in a HyperLinkField object are rendered.

查看更多
登录 后发表回答