简体   繁体   English

这样做更有效的方法? (ASP.NET文本框)

[英]More efficient way of doing this? (ASP.NET textboxes)

I'm using a Wizard in my ASP.NET page, where in the first step the user chooses from a DropDownList, how many sets of controls will appear in the next wizard step (from 1-5). 我在ASP.NET页中使用向导,在第一步中,用户从DropDownList中选择,下一向导步骤(从1-5)将显示多少组控件。

For example, in the 2nd step of the wizard there are 3 textboxes. 例如,在向导的第二步中,有3个文本框。 If they choose 2 on the previous screen, there will be 6 as there will be 2 sets of these. 如果他们在上一个屏幕上选择2,则将有6个,因为它们将有2套。

I need to be able to store the contents of all these textboxes in a database (simple part I think, there's 5 columns and all can be null. 我需要能够将所有这些文本框的内容存储在数据库中(我认为这很简单,有5列,并且所有列都可以为null。

The easy way of doing this I think is just creating all of the possible controls (5 sets), and hiding them based on what they choose in the previous screen. 我认为最简单的方法就是创建所有可能的控件(5套),然后根据它们在上一屏幕中选择的内容将其隐藏。 Is there a more efficient/easier way? 有没有更有效/更简便的方法?

Thanks 谢谢

It really depends on your definition of efficient/easier. 这实际上取决于您对高效/简便的定义。
A more standard approach would be to use a repeater control to display the correct number of controls based on previous input. 一种更标准的方法是使用转发器控件根据以前的输入显示正确数量的控件。 However if you have not used a repeater control before there will be a degree of learning involved in displaying your output and retrieving user input during the postback. 但是,如果您以前没有使用过中继器控件,则在回发期间显示输出和检索用户输入将涉及一定程度的学习。

您可以使用ASP.NET向导控件

If you absolutely know that 5 boxes is the max, and it is highly unlikely that there would ever be more than that, using Control.Visible on the server controls and their interface items such as label or what ever else, would work... but... 如果您绝对知道最多5个框,并且使用Control.Visible在服务器控件及其接口项(例如label或其他任何控件)上工作的可能性不大可能超过... 但...

It's a bit brittle of a solution, though; 但是,这有点脆弱。 Requiring you to make manual code changes in a few places if you decide to add more possible boxes. 如果您决定添加更多可能的框,则需要在一些地方进行手动代码更改。

A dynamic solution would let you set a maximum number of options in config, or just a single place in code. 动态解决方案可以让您在config中设置最大数量的选项,或者在代码中仅设置一个位置。 It would probably require you to change your database structure a little bit, but that would likely be better for normalization, anyway. 可能需要您稍微更改数据库结构,但是无论如何,这对于标准化来说可能会更好。 It involves dynamically generating the items in the step of the wizard, too. 它还涉及在向导步骤中动态生成项目。

(More info on that option can be had if desired!) (如果需要,可以提供有关该选项的更多信息!)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM