locked
Populate sites , Subsites and Lists in the dropdowns through progarmming RRS feed

  • Question

  • I have one toplevel under that I have sites and under that subsites and under subsites I have some lists.

    I need to pouplate in first dropdown with sites under Top Level site collection.

    In the 2 nd Dropdown I need to populates subsites under perticular site.

    In the 3rd drop down I need to populate all the lists under that perticular subsite.

    Kindly let me know how to acheive this through coding . Very urgent requirement need to complete by today.

    Tuesday, September 4, 2012 4:24 AM

Answers

  • Hi,

    Use below query and change column name at the end.

    query.Query = "<Where><And><And><Geq><FieldRef
     Name='Expiry_x0020_Date' /><Value Type='DateTime'>" + 
    FromDate + "</Value></Geq><Leq><FieldRef 
    Name='Expiry_x0020_Date' /><Value Type='DateTime'>" + 
    ToDate + "</Value></Leq></And><Eq><FieldRef Name='Column 
    Name' /><Value Type='Text'>Yes</Value></Eq></And>
    </Where>";

    Check this: http://buli.waw.pl/caml-query-multiple-conditions-in-and-or-clause/

    better use CAML query builder. Hope it could help


    Cheers, Hemendra-MCTS "Yesterday is just a memory,Tomorrow we may never see"

    • Marked as answer by Lhan Han Friday, September 14, 2012 12:07 PM
    Tuesday, September 4, 2012 8:00 AM

