在 ASP.NET 中创建表的其他选项

发布于 2024-11-16 08:19:43 字数 124 浏览 0 评论 0原文

我正在后面的代码中使用 StringBuilder 创建一个巨大的 html 表,基于用户选择的各种搜索条件。逻辑很复杂,因为我必须创建子标题、嵌套表格等,而且很难维护或修改。有没有更好的方法来处理此类问题?

谢谢!!

I am creating a huge html table using StringBuilder in the code behind, based on various search criterias selected by the user. The logic is complex as I have to create sub heading, nested tables etc. and it is really hard to maintain or modify. Is there a better way to deal with such kind of problems?

Thanks!!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

过去的过去 2024-11-23 08:19:43

所有 ASP 和 Html 控件都封装在类中。您对表<感兴趣/code>类(对于 ASP)和 HtmlTable 用于更轻量级的纯 html 类。

如果我必须选择,我会选择 html 版本,除非您想将服务器端事件添加到表中。

All ASP and Html controls are encapsulated in classes. You're interested in the Table class (for ASP) and HtmlTable for the more light-weight, html-only class.

If I had to choose, I'd go for the html one, unless you want to add server-side events to the table.

余生共白头 2024-11-23 08:19:43

几年前我也遇到过同样的情况。问题包括动态栏、副标题、单元格,一切。典型的表格大约有 1000 行和 50 列(即 50,000 个单元格!)。最初的实现使用了 GridView 并且执行得很糟糕。我重写了视图以使用 Repeater,这是一个非常轻量级的循环控件,带有 Literal 控件。与 100% StringBuilder 相比,这有点疯狂。我将其与一堆返回标准 html 位的字符串表示形式的静态方法结合起来(有点像 ASP.NET MVC 的“html 助手”),并保持对象模型完全隔离。一切都非常快(我忘记了,但我认为 RepeaterLiteral 控件的呈现方式是直接响应流的,因此性能与 StringBuilder,也许更好)。

即使上述内容也会很复杂,并且类似于您自己的方法。但保持理智的关键是保持不同部分的独立(对象模型、html 生成和动态绑定)。这几乎就像构建您自己的临时框架一样。但对于像这样严肃的工作,您需要在仅限于网络浏览器的情况下了解具体情况。

A few years ago I was in the same situation. The problem included dynamic columns, subheadings, cells, everything. A typical table would be around 1000 rows and 50 columns (that's 50,000 cells!). The original implementation used a GridView and performed horribly. I rewrote the view to use a Repeater, a very light-weight looping control, with Literal controls. That reigned in a bit of the madness vs. 100% StringBuilder. I combined that with a bunch of static methods which returned string representations for standard html bits (kind of like ASP.NET MVC's "html helpers"), as well as keeping the object model completely isolated. It was all very fast (I forget, but I think the way the Repeater and Literal controls are rendered is directly to the response stream, so performance was comparable to StringBuilder, perhaps even better).

Even the above will be complex, and is akin to your own approach. But the key to maintaining sanity is to keep the different pieces separate (object model, html generation, and dynamic binding). It's almost like building your own ad-hoc framework. But for serious jobs like this, you need to get nitty-gritty when confined to web browsers.

梦断已成空 2024-11-23 08:19:43

始终有内置的本机 ASP.NET Table 控件

http://www.w3schools.com/aspnet/ control_table.asp

There's always the built in native ASP.NET Table control

http://www.w3schools.com/aspnet/control_table.asp

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文