Asp.net 响应。在单行中写入输出
我试图在txt文件中的一行中从gridview输出数据,但输出是多行的Asp.net 响应。在单行中写入输出,asp.net,vb.net,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
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,0000000000000000 5353291,92911010110020108428318
,1,31,317397,0
我需要的是
EDR,0000000000000000 53535329192911010110020108428318,1,31,317397,0您尝试过对字符串进行消毒吗
myString = myString.Replace(Environment.NewLine,"")
替换换行符。在VB.NET中,换行符由vbCr、vbLf常量表示
str=str.Replace(vbCr,”).Replace(vbLf,”)
不确定,但查看代码,看起来来自网格的数据最后包含一个换行符。也许你可以尝试移除它,它可能会起作用。可以设置断点并检查值。如果有新行字符,可以用空字符串替换它们。