相关的DropDownLists和PostBacks [英] Related DropDownLists and PostBacks

查看:72
本文介绍了相关的DropDownLists和PostBacks的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



假设您有以下数据库表:



数据库表:

tblCompany(Id,Name)

tblDepartment(Id,CompanyId,Name)

tblEmployee( Id,DepartmentId,FirstName,LastName)




现在,假设您有一个ASP表单来添加员工:



ASP表格

公司: [DropDownListCompany]

部门: [DropDownListDepartment] (启用=假)

员工姓名:[TextBoxEmployeeName](启用=假)



现在,用户必须首先选择公司,然后允许获取该特定公司内的部门并启用部门下拉列表。



用户选择部门后,文本框启用。



问题是这样的:用户必须选择一家公司,然后才能获取相应的部门ents。



我找到了一个解决方案 - 但它会导致丢失的PostBack事件。还有另外一种方法吗?



提前致谢

Jeann

解决方案

您可以使用更新面板在您的表单中,以避免完全回发您的表单(即使它回发最终用户将无法知道)或您可以使用Ajax脚本根据您的条件填充下拉列表。


< blockquote>嗨Madhu,



更新面板效果很好!而且我发现ViewState可以为变量和非控制内容创建奇迹,而不是更新面板上的内容!



我来自Silverlight, Windows窗体和WPF背景 - 相当新的ASP.Net和JavaScript等,但我发现它更容易随着我的进展。



问候,



Jeann


Hi Guys,

Lets say you have the following DB tables:

DB Tables:
tblCompany (Id, Name)
tblDepartment (Id, CompanyId, Name)
tblEmployee (Id, DepartmentId, FirstName, LastName)


Now, lets say you have a ASP form to add an employee:

ASP Form
Company: [DropDownListCompany]
Department: [DropDownListDepartment] (Enabled = False)
Employee Name: [TextBoxEmployeeName] (Enabled = False)

Now, the user must first select the Company, which then allows the fetching of the departments within that specific company and enables the Department dropdownlist.

After the user selects the department, then the textboxes enables.

So the problem is this: The user must select a company, and only then can the application fetch the appropriate departments.

I have found a solution - but it generates a lost of PostBack events. Is there another way?

Thanks in advance
Jeann

解决方案

You can use update panel in your form for avoiding full post back of your form(even though it postbacks end user won't be able to know) or you can use Ajax Script for populating drop downs based on your conditions.


Hi Madhu,

Update panel works great! And I've found the ViewState to work wonders as well for variables and non-control stuff that doesn't go on update panels!

I'm from Silverlight, Windows Forms and WPF background - and fairly new to ASP.Net and JavaScript, etc. but I'm finding it more easy as I go along.

Regards,

Jeann


这篇关于相关的DropDownLists和PostBacks的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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