Data Cogs Information Technology

posts - 135, comments - 152, trackbacks - 40

General

Search This Site

Powered by Google

Brisbane

Locations of visitors to this page

Archives

UPDATE

There are a couple of great implementations of this now on CodePlex:

http://cascddlistwithfilter.codeplex.com/

http://customfieldcontrols.codeplex.com/

END UPDATE

Dependent Drop Downs, Cascading Drop Downs, Filtered Drop Downs.  Whatever you want to call them, this is where you have a secondary drop down list filtered based on the choice from the primary drop down list.  For example:  select a country and you get another drop down list populated with the cities in that country.

This functionality doesn't seem to be there in WSS 3.0 and/or MOSS 2007. Perhaps I am missing something?  (It wouldn't be the first time)  But this seems to be fundamental functionality.   Here is some more detail on the scenario:

Country List: I just want a basic drop down list of countries:

City List: I want to filter the cities based on the selected country:

I want a cascading or filtered drop down like so (select Australia, and get a list of Austrlian cities):

Select Germany and get a list of German cities: 

 

Anyway, I couldn't find a way to do this out of the box, so...I decided to create my own custom field controls to overcome the problem.

I found a couple of useful articles on writing custom field controls.  This article describes how to create a custom drop down list user control along with a custom property page:

http://www.kcdholdings.com/blog/?p=56

I used a lot of code from this example, which has a couple of interesting points.First of all it shows how to create a custom Choice field that can be populated from any list on any site on the web farm (not just the current site). It also has an example of a way to get around the problem of saving custom properties of field controls. For some reason this is not as easy as it should be. I think this will be fixed in SP1. This article describes this problem:

http://www.sharepointblogs.com/ aaronrh/archive/2007/05.aspx

Instead of using a delimited string, I used a class to temporarily store the property values. Here is what my property pages look like for the Parent and Child drop down lists:

Anyway, after learning how to overcome the challenges of field controls in general, it was time to move on to the bigger problem of finding a way to create cascading drop downs. I figured there was hope in the “cross list query” or “caml query”:

http://msdn2.microsoft.com/en- us/library/ms467521.aspx

For example, if I want to filter a list of cities based on a country field in that list:

string caml = @"<WHERE><EQ><FIELDREF Name='{0}' /><VALUE Type='Text'>{1}</VALUE></EQ></WHERE>“;
SPQuery query = new SPQuery();
query.Query = string.Format(caml, "Country", "Australia");
SPListItemCollection results = list.GetItems(query);
this.ChildDropDownList.DataSource = results.GetDataTable();
this.ChildDropDownList.DataTextField = "City";
this.ChildDropDownList.DataValueField = "City";
this.ChildDropDownList.DataBind();

So I have a parent drop down list that has a SelectedIndexChanged event, that I use to call a method in the child control that binds to the results of the above query.

void ParentDropDownList_SelectedIndexChanged(object sender, EventArgs e)
{
     ChildDropDownListFieldControl child = (ChildDropDownListFieldControl)
               FindControlRecursive(this.Page, "ChildDropDownList").Parent.Parent;
     child.SetDataSource(ParentDropDownList.SelectedValue);
}

I played around with a lot of different ways to locate the Child drop down list on the page. This is the only one I got to work. (There has to be a better way?)

Anyway, I would appreciate any feedback on any better ways to do this. Here is the source code; I also have a solution file that you can use to install the controls. Just edit the install.bat and point it to the WSS or MOSS site you want to install it on.

posted on Sunday, August 26, 2007 8:08 PM

Feedback

# re: Sharepoint – Cascading Drop Down Lists

Hi,

Great. Thanks a lot. This is something which i have been looking for long time.

I installed the parent and child drop down list control by editing the install.bat file to point to my site. I added the columns to the list as described above. But when i try to open the newform or editform.aspx, it is giving me the below error.

"One or more field types are not installed properly. Go to the list settings page to delete these fields."

Can you let me know why the error is coming. I checked whether web.config is edit properly for safecontrol entry, the dll is copied in GAC and the ascx files are copied in the ../xml folder. They seem to be proper. So, let me know what could be the issue. Or should i uninstall and try the manual installation.

Regards,
Ramesh
8/29/2007 6:12 AM | Ramesh

# re: Sharepoint – Cascading Drop Down Lists

Hi Ramesh,

I just installed it on a clean MOSS build and tested it. I didn't have any problems.

Can you tell me the scenario you are using the controls with? For example what is the Parent list, Child List? What are you using for the Text and Value fields in the Parent and what are you using for the Text, Value and Join fields in the Child?

Mark
8/29/2007 10:27 AM | Mark Daunt

# re: Sharepoint – Cascading Drop Down Lists

Hi Mark,

I am also getting the same error.I used the same lists i.e city and country.

Sometimes I get unexpected error also.

Do let me know if you can find any solution for this .

Thanks in advance
8/29/2007 7:41 PM | Shonty

# re: Sharepoint – Cascading Drop Down Lists

Hi Mark,
It worked for me now. The installation of the control was proper. The issue was to do with the column name that was being used. I was getting error because of one of the following reasons.

1. My old column name instead of country had spaces, say Technical Stream. I am not sure if spaces are ok in the column names.
2. I had renamed the default Title column name to Technical Stream. But now i ignored the title column in all the lists and created new columns without space. (Note: I have found in my experience that some times sharepoint refers the default column as title even after u rename it)
3. Also, i made sure that joining column name (say country) is same in parent and child table.

The error was because of one of the above reasons. I think this are because of some small column name mismatch.

Apart from this, i found an issue. In the country list you have, add a new country, say "USA", but dont add any cities. So, this country will appear in the final list. But, when u select USA from drop down, then the city drop down is not refreshed. It should not have any options, but now the city of previous selection is retained. I guess, on selection changed, the child list is not cleared.

