如何用vb.net中的新行替换break标记 [英] how to replace a break tag with a new line in vb.net
本文介绍了如何用vb.net中的新行替换break标记的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
< asp:TemplateField HeaderText = 考试程序 HeaderStyle-Width = 315px >
< ; ItemTemplate >
< asp:标签 ID = lblRepExamProc runat = server 文字 =' <% #Eval( PRCS_EXAM_PROCEDURE)%> ' / >
< / ItemTemplate >
< / asp:TemplateField >
// gridload
私有 Sub LoadGrid()
Dim dtPrcs As DataTable
dtPrcs = clsPRCS.ListData()
如果 dtPrcs.Rows.Count> 0 然后
gridExamProcs.DataSource = dtPrcs
gridExamProcs.DataBind()
displayInfoNoRecords.Visible = False
否则
displayInfoNoRecords.Visible = True
gridExamProcs.Visible = False
结束 如果
' 返回dtUserDetails
结束 Sub
//划船活动
受保护的 Sub gridExamProcs_RowDataBound(sender As 对象,e As System.Web.UI.WebControls.GridViewRowEventArgs)句柄 gridExamProcs.RowDataBound
如果 e.Row.RowType = DataControlRowType.DataRow 然后
Dim lblRepExamProc = DirectCast (e.Row.FindControl( lblRepExamProc),Label)
lblRepExamProc。 Text = lblRepExamProc.Text.Replace( < \\\
>, < br />)
结束 如果
结束 Sub
解方案
而不是做你想要的,你正在替换< \\\
(这是一个空标记,里面有新行;为什么?)带换行标记。难怪这不是你所期望的。 :-)
>
根据您的信息,没有通用文字新行:
http://en.wikipedia.org/wiki/New-line [ ^ ]。
新行与系统有关。与Web应用程序一样,您不知道客户的系统是什么,最好避免使用它。在.NET中,便携式新产品线如下:
http ://msdn.microsoft.com/en-us/library/system.environment.newline.aspx [ ^ ]。
-SA
<asp:TemplateField HeaderText="Examination Procedures" HeaderStyle-Width="315px">
<ItemTemplate>
<asp:Label ID="lblRepExamProc" runat="server" Text='<%#Eval("PRCS_EXAM_PROCEDURE")%>' />
</ItemTemplate>
</asp:TemplateField>
//gridload
Private Sub LoadGrid()
Dim dtPrcs As DataTable
dtPrcs = clsPRCS.ListData()
If dtPrcs.Rows.Count > 0 Then
gridExamProcs.DataSource = dtPrcs
gridExamProcs.DataBind()
displayInfoNoRecords.Visible = False
Else
displayInfoNoRecords.Visible = True
gridExamProcs.Visible = False
End If
' Return dtUserDetails
End Sub
//rowbound event
Protected Sub gridExamProcs_RowDataBound(sender As Object, e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles gridExamProcs.RowDataBound
If e.Row.RowType = DataControlRowType.DataRow Then
Dim lblRepExamProc = DirectCast(e.Row.FindControl("lblRepExamProc"), Label)
lblRepExamProc.Text = lblRepExamProc.Text.Replace("<\n>", "<br/>")
End If
End Sub
解决方案
Instead of doing what you want, you are replacing"<\n>"
(which is an empty tag with new line inside it; why?) with a line break tag. No wonder this is not what you expected. :-)
For your information, there is no universal text new line:
http://en.wikipedia.org/wiki/New-line[^].
New line is system-dependent. As with a Web application you don''t know what is your client''s system, it''s the best to avoid it. In .NET, the portable new line is this:
http://msdn.microsoft.com/en-us/library/system.environment.newline.aspx[^].
—SA
这篇关于如何用vb.net中的新行替换break标记的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文