asp.net gridview DataNavigateUrlFormatString from DataSource

元气小坏坏 提交于 2019-12-07 17:40:28

问题


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:


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.



来源:https://stackoverflow.com/questions/6804488/asp-net-gridview-datanavigateurlformatstring-from-datasource

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!