If you can resolve it, then let everyone know. Anyway, this is really a great control and something i have been looking for long time. Thanks a lot for the great post.

Shonty,
See if doing the changes mentioned in above three points solves your problem.
8/30/2007 3:44 AM | Ramesh

# re: Sharepoint – Cascading Drop Down Lists

Hi Ramesh,

Thanks for the feedback. I have uploaded a new version that fixes the problem where the parent list doesn't have any children (I just needed to add a line of code to clear the child list box).

As for renaming the Title field. I had thought that I had delat with this. There is an InternalName that remains "Title" even after you rename that field. In the ChildDropDownListFieldControl class, you will see the following code:

//if the title field has been renamed it doesn't seem to pick up the changed name
//so need to get the internal name for the field
string childListTextFieldInternal = list.Fields[childListTextField].InternalName;
string childListValueFieldInternal = list.Fields[childListValueField].InternalName;

this.ChildDropDownList.DataSource = results.GetDataTable();

this.ChildDropDownList.DataTextField = childListTextFieldInternal;
this.ChildDropDownList.DataValueField = childListValueFieldInternal;
this.ChildDropDownList.DataBind();

If you rename Title to City, I think you will see the field appear twice in the list. In this case I have been picking the first entry in the list and it seems to work.

Mark
8/30/2007 7:42 AM | Mark Daunt

# re: Sharepoint – Cascading Drop Down Lists

Hi Surya,

I thought about creating a single control that had a "child control"
property and a "ChildRefeshMethod" property. That way a each control can be a parent of the next control. Anyone can take me source code and modify it to give the kind of functionality you are talking about. If you have to wait for me, it might be a while :-)

Mark
10/8/2007 9:32 PM | Mark Daunt

# re: Sharepoint – Cascading Drop Down Lists

Amazing, really great work!
There is always room for improvement : an Ajax refresh of the child list would be even better, but I could install this custom field type without problem and it worked well at first try. Thanks a lot
10/10/2007 6:47 PM | Remi

# re: Sharepoint – Cascading Drop Down Lists

Hi,
I've test your tool with 2 lists and one Document Library, but when I make a new item or upload receive this screen:

<%@ Page language="C#" MasterPageFile="~masterurl/default.master" Inherits="Microsoft.SharePoint.WebPartPages.WebPartPage,Microsoft.SharePoint,Version=12.0.0.0,Culture=neutral,PublicKeyToken=71e9bce111e9429c" %> <%@ Register Tagprefix="SharePoint" Namespace="Microsoft.SharePoint.WebControls" Assembly="Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %> <%@ Register Tagprefix="Utilities" Namespace="Microsoft.SharePoint.Utilities" Assembly="Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %> <%@ Import Namespace="Microsoft.SharePoint" %> <%@ Register Tagprefix="WebPartPages" Namespace="Microsoft.SharePoint.WebPartPages" Assembly="Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<asp:Content ContentPlaceHolderId="PlaceHolderPageTitle" runat="server">
<SharePoint:ListFormPageTitle runat="server"/>
</asp:Content>
<asp:Content ContentPlaceHolderId="PlaceHolderPageTitleInTitleArea" runat="server">
<SharePoint:ListProperty Property="LinkTitle" runat="server" id="ID_LinkTitle"/>: <SharePoint:ListItemProperty id="ID_ItemProperty" MaxLength=40 runat="server"/>
</asp:Content>
<asp:Content ContentPlaceHolderId="PlaceHolderPageImage" runat="server">
<IMG SRC="/_layouts/images/blank.gif" width=1 height=1 alt="">
</asp:Content>
<asp:Content ContentPlaceHolderId="PlaceHolderLeftNavBar" runat="server"/>
<asp:Content ContentPlaceHolderId="PlaceHolderMain" runat="server">
<table cellpadding=0 cellspacing=0 id="onetIDListForm">
<tr>
<td>
<WebPartPages:WebPartZone runat="server" FrameType="None" ID="Main" Title="loc:Main" />
<IMG SRC="/_layouts/images/blank.gif" width=590 height=1 alt="">
</td>
</tr>
</table>
</asp:Content>
<asp:Content ContentPlaceHolderId="PlaceHolderTitleLeftBorder" runat="server">
<table cellpadding=0 height=100% width=100% cellspacing=0>
<tr><td class="ms-areaseparatorleft"><IMG SRC="/_layouts/images/blank.gif" width=1 height=1 alt=""></td></tr>
</table>
</asp:Content>
<asp:Content ContentPlaceHolderId="PlaceHolderTitleAreaClass" runat="server">
<script id="onetidPageTitleAreaFrameScript">
document.getElementById("onetidPageTitleAreaFrame").className="ms-areaseparator";
</script>
</asp:Content>
<asp:Content ContentPlaceHolderId="PlaceHolderBodyAreaClass" runat="server">
<style type="text/css">
.ms-bodyareaframe {
padding: 8px;
border: none;
}
</style>
</asp:Content>
<asp:Content ContentPlaceHolderId="PlaceHolderBodyLeftBorder" runat="server">
<div class='ms-areaseparatorleft'><IMG SRC="/_layouts/images/blank.gif" width=8 height=100% alt=""></div>
</asp:Content>
<asp:Content ContentPlaceHolderId="PlaceHolderTitleRightMargin" runat="server">
<div class='ms-areaseparatorright'><IMG SRC="/_layouts/images/blank.gif" width=8 height=100% alt=""></div>
</asp:Content>
<asp:Content ContentPlaceHolderId="PlaceHolderBodyRightMargin" runat="server">
<div class='ms-areaseparatorright'><IMG SRC="/_layouts/images/blank.gif" width=8 height=100% alt=""></div>
</asp:Content>
<asp:Content ContentPlaceHolderId="PlaceHolderTitleAreaSeparator" runat="server"/>

