我有一个我的字符串,该字符串绑定到我的gridview中,并且在内部包含一个HTML标签(一个简单的<br>
)。它应该打破我的网站上的线路,但没有。
我的字符串是(例如): text text text <br> text text text
and show <br>
而不是断开行。我希望它看起来像:
text text text
text text text
我的代码:
mygrd.DataSource = GetContentAsDataTable();
mygrd.DataBind();
客户端:
<asp:GridView ID="mygrd" runat="server" AutoGenerateColumns="False">
<Columns>
<asp:BoundField DataField="ID" HeaderText="ID" />
<asp:BoundField DataField="Content" HeaderText="Content" />
</Columns>
</asp:GridView>
感谢您的帮助
添加htmlencode =" false"或htmlencode =" true" <asp:BoundField>
上都可以使用设置播放,并查看是否获得所需的输出。
<asp:BoundField DataField="Content" HeaderText="Content" HeaderStyle-Width="5%" HtmlEncode="false" ItemStyle-Width="5%" ItemStyle-Wrap="false" ReadOnly="true" />
如果那不起作用。
Create a RowDataBound method in the codebehind
Protected Sub mygrd_RowDataBound(sender As Object, e As GridViewRowEventArgs)
If (e.Row.RowType = DataControlRowType.DataRow) Then
e.Row.Cells(yourcellnumber).Text = "text text text <br> text text text"
End If
End Sub
这应该有效。