为公司存储和选择多个州/城市的最佳方式?
我有 A 公司。我需要能够将该公司链接到多个州,而每个州又可以链接到多个城市。 例如:
Company A
\
- State A
|-City A
|-City B
\ |-City C
- State B
|-City A
|-City B
\ |-City C
- State C
|-City A
|-City B
|-City C
我的问题是:
- 将其存储在表中的最佳方法是什么?
- 允许用户选择此选项而无需多次刷新页面的最简单方法是什么?
我使用 ASP.NET (Framework 3.5) 和 C#。 如果有任何控件可以做到这一点,那么指向它们的指针也将受到高度赞赏。
谢谢,
吉姆
编辑:例如,我需要选择“公司 A”。 然后选择“状态A”。 在“A 州”下,我选择“A、B 和 C 城市”。 然后选择“State B”,并在其下选择“City A & B”。
I have Company A. I need the ability to link this Company to multiple States, and each state can in turn be linked to multiple Cities. For example:
Company A
\
- State A
|-City A
|-City B
\ |-City C
- State B
|-City A
|-City B
\ |-City C
- State C
|-City A
|-City B
|-City C
My questions are:
- What is the best way to store this in a table?
- What is the easiest way to allow a user to choose this without multiple page refreshes?
I use ASP.NET (Framework 3.5) with C#. If there are any controls around that can do this, a pointer to them would be most appreciated too.
Thanks,
Jim
Edit: For example, I need to choose "Company A". Then choose "State A". Under "State A", I choose "City A, B & C". Then choose "State B" and under that choose "City A & B".
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可能希望将其存储在四个表中,
这样,州和城市就可以在没有公司的情况下存在。
至于选择它们的控件,如果要选择单个城市,可以使用 AJAX CascadingDropDownList 可能是最好的选择。
在没有多次页面刷新的情况下执行此操作(至少如果我理解正确的话)将非常困难,并且可能会让用户感到困惑。 最好的办法是让它们尽可能无痛,这可能涉及也可能不涉及使用 AJAX。
You will probably want to store this in four tables
This way, states and cities can exist without companies.
As far as a control to select them, if you want to select a single city, an AJAX CascadingDropDownList may be the best option.
Doing this without multiple page refreshes, at least if I understand you correctly, will be extremely difficult and probably confusing for the user. Your best shot is to make them as painless as possible, which may or may not involve using AJAX.
要回答您的第一个问题,我会将其存储为:
您可能会考虑做的一件事是将公司链接到城市键,并将 FK 链接到城市,并拥有像 usa;fl;null 和 usa;ca;null 这样的城市代表该州内的所有城市。 通过这种方式转换为基于特定城市的公司并不会真正改变您的整体计划。 如果您知道您将始终与与州相关的公司打交道,那么最好在公司中执行 state_id (如上所示)。
祝你的项目好运。
To answer your first question, I would store it something like:
One thing you might consider doing is to link the companies to the city key and FK into city instead, and have a cities like usa;fl;null and usa;ca;null to represent all cities within that state. This way converting over to companies based on a specific city doesn't really change your overall scheme. If you know that you'll always be dealing with companies linked to states, then doing the state_id in companies (as shown above) would be preferrable.
Good luck with your project.