can you help me?

Thanks in advance,
Regards
Alessio
10/18/2007 1:22 AM | Alessio

# re: Sharepoint – Cascading Drop Down Lists

Hi, this is great, thanks.

I've installed this to my site and I added columns to the list.
It works fine but there is one problem.
When I try to edit aspx with added columns (i.e. NewForm.aspx, EditForm.aspx) in SharePoint Designer, page is displayed, but instead of the form there is

<MissingAssembly>Cannot import this Web Part.</MissingAssembly>

in the source code.

Please, where could be a problem?

Thanks
Robert
11/3/2007 12:10 AM | Robert

# re: Sharepoint – Cascading Drop Down Lists

Hi,
This is awesome ! Thanks for putting it together.
I have installed it and worked like a charm but I am not able to edit it in the Datasheet mode. Do you know what i would need to edit to make it work ? The fields are showing up as Read-only.

Thanks a lot !
-Jignesh
11/3/2007 2:10 AM | Jignesh

# re: Sharepoint – Cascading Drop Down Lists

Hi,

The datasheet view uses an activex control, called the ListNet control. It is not very well doumented but here is some info:

http://msdn2.microsoft.com/en-us/library/ms416795.aspx

It is not a web contrl at all, so I imagine that the controls it is hosting are in turn Windows controls. There might be some way to write an exquivalent winforms control to get hosted in ListNet but I can't find anything either.

So, I don't know of a way to add a custom control to this ListNet, but the article above discusses a way to replace the entire ListNet control with your own control. That would be a lot of work!

Hopefully someone can come up with a better answer.

Mark
11/3/2007 9:34 AM | Mark Daunt

# re: Sharepoint – Cascading Drop Down Lists

Thanks Mark for the link. I will look into it further. Here's some more info from my debugging.

When ActiveX control (Datasheet in our case here) tries to render the list
data, it makes a Web Service call (saw in Fiddler). At this point,
only XML/HTML (or CAML) is sent back. I think the User Control (ASCX) is only used when rendering in Standard View. The ActiveX control parses this CAML to render the items.

The ActiveX control might have a bug where it can't really parse the XML
(<Field> nodes as shown below) generated for the fields based on custom FieldType. It renders OOTB Choice fields just fine in the Datasheet view.

I viewed the page source and compared the CAML for the field that works
(OOTB Choice field) with my field based on the custom type and they are identicle except for their IDs & ColName (obvious reasons) attributes. My custom field has one additional attribute called Version which is auto generated as I am not
setting that in my code-behind. All the important attributes like ReadOnly,
FillInChoice etc are similar on both fields.

Here's the copy/paste of both fields as they appear on the page source: (I have removed ID and SourceId from
both for simplicity)

1. OOTB Choice field. Has 2 choices

Field Type=\u0026quot;Choice\u0026quot;
DisplayName=\u0026quot;Choices\u0026quot;
Required=\u0026quot;FALSE\u0026quot; Format=\u0026quot;Dropdown\u0026quot;
FillInChoice=\u0026quot;FALSE\u0026quot;
StaticName=\u0026quot;Choices\u0026quot; Name=\u0026quot;Choices\u0026quot;
ColName=\u0026quot;nvarchar6\u0026quot;
RowOrdinal=\u0026quot;0\u0026quot;\u0026gt;
\u0026lt;Default\u0026gt;Choice 1\u0026lt;\u002fDefault\u0026gt;\u0026lt;CHOICES\u0026gt;\u0026lt;CHOICE\u0026gt;Choice
1\u0026lt;\u002fCHOICE\u0026gt;\u0026lt;CHOICE\u0026gt;Choice 2\u0026lt;\u002fCHOICE\u0026gt;\u0026lt;\u002fCHOICES\u0026gt;\u0026lt;\u002fField\u0026gt;\u0026lt;


2. Field based on Custom FieldType

Field Type=\u0026quot;ListBasedChoice\u0026quot;
DisplayName=\u0026quot;test\u0026quot;
Required=\u0026quot;FALSE\u0026quot; StaticName=\u0026quot;test\u0026quot;
Name=\u0026quot;test\u0026quot; ColName=\u0026quot;nvarchar7\u0026quot;
RowOrdinal=\u0026quot;0\u0026quot; Format=\u0026quot;Dropdown\u0026quot;
FillInChoice=\u0026quot;FALSE\u0026quot; ReadOnly=\u0026quot;FALSE\u0026quot;
Version=\u0026quot;1\u0026quot;\u0026gt;\u0026lt;Default\u0026gt;Canada
\u0026lt;\u002fDefault\u0026gt;\u0026lt;CHOICES\u0026gt;\u0026lt;CHOICE\u0026gt;India
\u0026lt;\u002fCHOICE\u0026gt;\u0026lt;CHOICE\u0026gt;Canada
\u0026lt;\u002fCHOICE\u0026gt;\u0026lt;\u002fCHOICES\u0026gt;\u0026lt;\u002fField\u0026gt;\u0026lt;

I am not sure what else the ActiveX control is looking for.

Thanks
-Jignesh
11/4/2007 12:43 AM | Jignesh

# TemplateContainer always null

i'm going through your post on how to build these custom field types and i'm experiencing some strange behavior. i've got the editor control working fine, but when i try and enter values into the new form TemplateContainer.Controls.Find("cblMyCheckboxList") always returns null.

does anyone have any ideas why the TemplateContainer.Controls will always be empty? i've checked & re-checked and everything looks right.

