如何将这个经典的 ASP 转换为 ASP.NET

发布于 2024-09-05 21:47:39 字数 169 浏览 5 评论 0原文

我有一些经典的 asp 代码需要转换为 asp.net。到目前为止,我已经尝试使用数据读取器和中继器来实现此目的,但没有成功,因为菜单循环遍历 4 个不同的记录集,在移动到下一个记录之前传递 menuNid。

请您告诉我您将使用什么方法来转换此代码...即数据读取器?数据集? ETC?

谢谢

I have some classic asp code that needs converting to asp.net. So far I have tried to achieve this using datareaders and repeaters and had no luck as the menu loops through 4 different record sets, passing along the menuNid before moving to the next record.

Please can you tell me what method you would use to conver this code... i.e datareaders? dataset? etc?

Thanks

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

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

发布评论

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

评论(2

安穩 2024-09-12 21:47:39

哎哟...这是一些缓慢且重复的代码...(请原谅我直言不讳...)

您可以将所需的所有数据读入 DataTable(使用 DataSet 和 SqlDataAdapter),以便您可以重用它并不必对菜单中的每个级别和每个项目运行查询。这样,您就可以进行单个数据库调用,而不是进行大量数据库调用,并且数据库调用绝对是此代码中的瓶颈。

您可以使用递归来获得不同的级别,而不是一遍又一遍地重复相同的代码。

要构建菜单元素,您有多种选择。一种方法是在页面中放置一个 PlaceHolder,并通过将它们添加到彼此的 Controls 集合中来创建控件树。另一种选择是简单地在 StringBuilder 中自行构建 HTML 代码,并将结果放入 Literal 控件中。

Ouch... That's some slow and repetetive code... (Excuse me for being blunt...)

You could read all the data that you need into a DataTable (using a DataSet and a SqlDataAdapter) so that you can reuse it and don't have to run a query for every level and every item in the menu. That way you can have a single database call instead of a whole lot of them, and the database calls is absolutely the bottle neck in this code.

You could use recursion to get different levels, instead of repeating the same code over and over again.

To build the elements for the menu you have several options. One is to put a PlaceHolder in the page and create a tree of controls by adding them to each others Controls collection. Another option is to simply build the HTML code yourself in a StringBuilder, and put the result in a Literal control.

方圜几里 2024-09-12 21:47:39

嗯,你有几个选项。asp.net

支持 asp 样式表示法,意思是 <% %>等仍然受支持..并且您可以通过一些小的调整使您的代码几乎保持原样..
但你会错过它所提供的 90% 的东西。即标记和代码的分离。

我建议您熟悉 ASP.NET 中的服务器控件模型,并重写您的页面以使用它来摆脱所有%废话。

我们无法以表单答案教您 ASP.NET,但服务器控件是那里的方法论的核心,所以理解它们将使您非常接近获得如何着手转换您的东西的好主意。
http://www.w3schools.com/ASPNET/aspnet_controls.asp

well you have couple options there..

asp.net supports asp style notation, meaning <% %> etc are still supported.. and you could keep your code almost as is with some minor tweaking..
but you'd be missing out on 90% of what it has to offer. Namely the separation of markup and and code.

I recommend you familiarize your self with server control model in asp.net, and rewrite your pages to use that to get rid of all the % crap..

we can't teach you asp.net in a form answer, but server controls are the heart of the methodology there, so understanding them will bring you very close to getting a good idea in how to go about transitioning your stuff..
http://www.w3schools.com/ASPNET/aspnet_controls.asp

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