Response.Write单行输出

时间:2014-01-03 12:57:38

标签: asp.net vb.net

我试图在txt文件中的一行中输出gridview中的数据,但输出有多行

Dim str As New StringBuilder()

    For i = 0 To RowNo - 1

        str.Append("EDR,")
        str.Append(GridView1.Rows(i).Cells(9).Text)
        str.Append(",")
        str.Append("929110101,")
        str.Append(GridView1.Rows(i).Cells(8).Text)
        str.Append(",")
        str.Append("1,")
        str.Append(System.DateTime.DaysInMonth(Convert.ToInt32(GridView1.Rows(i).Cells(3).Text), Convert.ToInt32(GridView1.Rows(i).Cells(2).Text)))
        str.Append(",")
        str.Append(System.DateTime.DaysInMonth(Convert.ToInt32(GridView1.Rows(i).Cells(3).Text), Convert.ToInt32(GridView1.Rows(i).Cells(2).Text)))
        str.Append(",")
        str.Append(Convert.ToInt32(GridView1.Rows(i).Cells(7).Text))
        str.Append(",")
        str.Append(GridView1.Rows(i).Cells(5).Text)


    Next


    Response.Clear()

    Response.AddHeader("content-disposition", "attachment;filename=test.txt")

    Response.Charset = "ISO-8859-1"

    Response.Cache.SetCacheability(HttpCacheability.NoCache)

    Response.ContentType = "text/plain"

    Dim stringWrite As New System.IO.StringWriter()

    Dim htmlWrite As System.Web.UI.HtmlTextWriter = New HtmlTextWriter(stringWrite)

    Response.Write(str.ToString())

    Response.[End]()

我的输出就像那样

EDR,00000000000000005353291
,929110101,10020108428318
,1,31,31,7397,0

我需要的是

EDR,00000000000000005353291,929110101,10020108428318,1,31,31,7397,0

2 个答案:

答案 0 :(得分:2)

替换换行符。在VB.NET中,换行符由vbCr,vbLf常量表示。

str= str.Replace(vbCr, "").Replace(vbLf, "")

答案 1 :(得分:0)

您是否尝试过清理字符串?

myString = myString.Replace(Environment.NewLine,"")