Web表单上的动态内容 [英] Dynamic Content on Web Form

查看:104
本文介绍了Web表单上的动态内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经继承了一个站点,程序员在文件后面的代码中使用stringbuilder来保存动态生成的html,然后将stringbuilder字符串分配给Web表单上的div控件.在我看来,这是一种古老的处理方式,可以有效地将页面转换为经典的ASP.在设计时使用适当的.net控件会失去所有.net优势.

我正在尝试将此页面转换为适当的.net形式.

我已经设法对页面的大部分区域执行了此操作,但是在一部分中,一个循环中存在一个循环,并且这些循环中的每个循环都可以具有任意数量的项.一个例子可以更清楚地说明我们拥有用户指定为其首选品牌和型号的汽车的品牌和型号.用户A的数据可能如下所示
福特

 焦点
 彪马
  Sierra
奥迪

  A3
  A5
大众汽车

 高尔夫
 马球
 帕萨特
 甲虫

用户B可能看起来像
福特

 焦点
 彪马
奔驰

  SLK

我需要根据用户从数据库中检索数据,然后以与上面显示的方式类似的方式进行分配,即按层次结构依次排列Make和模型.

在Web表单上处理此问题的最佳方法是什么?我知道我可以检索汽车制造商并将其分配为外部中继器的数据源,但是我如何为每个外部中继器项下的模型创建内部中继器?我应该完全使用中继器吗?

希望这有道理,
预先感谢,
Slimms.

I have inherited a site where the programmer, in the code behind file, uses a stringbuilder to hold dynamically generated html and then assigns the stringbuilder string to a div control on the web form. This seems to me to be an old school way of doing things and effectively turns the page into classic asp. One loses all of the .net benefits using proper .net controls at design time.

I am attempting to convert this page to a proper .net form.

I have managed to do this with most areas of the page but in one part there is a loop within a loop and each of those loops can have any number of items. An example may make this clearer say we have Make and Models of cars which the user has specified as their preferred makes and models. users A''s data might look like the following
Ford

 Focus
 Puma
 Sierra
Audi

 A3
 A5
Volkswagen

 Golf
 Polo
 Passat
 Beetle

user B''s may look like
Ford

 Focus
 Puma
Mercedes

 SLK

I need to retrieve the data from the database based on the user and then dislpay it in a similar fashion to that shown above i.e hierarchically Make followed by models.

What is the best way to handle this on a web form? I understand i could retrieve the car makes and assign those as the datasource for an outer repeater but then how do i create the inner repeaters for the models under each outer repeater item? Should i use repeaters at all?

Hope this makes sense,
Thanks in advance,
Slimms.

推荐答案

我肯定会尝试使用嵌套的Repeater控件.您可以使用外部Repeater的ItemDataBound事件来对内部Repeater进行数据绑定:

[ http://msdn.microsoft.com/zh-cn/library/system.web.ui.webcontrols.repeater_events.aspx ]
I''d definitely try using nested Repeater controls. You can use the outer Repeater''s ItemDataBound Event to databind the inner Repeater:

[http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.repeater_events.aspx]


这篇关于Web表单上的动态内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