All replies

  • Since you haven't specified where you need this kind of functionality (like in a WebPart or an Application Page etc), it's difficult to assume whether the Server Object Model or the Client Object Model should be used.

    Here is a small code snippet which uses the Server Object Model. 

     SPWeb topLevelWeb;
            SPWeb childWeb1, childWeb2;
            SPWebCollection sites1, sites2;
    
            public void DeleteThisFunction()
            {            
                topLevelWeb = new SPSite("http://toplevelsiteurl").OpenWeb();
                
                sites1 = topLevelWeb.Webs;
                foreach (SPWeb item in sites1)
                {
                    dropDown1.Items.Add(item.Title);        
                }
            }
           
            void dropDown1_SelectedIndexChanged(object sender, EventArgs e)
            {
                childWeb1 = sites1[dropDown1.SelectedIndex];
                sites2 = childWeb1.Webs;
                foreach (SPWeb item in sites2)
                {
                    dropDown2.Items.Add(item.Title);
                }
            }
    
            void dropDown2_SelectedIndexChanged(object sender, EventArgs e)
            {
                childWeb2 = sites2[dropDown2.SelectedIndex];
                SPListCollection lists = childWeb2.Lists;
                foreach (SPList item in lists)
                {
                    dropDown3.Items.Add(item.Title);
                }
            }

    Regards,

    Nauzad Kapadia


    Please "Mark as Answer" if a post has answered your question or "Vote as Helpful" if it was helpful in some way. Here's why

    Tuesday, September 4, 2012 4:35 AM
  • Actually If there are no subsites under sites I need to disable 2nd Dropdown and same I need to disable 3rd dropdown if there are no lists under subsites.


    And I need server object model and It is webpart in moss2007 using VS 2010.
    Tuesday, September 4, 2012 4:38 AM
  • If there are no subsites or lists and you need to disable the dropdowns, just add an IF condition before the FOREACH and disable the dropdowns.

    Eg : 

                if (sites2.Count == 0)
                    dropDown2.Enabled = false;


    Please "Mark as Answer" if a post has answered your question or "Vote as Helpful" if it was helpful in some way. Here's why

    Tuesday, September 4, 2012 4:57 AM
  • After 3rd Dropdown I need to add two calendars buttons like from date and To date .

    Between the dates data I need to show in a gridview .

    Every list having column name Expiry date. We need to check the date from and To using ExpiryDate and Need to show that data in a gridview. Please help me this is total requirement.

    Tuesday, September 4, 2012 5:13 AM
  • Hi,

    You can try below code to get date range using CAMl and bind with grid:

    //RequestStartDate & RequestEndDate will be passed in mm/DD/yyyy format.
    //They can extend  to work with time also.
    
    string FromDate = (SPUtility.CreateISO8601DateTimeFromSystemDateTime(Convert.ToDateTime(From Date)));
    string ToDate = (SPUtility.CreateISO8601DateTimeFromSystemDateTime(Convert.ToDateTime(To Date)));
    
    SPQuery query=new SPQuery();
    query.Query = "<Where><And><Geq><FieldRef Name='Expiry_x0020_Date' /><Value Type='DateTime'>" + FromDate + "</Value></Geq><Leq><FieldRef Name='Expiry_x0020_Date' /><Value Type='DateTime'>" + ToDate + "</Value></Leq></And></Where>";
    DataTable dt = list.GetItems(query).GetDataTable();
    Hope it could help


    Cheers, Hemendra-MCTS "Yesterday is just a memory,Tomorrow we may never see"

    • Proposed as answer by Nauzad Kapadia Tuesday, September 4, 2012 6:57 AM
    Tuesday, September 4, 2012 6:56 AM
  • Hi,

    It would be better if your mentioned your complete requirement in the initial question so that it can be handled in one shot.

    To get the items in a certain date range, you can write a CAML query as follows -

                SPList list = childWeb2.Lists[dropDown3.SelectedIndex];
                SPQuery query = new SPQuery();
                query.ViewXml = "<Where><And><Geq><FieldRef Name='Expiry' /><Value IncludeTimeValue='false' Type='DateTime'>2012-09-04T17:48:21Z</Value></Geq>" + 
                    "<Leq><FieldRef Name='Expiry' /><Value IncludeTimeValue='false' Type='DateTime'>2012-09-04T17:49:08Z</Value></Leq></And></Where></Query>";

    Substitute the FROM and TO dates with the values selected by the user in the calendars. 


    Please "Mark as Answer" if a post has answered your question or "Vote as Helpful" if it was helpful in some way. Here's why

    Tuesday, September 4, 2012 6:56 AM
  • Thank you very much for your replies.. I have one more column in the list is YES/No column . How to write the caml query condition for it. The condition should satisfies date and the Yes option.. Please help me.
    Tuesday, September 4, 2012 7:27 AM
  • Hi,

    Please visit the link and download the CAML query builder which help you to build any query ..

    http://www.u2u.be/res/tools/camlquerybuilder.aspx

    Important: please post your question to proper forum. This is SharePoint 2010 not 2007 forum.


    thanksArup MCTS - SharePoint

    Play Sudoku Online


    • Edited by Arup Biswas Tuesday, September 4, 2012 7:37 AM
    Tuesday, September 4, 2012 7:35 AM
  • Hello Arup can you please provide link for 2007 forums.
    Tuesday, September 4, 2012 7:42 AM
  • Hi,

    Use below query and change column name at the end.

    query.Query = "<Where><And><And><Geq><FieldRef
     Name='Expiry_x0020_Date' /><Value Type='DateTime'>" + 
    FromDate + "</Value></Geq><Leq><FieldRef 
    Name='Expiry_x0020_Date' /><Value Type='DateTime'>" + 
    ToDate + "</Value></Leq></And><Eq><FieldRef Name='Column 
    Name' /><Value Type='Text'>Yes</Value></Eq></And>
    </Where>";

    Check this: http://buli.waw.pl/caml-query-multiple-conditions-in-and-or-clause/

    better use CAML query builder. Hope it could help


    Cheers, Hemendra-MCTS "Yesterday is just a memory,Tomorrow we may never see"

    • Marked as answer by Lhan Han Friday, September 14, 2012 12:07 PM
    Tuesday, September 4, 2012 8:00 AM