thanks,
jason
11/9/2007 10:36 AM | jt

# re: Sharepoint – Cascading Drop Down Lists

Hello mark,

you have done a good job with this solution i have been looking for this for hours.
I have a problem with the installation, when i install your solution to my test site
http://litwaredemo/Unit I can not see the class on the screen, could you please describe what I did wrong. Please describe it step by step I'm a newbee :S

thanks a lot

Robin
11/15/2007 8:17 AM | Robin

# re: Sharepoint – Cascading Drop Down Lists

Found it :) it was easy don't mind my last post works creat !
11/15/2007 10:58 PM | Robin

# re: Sharepoint – Cascading Drop Down Lists

Hello Mark,

I would like to install this solution on a test environment with the dutch language as main language. Can I change the laguage type in your solution? If this possible how can I do this?

thanks

Robin
11/16/2007 1:57 AM | Robin

# re: Sharepoint – Cascading Drop Down Lists

Hi Mark,

you made a great tool. why don't you put it on CodePlex, there may be some some others to came up with some new ideas.

in ParentDropDownListFieldControl.cs, after this line:

this.ParentDropDownList.DataBind();

you may want to add

this.ParentDropDownList.Items.Insert(0, new ListItem("(None)", ""));


same idea for the Child, so you should be forced to set a value from the list of values.


Andrei
11/16/2007 9:39 AM | Andrei

# re: Sharepoint – Cascading Drop Down Lists

sorry,

so you shouldn't be forced to set a value ...
11/16/2007 9:41 AM | Andrei

# re: Sharepoint – Cascading Drop Down Lists

FLDTYPES_childdropdownlist.xml, line 24

instead

DisplayName="ChildJoinFiel:"

correct to

DisplayName="ChildJoinField"
11/16/2007 7:13 PM | Andrei

# re: Sharepoint – Cascading Drop Down Lists

Great tool. I am needing to filter on a multiselect listbox with a multiselect result for the child dropdown. Have you subbestions on how to do that?
11/17/2007 11:34 PM | Becky

# re: Sharepoint – Cascading Drop Down Lists

Hi Folks,
Inspired from your control, this is what i came up with , addressing a problem , i feel, far more generic then yours:

http://baigadil.blogspot.com/2007/11/sharepoint-2007-custom-lookup-drop-down.html
11/19/2007 3:18 AM | Adil Baig

# re: Sharepoint – Cascading Drop Down Lists

Hi Adil,

Nice one!

I was hoping people would expand on this. I'll have a good look at your solution.

Mark
11/20/2007 4:33 AM | Mark Daunt

# re: Sharepoint – Cascading Drop Down Lists

Hi everyone,

i am new to sharepoint,
but i got this cascading problem in many applications....
so i can't understand quickly..
so please help me by providing step by step process of this article
thank you all
12/26/2007 5:37 PM | Sreasty

# re: Sharepoint – Cascading Drop Down Lists

Hi Freinds,
now i understood ..how to implement and deploy
but i got one problem...ie my client using shared server from another country
so he is not allowed me to place the required files into server...
so , is there any alternative for this..
please help me
Thank you all
12/28/2007 11:33 AM | Sreasty

# re: Sharepoint – Cascading Drop Down Lists

Hi,

thanks for this great control. I found a bug in the code, on edit (after you saved the column), you can't change the source list.
For the fix, replace in ParentDropDownListFieldEditControl.cs at InitializeWithField this line:
if (!string.IsNullOrEmpty(parentSiteUrl))

to:
if (string.IsNullOrEmpty(txtSiteURL.Text) && !string.IsNullOrEmpty(parentSiteUrl))

Tyborg
1/4/2008 1:21 AM | Tyborg

# re: Sharepoint – Cascading Drop Down Lists

Thanks Tyborg,

I'll make that change to the code when I get a chance.

Mark
1/4/2008 8:31 AM | Mark Daunt

# re: Sharepoint – Cascading Drop Down Lists

hi please help me out in creating cascaded drop down boxes in custom list!!!!!!!!!!
1/7/2008 8:59 PM | Anu

# re: Sharepoint – Cascading Drop Down Lists

Hi Mark,

Thanks for the great tool.
There seems to be a problem when more than one parent-child lists are created in a form. For example, I would like to have ParentA-ChildA and ParentB-ChildB in a form. ParentA-ChildA is working properly initially but not when ParentB-ChildB is added to the form. If I move the ParentB-ChildB to a new form with only one parent-child list, then it is working properly.
Can anyone give me some advice on this scenario?

Thank you.
1/14/2008 12:09 PM | Michelle

# re: Sharepoint – Cascading Drop Down Lists

Do you, or anyone, know if it's possible to implement cascading drop down lists into 2.0?
1/18/2008 5:02 AM | Sicarii

# re: Sharepoint – Cascading Drop Down Lists

Hi -

This is an absolutely awesome control. It works exactly as we need it except for two minor issues that I would like help with:

1) I added
this.ParentDropDownList.Items.Insert(0, new ListItem("(None)"));
but want the field in the list to be required. How can I get the parent field to be required, but also have this functionality that allows the default value to be (None)?

2) the parent link field seems to be requried to be named without spaces. For example, we have a field called "System Name" I would to link the parent/child on, but it will only work as "SystemName". I am not sure how the internal name is set, i.e. if I can have a column named "System Name" with an internal name of "SystemName"?

TIA,
Dave

1/24/2008 6:23 AM | David Satz

# re: Sharepoint – Cascading Drop Down Lists

Just to add to my issue with item #2 above - could it be related to using renamed "title" columns?
1/24/2008 8:56 AM | David Satz

# re: Sharepoint – Cascading Drop Down Lists

FYI: I changed the code in
ChildDropDownListFieldEditControl.cs

