使用 AJAX 填充下拉列表
我有 3 个下拉框,是使用 HTML 选择标签创建的。页面加载时,第一个框有几个名称。现在,当我单击第一个框中的一个名称时,第二个框中应出现更多名称,当我单击第二个框中的名称时,第三个框中应出现更多名称。如何使用 AJAX 实现此目的?我只能使用 ASP.Net 和 MS SQL Server。我对 AJAX 完全是个菜鸟,我一直在自学这方面的知识,但没有任何效果。我已经寻找代码近一周了。我查了一下 w3schools.com,但是当我尝试该代码时,它不起作用。请帮助我,请一步步告诉我,要使其工作所需的东西,以及什么放在哪里。我的最后期限即将到来,但我却束手无策,试图让它发挥作用。帮我!!
I have 3 drop down boxes, created using the HTML select tag. On page load, the first box has a few names. Now, when I click on one of the names in the first box, some more names should appear in the second and when I click on a name in the second box, some more names should appear in the third box. How can I achieve this using AJAX? I have to use ASP.Net and MS SQL Server only. I'm a complete noob to AJAX and I've been educating myself about it, but nothing's working out. I've been looking for the code for close to a week. I looked up w3schools.com, but when I tried that code, it didn't work. Please help me out and please tell me step by step, the things required in order to make it work, and what goes where. I have a deadline that is fast approaching and am at my wit's end trying to make it work. HELP ME!!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我建议将三个下拉列表放在 UpdatePanel 中,并为每个 updatepanel 添加一个触发器。然后,当值发生变化时,重新填充下拉列表并让 updatepanel 推送更新。如果您想提交值,还可以保留会话状态。
我面前没有编译器,但如果需要,只需发表评论,我明天将发布代码。
工作示例
我使用的是 Visual Studio 和母版页附带的“传统模板”,所以请原谅内容占位符。但这应该证明我的意思:
I would recommend placing the three dropdownlists in an UpdatePanel and adding a trigger to each for the updatepanel. Then, when the value changes, re-populate the dropdown and let the updatepanel push the update. Also keeps session-state in case you want to submit the values.
I don't have a compiler in front of me, but if need be just post a comment and I'll post the code tomorrow.
Working Example
I'm using the "Traditional template" that comes with visual studio and the master page, so excuse the content place holders. But this should demonstrate what I mean: