简体   繁体   English

ASP.NET页面中依赖Java的DropDownLists

[英]Javascript Dependent DropDownLists in an ASP.NET page

I have a .NET registration form that populates some DDLs from the database and has others hard coded. 我有一个.NET注册表单,该表单填充了数据库中的某些DDL,并进行了其他硬编码。 The requirement calls for a series of three dependent DDLs: One for Organization and two for Job Title. 该要求需要一系列三个从属DDL:一个用于组织,两个用于职位。 Depending on which Organization is chosen, some Job Titles may have sub-choices like so: 根据所选择的组织,某些职位可能具有如下子选择:

DDL1    DDL2    DDL3
A       a       n/a
B       a       c
C       b       n/a

In some cases the same choice in DDL2 will require a choice from DDL3; 在某些情况下,DDL2中的相同选择将需要从DDL3中进行选择。 in some cases the choice from DDL2 will be sufficient. 在某些情况下,从DDL2中进行选择就足够了。 For example, If the choice from DDL1 was Hospital, DDL 2 would contain Physician, and DDL3 would contain Pediatrician and I would need to submit the values from DDL1 and DDL3. 例如,如果从DDL1中选择医院,则DDL 2将包含医师,DDL3将包含儿科医生,而我需要提交DDL1和DDL3中的值。 But, if DDL1 was Lab, the Physician choice from DDL2 would suffice and I would submit DDL1 and DDL2. 但是,如果DDL1是Lab,那么DDL2的医师选择就足够了,我将提交DDL1和DDL2。 I have a javascript file that handles all the choices perfectly but I'm having trouble getting the values sent to the DB because of postback issues. 我有一个javascript文件,可以很好地处理所有选择,但是由于回发问题,我无法将值发送到数据库。

I've tried several fixes including UpdatePanels and Triggers but I can't quite get it right. 我已经尝试了多个修复程序,包括UpdatePanels和Triggers,但我不太正确。

I found this and it looks like it fits my needs nearly perfectly. 我发现了这一点,看起来几乎可以完全满足我的需求。 Still tweaking to get it to work. 仍在调整以使其正常工作。

http://code.msdn.microsoft.com/CSASPNETCascadingDropDownLi-0a3f1ecf#content http://code.msdn.microsoft.com/CSASPNETCascadingDropDownLi-0a3f1ecf#content

I've got a simple XML example created: 我创建了一个简单的XML示例:

<Countries>

 <Country name="China">
   <Region name="East China">
    <City name="ShangHai" guid="12345"></City>
    <City name="SuZhou" guid="23456"></City>
    <City name="NianJing" guid="34567"></City>
    <City name="QingDao" guid="45678"></City>
    <City name="ZheJiang" guid="56789"></City>
   </Region>
 </Country>

</Countries>

Here's the C# to get the City name to populate the DDL: 这是获取城市名称以填充DDL的C#:

        /// <summary>
    ///  Get city based on region
    /// </summary>
    /// <param name="strRegion">The region name</param>
    /// <returns>The list contains city</returns>
    public static List<string> GetCityByRegion(string strRegion)
    {
        XmlDocument document = new XmlDocument();
        document.Load(strXmlPath);
        XmlNodeList nodeList = document.SelectNodes(
            "Countries/Country/Region[@name='" + strRegion + "']/City");
        List<string> list = new List<string>();
        foreach (XmlNode node in nodeList)
        {
            list.Add(node.Attributes["name"].Value);
        }
        return list;
    }

How do I get the guid value into the .NET form since that's the value I need to submit to the DB? 如何将guid值转换成.NET表单,因为那是我需要提交给数据库的值?

You can use a loop. 您可以使用循环。

if(DDL1.SelectedValue.Equals("") || (DDL2.SelectedValue.Equals(""))
{
//your message
}
else if (DDL1.SelectedValue.Equals("") || (DDL3.SelectedValue.Equals(""))
{
//your message
}

... and so on. ... 等等。

Just add some codes in it that will satisfy your need. 只需在其中添加一些代码即可满足您的需求。 You can also use "&&" if you need to have a condition where both are to be satisfied. 如果您需要满足两个条件,也可以使用“ &&”。

Hope this can help you. 希望这可以帮到你。

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

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