Skip to content
September 24, 2009 / red1s

Quick Tip – Data-Enabled Dependency Dropdown


 

Working on MOSS 2007 I had to create a data enabled cascade dropdown with (C# .Net 3.5 )

 

For this example My Department is based on my division

 

// Populate division dropdown list
            lstDivision.Items.Clear();
            ListItem itmDivision = new ListItem();
            itmDivision.Text = "Select Division";
            itmDivision.Value = "**";
            lstDivision.Items.Add(itmDivision);


            // lblDepartment_ID.Text = lstDivision_ID.SelectedItem.ToString();

            NamedLobSystemInstanceDictionary sysInstances = ApplicationRegistry.GetLobSystemInstances();
            LobSystemInstance instance = sysInstances[lobSystemInstance];
            Entity entity = instance.GetEntities()["sp.Division"];
            FilterCollection filterCollection = entity.GetFinderFilters();
            IEntityInstanceEnumerator entityList = entity.FindFiltered(filterCollection, instance);

            while (entityList.MoveNext())
            {
                itmDivision = new ListItem();
                itmDivision.Text = entityList.Current["Division_Name"].ToString();
                itmDivision.Value = entityList.Current["Division_ID"].ToString();
                lstDivision.Items.Add(itmDivision);
            }

            lstDivision.SelectedIndexChanged += new EventHandler(lstDepartment_SelectedIndexChanged);
            lstDivision.AutoPostBack = true;

.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, “Courier New”, courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }

 

Now that I have populated my division dropdown list i need to handle the change of selection, this will be done by the following event handler:

 

 void lstDepartment_SelectedIndexChanged(object sender, EventArgs e)
        {

            lstDepartment.Items.Clear();

            ListItem deptItem = new ListItem();
            deptItem.Text = "Select Department";
            deptItem.Value = "**";
            lstDepartment.Items.Add(deptItem);

            if (lstDivision.SelectedValue != "**")    // Division has been selected
            {

                NamedLobSystemInstanceDictionary sysInstances = ApplicationRegistry.GetLobSystemInstances();
                LobSystemInstance instance = sysInstances[lobSystemInstance];
                Entity entity = instance.GetEntities()["sp.Department"];
                FilterCollection filterCollection = entity.GetFinderFilters();
                IEntityInstanceEnumerator entityList = entity.FindFiltered(filterCollection, instance);


                while (entityList.MoveNext())
                {
                    if (entityList.Current["Division_ID"].ToString() == lstDivision.SelectedValue)
                    {
                        deptItem = new ListItem();
                        deptItem.Text = entityList.Current["Department_Name"].ToString();
                        deptItem.Value = entityList.Current["Department_ID"].ToString();
                        lstDepartment.Items.Add(deptItem);
                    }
                }
            }

        }

.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, “Courier New”, courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }

 

And there you have it Hot smile

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: