locked
Cascading Drop Down List C# RRS feed

  • Question

  • Hi

    We have attempted to create multiple cascadimng drop down lists to auto populate fields without success. We followed the following post; http://www.bizsupportonline.net/browserforms/filter-cascade-drop-down-infopath-sharepoint-browser-form-owssvr-dll.htm and seem to have completed all steps correctly except we cannot query the SharePoint list correctly.

    I imagine the error in the code is in the following line: + "&XMLDATA=TRUE&FilterField1=Property Name&FilterValue1="

    Here is the complete code which we have attempted to run:
    Our SharePoint list appears as follows:

    XPathNavigator root = MainDataSource.CreateNavigator();
    
    // Get the value for the property name
    string Property Name = root.SelectSingleNode("/my:assetTracking/my:group3/my:PropertyName", 
    NamespaceManager).Value;
    
    // Clear the last selected value in the Property Number drop-down list box
    root.SelectSingleNode("/my:assetTracking/my:group3/my:PropertyNumber", NamespaceManager).SetValue("");
    
    // Retrieve the data connection bound to the Property Number drop-down list box
    FileQueryConnection con = (FileQueryConnection)DataConnections["Property Numbers"];
    
    // Change the location of the data connection to point the XML file
    // returned by the owssvr.dll with a filter on property number
    con.FileLocation = @"http://moss:7777/_vti_bin/owssvr.dll" 
    + "?Cmd=Display&List={EA774048-424C-47D4-86A5-CE31DCF6835A}"
    + "&XMLDATA=TRUE&FilterField1=Property Name&FilterValue1=" 
    + PropertyName;
    
    
    // Query the data connection to fill the Property Number drop-down list box with items
    con.Execute();
    
    
    

     

    ID Property Name               Property Number
    1  Rosehaven Senior Centre 9
    2  Rosehaven Senior Centre 9
    3  Rosehaven Senior Centre 9
    4  Rosehaven Senior Centre 9
    5  Rosehaven Senior Centre 9
    6  Rosehaven Senior Centre 9
    7  Rosehaven Senior Centre 9
    8  Rosehaven Senior Centre 9
    9  Rosehaven Senior Centre 9
    10 Musgrave Park Senior Centre 20
    11 Drommedaris Pilot Project 5
    12 Drommedaris Pilot Project 5
    13 Drommedaris Pilot Project 5
    We are attempting to run the code on the server. Not sure if the would affect anything however the drop down is populated however it is not filtered correctly so would imagine that we are quite close. We just need to auto populate the property number when the property name is selected.
     
    Appreciate your suggestions.

    Thanks
    Tony

     

    Tuesday, June 14, 2011 6:11 AM

All replies

  • In your URL, you  have a space in the FilterField name: Property Name. Try using the internal name of the column.  Also to test the URL, you paste it in the browser to see if you get any XML Data back.

     

     


    Meredith Blog: http://sharepointchic.blogspot.com
    Tuesday, June 14, 2011 12:43 PM
  • Hi

    Thanks very much for your reply. I am going to attempt to insert the code. I would like to confirm if there is any reason why this should not work on the server.

    I read some documentation which described how programming may differ from server to client. If there is not affect running this on the server, then I should get it to work.

    Thanks
    Anthony

    Wednesday, June 15, 2011 6:06 AM
  • You can also make sure that you get the correct values for "&XMLDATA=TRUE&FilterField1=Property Name&FilterValue1="
    + PropertyName;

    by going to the list/library itself in your browser. Use the column heading to apply a filter and then look at the url, it will have the filter field/value properties set and you can make sure that they are correct in your form.

    Wednesday, June 15, 2011 10:39 AM
  • Hi

    Thanks for your reply. By your response, I assume that there should be no difference between server and client. I am going to start testing this shortly.

    Thanks
    Tony

    Wednesday, June 15, 2011 11:49 AM
  • Hi I have managed to get this functionality working! I failed to mention that I actaully need to cascade more than one drop down list which would cascade depending on the selection in the first drop down. My fields are Property Name, Property Number and Street Address. When a Property Name is selected, the Property Number is now the correct selection and just need to cascade the Street Address. I attempted the following code which was unsuccessful: XPathNavigator root = MainDataSource.CreateNavigator(); // Get the value for the property name string PropertyName = root.SelectSingleNode("/my:assetTracking/my:group3/my:PropertyName", NamespaceManager).Value; // Clear the last selected value in the Property Number drop-down list box root.SelectSingleNode("/my:assetTracking/my:group3/my:PropertyNumber", NamespaceManager).SetValue(""); // Clear the last selected value in the Street Address drop-down list box root.SelectSingleNode("/my:assetTracking/my:group2/my:Street Address", NamespaceManager).SetValue(""); // Retrieve the data connection bound to the Property Number drop-down list box FileQueryConnection con = (FileQueryConnection)DataConnections["PropertyNumbers"]; // Change the location of the data connection to point the XML file // returned by the owssvr.dll with a filter on property number con.FileLocation = @"http://moss:7777/_vti_bin/owssvr.dll" + "?Cmd=Display&List={EA774048-424C-47D4-86A5-CE31DCF6835A}" + "&XMLDATA=TRUE&FilterField1=Title&FilterValue1=" + PropertyName; // Retrieve the data connection bound to the Street Address drop-down list box FileQueryConnection con = (FileQueryConnection)DataConnections["Street Addresses"]; // Change the location of the data connection to point the XML file // returned by the owssvr.dll with a filter on property number con.FileLocation = @"http://moss:7777/_vti_bin/owssvr.dll" + "?Cmd=Display&List={02232DBE-F2BB-42B3-BBCE-B33A91EDF28B}" + "&XMLDATA=TRUE&FilterField1=Title&FilterValue1=" + PropertyName; // Query the data connection to fill the Property Number drop-down list box with items con.Execute(); I receive one error message which states: A local variable named ‘con’ is already defined in this scope Any assitance would be greatly appreciated. Thanks Tony
    Thursday, June 16, 2011 1:39 PM
  • You are defining the variable con twice.  Either use a different name the second time:

     

    FileQueryConnection con2 = (FileQueryConnection)DataConnections["Street Addresses"];

     

    or just remove the datatype from the second line - and reuse the con variable:

     

    con = (FileQueryConnection)DataConnections["Street Addresses"];

     


    Meredith Blog: http://sharepointchic.blogspot.com
    Thursday, June 16, 2011 4:38 PM
  • Hi

    Thanks very much for getting back to me.

    I tried the following codes without success:

    XPathNavigator root = MainDataSource.CreateNavigator();

                // Get the value for the property name
                string PropertyName = root.SelectSingleNode("/my:assetTracking/my:group3/my:PropertyName",
                NamespaceManager).Value;

                // Clear the last selected value in the Property Number drop-down list box
                root.SelectSingleNode("/my:assetTracking/my:group3/my:PropertyNumber",

                NamespaceManager).SetValue("");

                // Retrieve the data connection bound to the Property Number drop-down list box
                FileQueryConnection con = (FileQueryConnection)DataConnections["PropertyNumbers"];
                    

                // Change the location of the data connection to point the XML file
                // returned by the owssvr.dll with a filter on property number
                con.FileLocation = @"http://moss:7777/_vti_bin/owssvr.dll"
                + "?Cmd=Display&List={EA774048-424C-47D4-86A5-CE31DCF6835A}"
                + "&XMLDATA=TRUE&FilterField1=Title&FilterValue1="
                + PropertyName;

                // Query the data connection to fill the Property Number drop-down list box with items
                con.Execute();

                // Clear the last selected value in the Street Address text list box
                root.SelectSingleNode("/my:assetTracking/my:group2/my:StreetAddress",

                NamespaceManager).SetValue("");

                con = (FileQueryConnection)DataConnections["StreetAddresses"];

                // Change the location of the data connection to point the XML file
                // returned by the owssvr.dll with a filter on property name
                con.FileLocation = @"http://moss:7777/_vti_bin/owssvr.dll"
                + "?Cmd=Display&List={02232DBE-F2BB-42B3-BBCE-B33A91EDF28B}"
                + "&XMLDATA=TRUE&FilterField1=Title&FilterValue1="
                + PropertyName;

                // Query the data connection to fill the Property Number drop-down list box with items
                con.Execute();
            }

    I also tried:

    XPathNavigator root = MainDataSource.CreateNavigator();

                // Get the value for the property name
                string PropertyName = root.SelectSingleNode("/my:assetTracking/my:group3/my:PropertyName",
                NamespaceManager).Value;

                // Clear the last selected value in the Property Number drop-down list box
                root.SelectSingleNode("/my:assetTracking/my:group3/my:PropertyNumber",

                NamespaceManager).SetValue("");

                // Clear the last selected value in the Street Address text list box
                root.SelectSingleNode("/my:assetTracking/my:group2/my:StreetAddress",

                NamespaceManager).SetValue("");


                // Retrieve the data connection bound to the Property Number drop-down list box
                FileQueryConnection con = (FileQueryConnection)DataConnections["PropertyNumbers"];
                                    con = (FileQueryConnection)DataConnections["StreetAddresses"];

                // Change the location of the data connection to point the XML file
                // returned by the owssvr.dll with a filter on property number
                con.FileLocation = @"http://moss:7777/_vti_bin/owssvr.dll"
                + "?Cmd=Display&List={EA774048-424C-47D4-86A5-CE31DCF6835A}"
                + "&XMLDATA=TRUE&FilterField1=Title&FilterValue1="
                + PropertyName;

                // Change the location of the data connection to point the XML file
                // returned by the owssvr.dll with a filter on property name
                con.FileLocation = @"http://moss:7777/_vti_bin/owssvr.dll"
                + "?Cmd=Display&List={02232DBE-F2BB-42B3-BBCE-B33A91EDF28B}"
                + "&XMLDATA=TRUE&FilterField1=Title&FilterValue1="
                + PropertyName;

                // Query the data connection to fill the Property Number drop-down list box with items
                con.Execute();

    I just need to filter more than one drop down based on the value selected in the first drop down. Really appreciate any suggestions.

    Thanks
    Tony

     

    Friday, June 17, 2011 7:32 AM