且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在 ASP.NET Web 表单中创建动态 UI

更新时间:2023-02-15 22:50:26

我建议创建一个 userconrol 来实现一个问题(标签)和答案(单选按钮)以及每个控件(标签,单选按钮)绑定到用户控件的属性,然后您可以从数据库中读取问题,并为每个数据创建此用户控件对象,并将相应的数据设置为用户控件的该属性,然后从控制这个状态读取数据,反之亦然.

I suggest create a userconrol that implement a question(label) and answers(radio buttons) and each controls(labels,radios) is binded to a property of your usercontrol, Then you can read questions from database and for each data create this usercontrol object and set correspond data to that property of usercontrol, And to read data from control this state doing vice versa.

尽管您必须在每次回发时重新创建用户控件并将默认数据设置为这些.

Albeit you must recreate usercontrols in each post back and set default data to those.

您还可以创建多个具有不同 UI 的用户控件,这些用户控件继承了界面,例如 IQuestion工厂> 创建每个用户控件的类取决于环境变量.

Also you can create multiple usercontrols with different UI that inherit a interface such as IQuestion, and a factory class that create each of usercontrols depend of environment varibles.