protected void refreshLookups()

and replaced ddlColumnJoin.Items.Add(oneField.Title); with ddlColumnJoin.Items.Add(oneField.InternalName);

so that I can make sure the child dropdown picks up the internal name of the JOIN field even if it was renamed
1/30/2008 5:47 AM | David Satz

# re: Sharepoint – Cascading Drop Down Lists


Another question: any idea why the parent and child columns I added do not get exported to Excel from a view they are on?

I tried adding some more elements to FieldType

<Field Name="SQLType">nvarchar</Field>
<Field Name="BaseRenderingTypeName">Text</Field>
<Field Name="AllowBaseTypeRendering">TRUE</Field>

to no avail :-(
2/1/2008 3:25 AM | David Satz

# re: Sharepoint – Cascading Drop Down Lists

Is there an updated soltuion or source to download? The links at the top seem to be out of date with comments in the thread.

BTW, Nice Job
2/6/2008 1:41 PM | Chris O

# re: Sharepoint – Cascading Drop Down Lists

Good solution. Is there any way to choose a parent and will effect 2 child fields?
2/6/2008 5:21 PM | slertrit

# Il "mito" dei form condizionali su SharePoint

Una delle domande più ricorrenti che mi capita di ascoltare durante i corsi o le consulenze SharePoint
2/8/2008 4:26 AM | Igor Macori

# re: Sharepoint – Cascading Drop Down Lists

I'm thinking something like this as a starter idea, but I don't have the proper set up to test it out... I need to get VS plus VSeWSS on my webserver, but I need permission from IT :-(


ParentDropDownListFieldControl.cs:

protected CheckBoxList ParentDropDownList;

protected CheckBoxList ChildDropDownList;

Replace all instances of child.SetDataSource with:
child.SetDataSource(ParentDropDownList.Items);

ParentDropDownListFieldControl.ascx:
<asp:CheckBoxList ID="ParentDropDownList" runat="server" />

ChildDropDownListFieldControl.ascx
<asp:CheckBoxList ID="ChildDropDownList" runat="server" />

ChildDropDownListFieldControl.cs:
public void SetDataSource(ListItemCollection parentSelectedItems)
{
... Existing code unchanged ...

StringBuilder caml = new StringBuilder();
caml.Append("<Where>");
foreach (string parentSelectedValue in parentSelectedItems)
{
string condition = "<Eq><FieldRef Name='{0}'/><Value Type='Text'>{1}</Value></Eq>";
caml.AppendFormat(condition, childJoinField, parentSelectedValue);
if (parentSelectedItems.IndexOf(parentSelectedValue) <= parentSelectedItems.Count)
{
caml.Append("<Or>");
}
}
caml.Append("</Where>");

SPQuery query = new SPQuery();
query.Query = caml.ToString();

... Existing code unchanged ...
2/9/2008 8:53 AM | Tony

# re: Sharepoint – Cascading Drop Down Lists

That's in response to a post that I thought got posted but didn't. This is my idea to make a cascading checkboxlist that would function the same, but I don't have a way to effectively develop the code while I wait for my IT team to approve installation of VS and VSeWSS on the web server...
2/9/2008 8:55 AM | Tony

# re: Sharepoint – Cascading Drop Down Lists

Hi

This is a great post, I have implemented it and it works well. However, is there a way using javascript to get the currently selected option in child drop down field.

I would like to display some ojectives in a separate textarea based on the course that the user selects from the child drop down but cannot work out how.

Any ideas....

Thanks
2/19/2008 4:19 AM | Daniel

# re: Sharepoint – Cascading Drop Down Lists

Hi ,

i used this cascading drop down controil for sharepoint list in TEST Server , while moving to PRODUCTION SERVER these columns where not functioning "File not FOUND" error occurs !!!!!!!!1

help me solve this issue
3/29/2008 2:30 AM | Pradeep

# re: Sharepoint – Cascading Drop Down Lists

Hi,
Great piece of code, thanks.
I was thinking to improve it, because I'd like the column values to show up as links not strings (like in the lookup column). I'm pretty new to SharePoint development and I was thinking if you could give me some suggestions about how this could be done using your solution?
Thanks
4/14/2008 7:08 PM | Dex

# re: Sharepoint – Cascading Drop Down Lists

This lookup has many major issues....

The Parent and Child fields do not store the data correctly within the desired data source.

This is a major issue if you are doing filtering in data view web parts.
4/22/2008 2:17 AM | kova

# re: Sharepoint – Cascading Drop Down Lists

Very nice work, but I would have made ony one field to store the parent and child dropdownlist values, like MS do for their picture/link field (you know http://url, description)

That way you don't have to use the method "FindControlRecursive"!

Nevertherless great job!
5/7/2008 12:37 AM | superchinois

# re: Sharepoint – Cascading Drop Down Lists

This is a great tool... At the above comment, if they were combined then you couldn't sort or group based on the results seperatly. With the example, you could not Group by Countries, then by Cities.

However, is there a way to have the control not attach itself to the list ID, but rather so other convention?
5/9/2008 4:57 AM | Kevin

# SharePoint Kaffeetasse #65

SharePoint und Web 2.0 Knowledge and Talent in a People-Ready Business Server Side Integration of SharePoint
5/13/2008 5:53 PM | Mirrored Blogs

# 修复DataCogs二级联动FieldControl支持中文 -转载

???????????Field Type
5/15/2008 1:14 PM | Bob.Liu

# re: Sharepoint – Cascading Drop Down Lists

Pradeep, have you solved this problem, I have exact same problem. It is deployed correctly on the production server as the new columns work fine but the lists that came from development server does not work. You can not create new items, edit old ones event can't delete these columns. Any help would be appreciated.
Thank you
5/27/2008 9:01 PM | raomsaja

# re: Sharepoint – Cascading Drop Down Lists

Pradeep and Raomsaja, I have the same problem as well. I think the reason is because the control attaches to the list ID. Can someone verify this as well? Many thanks, Kevin
6/11/2008 6:40 AM | Kevin

# re: Sharepoint – Cascading Drop Down Lists

For those of you having issues with datasheet view, what you need to do is set the field's ReadOnly property to false in the Update () method. This way you can edit the values while in datasheet mode.
6/25/2008 2:54 AM | _Hyde_

# re: Sharepoint – Cascading Drop Down Lists

With a slicker storytelling pace that puts down more emphasis on it’s plotting and
action (and it’s grotesque hentai angle which works well here), but don’t think it http://mikrosfera.info
http://zagadko.info/index.php?sm=2
http://farmostok.com/index.php?sm=1
lags on the sex because while it comes in short bites these bites are fairly mango
dispersed about the title and it all flows together well. Add to that it’s unique
visual style and the fact we’re looking at a work from the “creator” of the whole
“erotic grotesque” style and anime you can see why this is a 5 out of 5. Breakdown will http://zama-nuha.info/index.php?sm=1
http://razdolie.info/index.php?sm=1
prove that out.
6/25/2008 6:16 PM | alevo

# re: Sharepoint – Cascading Drop Down Lists

Hi all,

Great code!!! We get an error emssage when we try to access to a list element properties. Any ideas??

Carles

Server Error in '/' Application.
--------------------------------------------------------------------------------

Al menos uno de los tipos de campo no se ha instalado correctamente. Vaya a la página de configuración de la lista para eliminar estos campos.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Runtime.InteropServices.COMException: Al menos uno de los tipos de campo no se ha instalado correctamente. Vaya a la página de configuración de la lista para eliminar estos campos.

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:


[COMException (0x81020014): Al menos uno de los tipos de campo no se ha instalado correctamente. Vaya a la página de configuración de la lista para eliminar estos campos.]
Microsoft.SharePoint.Library.SPRequestInternalClass.GetListItemDataWithCallback(String bstrUrl, String bstrListName, String bstrViewName, String bstrViewXml, SAFEARRAYFLAGS fSafeArrayFlags, ISP2DSafeArrayWriter pSACallback, ISPDataCallback pPagingCallback, ISPDataCallback pSchemaCallback) +0
Microsoft.SharePoint.Library.SPRequest.GetListItemDataWithCallback(String bstrUrl, String bstrListName, String bstrViewName, String bstrViewXml, SAFEARRAYFLAGS fSafeArrayFlags, ISP2DSafeArrayWriter pSACallback, ISPDataCallback pPagingCallback, ISPDataCallback pSchemaCallback) +265

[SPException: Al menos uno de los tipos de campo no se ha instalado correctamente. Vaya a la página de configuración de la lista para eliminar estos campos.]
Microsoft.SharePoint.Library.SPRequest.GetListItemDataWithCallback(String bstrUrl, String bstrListName, String bstrViewName, String bstrViewXml, SAFEARRAYFLAGS fSafeArrayFlags, ISP2DSafeArrayWriter pSACallback, ISPDataCallback pPagingCallback, ISPDataCallback pSchemaCallback) +395
Microsoft.SharePoint.SPListItemCollection.EnsureListItemsData() +2191
Microsoft.SharePoint.SPListItemCollection.GetDataTable() +262
DataCogs.WebControls.ChildDropDownListFieldControl.SetDataSource(String parentSelectedValue) +768
System.Web.UI.Control.EnsureChildControls() +149
Microsoft.SharePoint.WebControls.BaseFieldControl.OnLoad(EventArgs e) +216
System.Web.UI.Control.LoadRecursive() +66
System.Web.UI.Control.LoadRecursive() +191
System.Web.UI.Control.LoadRecursive() +191
System.Web.UI.Control.LoadRecursive() +191
System.Web.UI.Control.LoadRecursive() +191
System.Web.UI.Control.LoadRecursive() +191
System.Web.UI.Control.LoadRecursive() +191
System.Web.UI.Control.LoadRecursive() +191
System.Web.UI.Control.LoadRecursive() +191
System.Web.UI.Control.LoadRecursive() +191
System.Web.UI.Control.LoadRecursive() +191
System.Web.UI.Control.LoadRecursive() +191
System.Web.UI.Control.LoadRecursive() +191
System.Web.UI.Control.LoadRecursive() +191
System.Web.UI.Control.LoadRecursive() +191
System.Web.UI.Control.LoadRecursive() +191
System.Web.UI.Control.LoadRecursive() +191
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2604




--------------------------------------------------------------------------------
Version Information: Microsoft .NET Framework Version:2.0.50727.1433; ASP.NET Version:2.0.50727.1433
7/3/2008 1:26 AM | Carles

# re: Sharepoint – Cascading Drop Down Lists

Mark,

Interesting code ... am going to try and get it going ...

I am a sharepoint scoob so i just have one question .. will the auto install take care of the DLL registration as well or do i need to go through that process still?
7/4/2008 3:26 PM | Hayden

# re: Sharepoint – Cascading Drop Down Lists

Very interesting code I will try it on my own.
7/29/2008 10:56 PM | Ringtones

# re: Sharepoint – Cascading Drop Down Lists

When using the cascading dropdown list column in a custom list form and trying to open this same page in Sharepoint Designer, the entire custom list form will not render the sharepoint fields and I get a continuous error about not having permissions.

I never experienced this issue until I used the cascading dropdown column type.

Any ideas?
8/1/2008 2:27 PM | JD

# re: Sharepoint – Cascading Drop Down Lists

Has anyone tried to export a site with the custom field and import into another site?
I am getting the following...

[8/18/2008 4:13:10 PM]: FatalError: Object reference not set to an instance of an object.
at DataCogs.SharePoint.FieldControls.ParentDropDownListField.get_ContextId()
at DataCogs.SharePoint.FieldControls.ParentDropDownListField.get_ParentSiteUrl()
at DataCogs.SharePoint.FieldControls.ParentDropDownListField.Update()
at DataCogs.SharePoint.FieldControls.ParentDropDownListField.OnAdded(SPAddFieldOptions op)
at Microsoft.SharePoint.SPFieldCollection.AddFieldAsXmlInternal(String schemaXml, Boolean addToDefaultView, SPAddFieldOptions op)
at Microsoft.SharePoint.Deployment.ListSerializer.CreateOrUpdateField(SPList list, String fieldName, XmlNode fieldNode)
at Microsoft.SharePoint.Deployment.ListSerializer.UpdateListFields(SPList list, Dictionary`2 listMetaData)
at Microsoft.SharePoint.Deployment.ListSerializer.SetObjectData(Object obj, SerializationInfo info, StreamingContext context, ISurrogateSelector selector)
at Microsoft.SharePoint.Deployment.XmlFormatter.ParseObject(Type objectType, Boolean isChildObject)
at Microsoft.SharePoint.Deployment.XmlFormatter.DeserializeObject(Type objectType, Boolean isChildObject, DeploymentObject envelope)
at Microsoft.SharePoint.Deployment.XmlFormatter.Deserialize(Stream serializationStream)
at Microsoft.SharePoint.Deployment.ObjectSerializer.Deserialize(Stream serializationStream)
at Microsoft.SharePoint.Deployment.ImportObjectManager.ProcessObject(XmlReader xmlReader)
at Microsoft.SharePoint.Deployment.SPImport.DeserializeObjects()
at Microsoft.SharePoint.Deployment.SPImport.Run()
8/19/2008 7:36 AM | chris o

# re: Sharepoint – Cascading Drop Down Lists

Hi Mark,

I follow the instructions and advises on previous posts in order to eliminate possible conflicts but I'm still getting this error when I try to save the form and create the item.

Type mismatch. (Exception from HRESULT: 0x80020005 (DISP_E_TYPEMISMATCH))

Any thoughts?

Anyone?

Thanks,
Roger
8/27/2008 8:49 PM | Roger

# re: Sharepoint – Cascading Drop Down Lists

Hi,

Thanks for sharing your work! Does the cascading also work in the Office 2007 Document Information Panel?

Thanks,
Jonas
9/10/2008 5:37 PM | Jonas

# re: Sharepoint – Cascading Drop Down Lists

Works like a charm! Thank you soooo much for sharing this, you saved my life!
9/12/2008 2:16 AM | Matt

# re: Sharepoint – Cascading Drop Down Lists

Also, don't know if someone already linked to this, but here are some good additional instructions on how to use it: http://splittingshares.wordpress.com/2008/04/30/cascading-drop-down-lists-in-a-parent-child-relationship/
9/12/2008 2:18 AM | Matt

# Problem Handling Edit

I have implemented the Cascading using Listbox with Multiselect upto 5 levels.

However i am facing the problem while editing the items.
As soon as i select a value in the topmost listbox, all the other previous Selections in remaining listboxes are cleared. I have problem retaining the previously selected values.

I would really appreciate help from ur end.

Thanks in Advance
9/16/2008 6:50 PM | SVAM

# Sharepoint Cascading Dropdown List Project on Codeplex

9/25/2008 11:22 AM | Data Cogs Information Technology

# re: Sharepoint – Cascading Drop Down Lists

Has anyone figure out the solution to the "File not FOUND" problem?
10/2/2008 3:03 AM | henry

# re: Sharepoint – Cascading Drop Down Lists

This tool is great!!!

I have installed it correctly and am able to manually create the column fields in a list with the proper property values set.

What I would like to do is create the List field programmatically and set the properties but it isn’t working.

If I do the following code I get the error below.
SPField questionField = new SPField(fields, "ParentDropDownListField", "Question");
questionField.SetCustomProperty("ParentSiteUrl", "http://mossdev/site1");
questionField.SetCustomProperty("ParentListName", "SITE1_QUESTION_LIST");
questionField.SetCustomProperty("ParentListTextField", "ID");
questionField.SetCustomProperty("ParentListValueField", "Question");
questionField.Update();
fields.Add(questionField);

ERROR:
Exception = System.NullReferenceException: Object reference not set to an instance of an object.
at Microsoft.SharePoint.SPField.get_CustomProperties()
at Microsoft.SharePoint.SPField.SetCustomProperty(String propertyName, Object propertyValue)
at MOCEvenHandlerInstaller.MOC_Installer.CreateWorkItemsList(SPWeb mocSite) in C:\Documents and Settings\Administrato
r\My Documents\Visual Studio 2005\Projects\MOCEventHandler\MOCEvenHandlerInstaller\MOC_Installer.cs:line 882


If I just do the following code I get the error below.
SPField questionField = new SPField(fields, "ParentDropDownListField", "Question");
questionField.Update();
fields.Add(questionField);

ERROR:
Exception = Microsoft.SharePoint.SPException: One or more field types are not installed properly. Go to the list setting
s page to delete these fields. ---> System.Runtime.InteropServices.COMException (0x81020014): One or more field types ar
e not installed properly. Go to the list settings page to delete these fields.
at Microsoft.SharePoint.Library.SPRequestInternalClass.AddField(String bstrUrl, String bstrListName, String bstrSchem
aXml, Int32 grfAdd)
.
.
.

I assume they are both caused by the same thing. It appears as though Sharepoint doesn't know about the new field type. I created a field type manually and
then printed the type, custom properties and it looks like I am setting everything correctly.

Any help with this would be appreciated.

10/3/2008 5:32 AM | Joe

# re: Sharepoint – Cascading Drop Down Lists

The controls work great for standard text look ups... thank you. There are many people looking for this functionality, but not many easy to find solutions.

I can't get the control to work if the parent field is a "lookup field".

I have a customer and contact list. The customer name is the parent lookup. The contact is the child... when I link the existing customer lookup field on the child to the parent I get the "One or more field types are not installed properly. Go to the list settings page to delete these fields. " error message on new or edits.

If I just type the customer in a non-lookup field it works great.

Any suggestions are appreciated very much.

Tobin
10/8/2008 1:49 AM | Tobin

# Use more than 2 drop down list??

Great tool!
Is it possible to use more than 2 cascading drop down list?
For example, 1 parent, and to child? where the second child is bind to the first child.

10/10/2008 9:12 PM | Student

# re: Sharepoint – Cascading Drop Down Lists

I have searched the net and I should say I have not come across an article like this which is so easy to understand and learn the concepts.
cheers
10/16/2008 7:50 PM | goodt

# re: Sharepoint – Cascading Drop Down Lists

I have the need to use two sets of parent/child fields on a form. The first relationship filters client id based on a name drop down. The second filters a sub category based on a category. Has anyone determined a way to use two sets of these controls in one list?

Thanks.
10/31/2008 2:22 AM | Samantha

# re: Sharepoint – Cascading Drop Down Lists

Has anyone tried the solution posted above for getting the 'Edit in Dataview" function to work with these parent-child fields??

..."For those of you having issues with datasheet view, what you need to do is set the field's ReadOnly property to false in the Update () method. This way you can edit the values while in datasheet mode."

If anyone has got this working with these fields, I would love to hear how you did this!! :)
11/6/2008 5:16 PM | Kuriko

# re: Sharepoint – Cascading Drop Down Lists

Does not work in Word 2007. Obviously this seem to be issue with every custom lookup that people have tried to write. But had anyone been able to create a custom lookup derived from "lookup" and get it working under Word as well.
11/13/2008 8:27 AM | Irfan Malik

# re: Sharepoint – Cascading Drop Down Lists

Have you tried to add
<Field Name=“AllowBaseTypeRendering“>TRUE</Field>
in the .xml file??
11/19/2008 11:21 PM | share

# re: Sharepoint – Cascading Drop Down Lists

I have installed and it works.

My question is;
If I do not choose any country, I want it to show all cities. Is this possible?
So If I leave "Country" as blank in Country dropdwon list, it would show the list of all cities in "City" dropdown

Berlin
Bonn
Paris
Melbourne

Thank you,
12/11/2008 8:09 PM | OCY

# re: Sharepoint – Cascading Drop Down Lists

Datasheet used CAML to render the contents, but for most custom field types, they are too complicated to use CAML, so... forget about Edit in Datasheet.
Or if someone has a solution, please do post it here.
tag [Datasheet][Custom Field Type][SharePoint]
1/15/2009 6:25 PM | Zhang Mingquan Mike

# cuadro desplegable (combo box) con datos de una tabla SQL en una l | hilpers

cuadro desplegable (combo box) con datos de una tabla SQL en una l | hilpers
1/18/2009 9:34 PM | Pingback/TrackBack

# Reloading a custom list item | keyongtech

Reloading a custom list item | keyongtech
1/19/2009 2:45 AM | Pingback/TrackBack

# How do I create a filtered lookup column? | keyongtech

How do I create a filtered lookup column? | keyongtech
1/22/2009 11:10 AM | Pingback/TrackBack

# How can I view this custom field into Word2007 as a LookUp field ?

How can I view this custom field into Word2007 as a LookUp field ?

I've tried to change the xml from

<Field Name="ParentType">Text</Field>

to

<Field Name="ParentType">Lookup</Field>

but it doesn't work

thanks to all
2/3/2009 2:42 AM | Lambuz

# re: Sharepoint – Cascading Drop Down Lists

"Does not work in Word 2007. Obviously this seem to be issue with every custom lookup that people have tried to write. But had anyone been able to create a custom lookup derived from "lookup" and get it working under Word as well."

Did you get it to work Irfan Malik?
3/25/2009 3:30 AM | Lan N

# Alphabetize Lookup Options

Anyone know of a way to have the results alphabetized? It seems that they display in the order of ID rather then any other sort order. Anyone have a solution so as users add / edit drop down fields it keeps them in alphabetical order?

Thanks,
Jason
4/29/2009 4:54 AM | Jason

# re: Sharepoint – Cascading Drop Down Lists

Why if I fill the parent control from a column with calculated values (as [Name]&"-"&[Surname]) I get all the values:

string;#Nome1-Cognome1
string;#Nome2-Cognome2
string;#Nome3-Cognome3

instead of

Nome1-Cognome1
Nome2-Cognome2
Nome3-Cognome3

can I remove the string;#?!?
7/1/2009 6:22 PM | sciare.user

# re: Sharepoint – Cascading Drop Down Lists

Hi,

I installed a similar solution for this I found here:
http://blog.12thwave.com/?p=7

and it works perfectly.

Now my question is, how easy would be to alter your code so the last dropdown is not a dropdown but a textfield. Basically what I want to achieve is that once all the previous dropdowns have been selected, we get a textbox at the end with a summary text. This summary text would be definied in the list of the last dropdown.
8/11/2009 11:24 PM | c

Post Comment

Title  
Name  
Url
Comment   
Protected by Clearscreen.SharpHIPEnter the code you see: