问题
I have a gridview databound by a datatable. In one of the columns the people who enter the data put in the location of their facility and a link to their website in the same cell. Like:
Baltimore, MD <a href="www.location.com">Location</a>
How do I make it so the link is read as html?
gridview code:
<asp:GridView ID="GridView3" runat="server" AutoGenerateColumns="False">
<Columns>
<asp:BoundField DataField="start_date" HeaderText ="Start Date" DataFormatString="{0:d}" HtmlEncode="False" />
<asp:BoundField DataField="end_date" HeaderText ="End Date" DataFormatString="{0:d}" HtmlEncode="False" />
<asp:BoundField DataField="sponsor" HeaderText ="Sponsor" />
<asp:HyperLinkField DataNavigateUrlFields ="sponsor_id"
DataNavigateUrlFormatString="http://www.cdc.gov/niosh/topics/spirometry/sponsors.html#c{0}"
HeaderText ="Sponsor Details"
Text="Details"/>
<asp:BoundField DataField="location" HeaderText ="Location" />
<asp:BoundField DataField="region" HeaderText="Region" />
<asp:BoundField DataField="course_type" HeaderText ="Course Type" />
</Columns>
They would be adding to the column bound to the location field.
SOLVED
<Columns>
<asp:BoundField DataField="start_date" HeaderText ="Start Date" DataFormatString="{0:d}" HtmlEncode="False" />
<asp:BoundField DataField="end_date" HeaderText ="End Date" DataFormatString="{0:d}" HtmlEncode="False" />
<asp:BoundField DataField="sponsor" HeaderText ="Sponsor" />
<asp:HyperLinkField DataNavigateUrlFields ="sponsor_id"
DataNavigateUrlFormatString="http://www.cdc.gov/niosh/topics/spirometry/sponsors.html#c{0}"
HeaderText ="Sponsor Details"
Text="Details"/>
<asp:BoundField DataField="location" HeaderText ="Location" HtmlEncode="false" />
<asp:BoundField DataField="region" HeaderText="Region" />
<asp:BoundField DataField="course_type" HeaderText ="Course Type" />
</Columns>
changed htmlencode to false.
来源:https://stackoverflow.com/questions/35319985/html-in-a-gridview