怎么将datagridview 中显示的数据导入txt文件中?

给个代码或者例子就是将绑定在控件的内容写入一个txt文件中
2025-01-06 05:19:06
推荐回答(2个)
回答1:

导入到xls文件中!
protected void Button1_Click(object sender, EventArgs e)
{
Export("Application/MS-excel", "某报表.xls");
}

private void Export(string FileType, string FileName)
{
Response.Charset = "GB2312";
Response.ContentEncoding = System.Text.Encoding.UTF7;
Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(FileName, Encoding.UTF8).ToString());
Response.ContentType = FileType;
this.EnableViewState = false;
StringWriter sw = new StringWriter();
HtmlTextWriter htw = new HtmlTextWriter(sw);
GridView1.RenderControl(htw);
Response.Write(sw.ToString());
Response.End();
}

回答2:

不是吧?应该把数据源导入到txt文件中!