ASP.NET:将DataTable呈现到字符串(HTML)的最短方法?
发布时间:2020-12-15 19:16:25 所属栏目:asp.Net 来源:网络整理
导读:将DataTable转换为字符串(以 HTML格式化)的最短方法是什么? 以编程方式绑定到UI控件和呈现到ASP.NET页面是不可接受的.不能依赖于ASP.NET页面生命周期. 这样做的目的不应该是重要的,而是为了满足好奇心:这是用于进行大量DataTable处理的算法中的日志/调试/
将DataTable转换为字符串(以
HTML格式化)的最短方法是什么?
以编程方式绑定到UI控件和呈现到ASP.NET页面是不可接受的.不能依赖于ASP.NET页面生命周期. 这样做的目的不应该是重要的,而是为了满足好奇心:这是用于进行大量DataTable处理的算法中的日志/调试/转储目的. 谢谢! 解决方法
您可以使用ASP.NET控件,如GridView,DataGrid,并使用StringWriter将它们渲染到StringBuilder中,无需为此使用ASP.net页面,这是Console中的一个简单示例
class Program { static void Main(string[] args) { IList<Person> persons = new List<Person>() { new Person{Id = 1,Name="Test Name 1"},new Person{Id = 2,Name="Test Name 2"} }; GridView gridView = new GridView(); StringBuilder result = new StringBuilder(); StringWriter writer = new StringWriter(result); HtmlTextWriter htmlWriter = new HtmlTextWriter(writer); gridView.DataSource = persons; gridView.DataBind(); gridView.RenderControl(htmlWriter); Console.WriteLine(result); } } class Person { public int Id { get; set; } public string Name { get; set; } } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- asp.net-mvc – 在Web API 2中使用MVC 5 AttributeRouting的
- asp.net – SyndicationFeed:内容为CDATA?
- 在子目录中部署ASP.NET应用程序
- 在asp.net中使用太多会话的缺点
- asp.net-mvc – EF映射对象不兼容的数据读取器异常
- asp.net-mvc – Identity Server 3 – 客户端应用程序未知或
- 难道调用ThreadPool.QueueUserWorkItem()的时候,真是必须
- 在ASP.NET(C#)中创建动态RSS提要页面 – 我是否需要做额外的
- asp.net网站与网络应用程序
- ASP.NET – Web.config登录错误找不到存储过程’dbo.aspnet
推荐文章
站长推荐
- asp.net – odbc连接的连接字符串是什么?
- asp.net 读取xml文件里面的内容,绑定到dropdown
- asp.net – 从MVC控制器返回不同的视图
- asp.net – 如何在OnActionExecuting中获取当前路
- asp.net-mvc-3 – 如何通过ajax上传文件
- asp.net – 如何使用SqlDependency使OutputCache
- entity-framework – WithOptional with Entity
- asp.net-mvc – 在IIS 5.1上部署ASP.NET MVC(Win
- asp.net-mvc – ASP.NET MVC:使用没有IClientVa
- asp.net-mvc-3 – 局部变量在Razor助手中不起作用
热点阅读